Hallo,
Ich versuche mich gerade daran, den Nano ESP dazu zu bringen, eine e-mail zu versenden.
Als Vorlage habe ich folgenden Code verwendet, der allerdings für einen Arduino, mit Ethernet Shield geschrieben wurde:
http://www.jucetechnology.com/wordpress/simple-burglar-ethernet-shield-connection/
Leider waren meine Bemühungen, den Code für den Nano ESP anzupassen, nicht gerade von Erfolg gekrönt.
Liegt wohl hauptsächlich an meiner fehlenden Programmierfahrung.
Hier mal mein Code:
#include ;
#include
#include
#define SSID "YourSSID"
#define PASSWORD "xxxxxx"
#define LED_WLAN 13
char smtpServer[] = "smtpcorp.com";
NanoESP nanoesp = NanoESP();
NanoESP client;
void setup() {
Serial.begin(19200);
nanoesp.init();
//Station Mode, Connect to WiFi
if (!nanoesp.configWifi(STATION, SSID, PASSWORD)) {
Serial.println(F("Error: WLAN not Connected\n"));
}
else {
Serial.println(F("WLAN Connected\n"));
digitalWrite(LED_WLAN, HIGH);
}
//Print IP in Terminal
Serial.println(nanoesp.getIp());
//Time for Ping
int vTime = nanoesp.ping("www.google.de");
if (vTime > 0 ){
Serial.println("Internet Connection OK\nPing: " + String(vTime) + "ms");
}
else {
Serial.println(F("Error: Internet Connection"));
}
}
void loop()
{
email("hallo");
delay(1000);
}
// now I send email
bool email(char* text)
{
bool success = false;
Serial.println("Sending email...");
if (client.connect(smtpServer, 2525)){ //2525 is SMTP Server port
Serial.println("connected");
delay(100);
client.println("EHLO arduino");
for(int i=0; i 0)
break;
}
Serial.println("responded");
client.println("AUTH LOGIN"); //see "http://base64-encoder-online.waraxe.us/"
client.println("xxxxxxxxxx"); //Type your username and encode it
client.println("yyyyyyyyyy"); //Type your password and encode it
// Put your "from" email address here
client.println("MAIL FROM:"); //Seems you can write what you want here...
for(int i=0; i 0)
break;
}
client.println("RCPT TO:");
for(int i=0; i 0)
break;
}
client.println("DATA");
for(int i=0; i 0)
break;
}
//Sender
client.println("from: mail@mail.com"); //Sender address
client.println("to: mail@mail.com"); //Receiver address
client.println("SUBJECT: From your arduino");
client.println("");
client.println(text);
client.println(".");
client.println("QUIT");
for (int i = 0; i 998){
Serial.println("error: No response");
}
if(client.read() > 0)
break;
}
success = true;
client.println();
Serial.println("end");
}
else {
Serial.println("Failed");
client.println("QUIT"); //Disconnection
}
client.stop();
return success;
}
Hier bekomme ich allerdings folgende Fehler:
Arduino: 1.6.13 (Windows 8.1), Board: “Arduino Nano, ATmega328”
C:\Users\Andreas\AppData\Local\Temp\arduino_modified_sketch_676728\sketch_dec30a.ino:1:17: warning: extra tokens at end of #include directive
#include <SPI.h>;
C:\Users\Andreas\AppData\Local\Temp\arduino_modified_sketch_676728\sketch_dec30a.ino: In function ‘void loop()’:
C:\Users\Andreas\AppData\Local\Temp\arduino_modified_sketch_676728\sketch_dec30a.ino:42:16: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
email(“hallo”);
C:\Users\Andreas\AppData\Local\Temp\arduino_modified_sketch_676728\sketch_dec30a.ino: In function ‘bool email(char*)’:
sketch_dec30a:51: error: ‘class NanoESP’ has no member named ‘connect’
if (client.connect(smtpServer, 2525)){ //2525 is SMTP Server port
sketch_dec30a:102: error: ‘class NanoESP’ has no member named ‘stop’
client.stop();
exit status 1
‘class NanoESP’ has no member named ‘connect’
Für eure Hilfe zum Code, wäre ich euch sehr dankbar.
1 Antwort
klaus – 05.01.2017
Ixh weiß ja nicht, ob Du den Fehler inzwischen schon selbst gefunden hast. Die Meldung besagt, dass es keine Funktion “connect” in der nanoESP Bibliothek gibt. In der neuen Bibliothek finde ich auch nur die Funktion “boolean newConnection(int id, String type, String ip , unsigned int port)”. Diese müsstest Du verwenden.