Почему не компилируется?

Mestniy96
Offline
Зарегистрирован: 31.08.2015

Взял вот от сюда библиотеку(https://github.com/gregington/SMTPClient), написал скетч:

An Arduino library to send emails to an SMTP server. Supports sending emails from an Arduino to an unauthenticated SMTP server. This library supports sending email through Ethernet, however it should also work with WiFi, but this has not been tested.
Usage

Client.h, Mail.h and SMTPClient.h need to be imported.

#import <Client.h>
#import <Mail.h>
#import <SMTPClient.h>

An instance of SMTPClient needs to be created with the server hostname or IP and the port where the SMTP server is located as well as the Client instance that will be used to make the connection. If the port is omitted, it is defaulted to port 25. In the following example, the client is an EthernetClient, but a WiFi or other client could be specified.

byte ip[] = { 192, 168, 0, 125 };
EthernetClient ethClient;
SmtpClient client(&ethClient, ip);

To send an email, an instance of the Mail class needs to be creaed and methods called to populate the object. At a minimum, at least one recipient and a from address are required. A maximum of 16 destination addresses are supported, with them being any combination of To, Cc or Bcc.

Mail mail;
mail.from("Some Sender <sender@example.com>");
mail.replyTo("noreply@example.com");
mail.to("Someone <someone@example.com>");
mail.to("Someone Else <someoneelse@example.com>");
mail.cc("Another <another@example.com>");
mail.bcc("Secret <secret@example.com>");
mail.subject("Hello there");
mail.body("I can send email from an Arduino!");
client.send(&mail);

 

Mestniy96
Offline
Зарегистрирован: 31.08.2015

Ой не тот код простите:

#include <Mail.h>
#include <SmtpClient.h>
#include <UIPEthernet.h>
#include <FullIP.h>
#include <Ethernet.h>

#import <Client.h>
#import <Mail.h>
#import <SMTPClient.h>




 byte ip[] = { 192, 168, 0, 218 };




// the setup routine runs once when you press reset:
void setup() {                
 

uint8_t mac[6] = {0x00,0x01,0x02,0x03,0x04,0x05};
  Ethernet.begin(mac);
Serial.begin(115200);  
  
 EthernetClient ethClient;
 // ETHER_28J60 ethClient;
SmtpClient client(&ethClient, ip,25);
Serial.print("localIP: ");
  Serial.println(Ethernet.localIP());
delay(500);
}

// the loop routine runs over and over again forever:
void loop() {
 Mail mail;
mail.from("Some Sender <sender@example.com>");
mail.replyTo("noreply@example.com");
mail.to("Someone <someone@example.com>");
mail.to("Someone Else <someoneelse@example.com>");
mail.cc("Another <another@example.com>");
mail.bcc("Secret <secret@example.com>");
mail.subject("Hello there");
mail.body("I can send email from an Arduino!");
client.send(&mail);         // wait for a second
}

 

Mestniy96
Offline
Зарегистрирован: 31.08.2015

46 строка не компелируется

Alexino
Offline
Зарегистрирован: 29.12.2015

Сочувствуем.
А вопрост то, собссно, в чём ? 

ЕвгенийП
ЕвгенийП аватар
Offline
Зарегистрирован: 25.05.2015

Местный,

сколько ж Вам раз говорить: если что-то не компилируется, значит компилятор сказал Вам что именно ему не нравится. Так давайте, блин сюда, чего он там сказал! Я понимаю, что что Вам пофиг, чего он там говорит, т.к. читать Вы всё равно не умеете, но из того, что Вы не умеете читать, не значит, что никто не умеет! 

Хотя, в данном случае всё и так понятно. Вы используете в 46 строке переменную client, которую нигде не описали. Нет, вернее, Вы описали её в функции setup(), но при чём здесь это? Описали в setup, а использовать собираетесь в loop - так не бывает.

Mestniy96
Offline
Зарегистрирован: 31.08.2015

Последовал по Вашему совету, получил вот такой код. Спасибо.

#include <Mail.h>
#include <SmtpClient.h>
#include <UIPEthernet.h>
#include <FullIP.h>
#include <Ethernet.h>
#include <SPI.h>

#import <Client.h>
#import <Mail.h>
#import <SMTPClient.h>
// the setup routine runs once when you press reset:
void setup() {  
Serial.begin(115200);
}

// the loop routine runs over and over again forever:
void loop() { 
  uint8_t mac[6] = {0x00,0x01,0x02,0x03,0x04,0x05};
byte ip[] = { 192, 168, 0, 218 }; 
Ethernet.begin(mac); 
EthernetClient ethClient;
SmtpClient client(&ethClient, ip,25);
// ETHER_28J60 ethClient;
Serial.print("localIP: ");
Serial.println(Ethernet.localIP());
delay(500);
 Mail mail;
mail.from("Some Sender <sender@example.com>");
mail.replyTo("noreply@example.com");
mail.to("Someone <someone@example.com>");
mail.to("Someone Else <someoneelse@example.com>");
mail.cc("Another <another@example.com>");
mail.bcc("Secret <secret@example.com>");
mail.subject("Hello there");
mail.body("I can send email from an Arduino!");
client.send(&mail);         // wait for a second
}

Он компилируется но почемуто сообщения mail не отправляются!!!!

ЕвгенийП
ЕвгенийП аватар
Offline
Зарегистрирован: 25.05.2015

Ну, знаете, Вы теперь инициализируете eyhernet в loop с частотой 200килогерц. Зачем? Сделайте как у Вас было, только переменную опишите как глобальную.

Mestniy96
Offline
Зарегистрирован: 31.08.2015

ЕвгенийП пишет:

Ну, знаете, Вы теперь инициализируете eyhernet в loop с частотой 200килогерц. Зачем? Сделайте как у Вас было, только переменную опишите как глобальную.

Спасибо Вам большое. Простите за кривизну мыслей пожалуйста!!!

Mestniy96
Offline
Зарегистрирован: 31.08.2015

Последний вопрос: Подскажите пожалуйста, за что отвечает вот этот отрезок:

SmtpClient client(&ethClient, ip,25);

 

Mestniy96
Offline
Зарегистрирован: 31.08.2015

Вообще правильно ли я сделал?

#include <Mail.h>
#include <SmtpClient.h>
#include <UIPEthernet.h>
#include <FullIP.h>
#include <Ethernet.h>
#include <SPI.h>

#import <Client.h>
#import <Mail.h>
#import <SMTPClient.h>
// the setup routine runs once when you press reset:
uint8_t mac[6] = {0x00,0x01,0x02,0x03,0x04,0x05};
EthernetClient ethClient;
byte ip[] = { 192, 168, 0, 218 }; 
void setup() {  
Serial.begin(115200);
Ethernet.begin(mac); 
// ETHER_28J60 ethClient;
Serial.print("localIP: ");
Serial.println(Ethernet.localIP());
}

// the loop routine runs over and over again forever:
void loop() { 
SmtpClient client(&ethClient, ip,25);
delay(500);
Mail mail;
mail.from("Some Sender <sender@example.com>");
mail.replyTo("noreply@example.com");
mail.to("Someone <someone@example.com>");
mail.to("Someone Else <someoneelse@example.com>");
mail.cc("Another <another@example.com>");
mail.bcc("Secret <secret@example.com>");
mail.subject("Hello there");
mail.body("I can send email from an Arduino!");
client.send(&mail);//wait for a second
}

 

Mestniy96
Offline
Зарегистрирован: 31.08.2015

Суть данного скетча опрашивать сетевуху и выводить ее состояние на email