Email Versand mit Nano ESP

Forums The NanoESP & Pretzel Board Forum Email Versand mit Nano ESP

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #1920
    Encom
    Participant

    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 <SPI.h>;
    #include <NanoESP.h>
    #include <SoftwareSerial.h>
    
    #define SSID "YourSSID"
    #define PASSWORD "YourPassword"
    
    #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<999; ++i){
          if(client.read() > 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</p>
        // Put your "from" email address here
        client.println("MAIL FROM:<dumm@gmail.com>"); //Seems you can write what you want here...
        for(int i=0; i<999; ++i){
          if(client.read() > 0)
            break;
        }
        client.println("RCPT TO:<mail@mail.com>");
        for(int i=0; i<999; ++i){
          if(client.read() > 0)
            break;
        }
        client.println("DATA");
        for(int i=0; i<999; ++i){
          if(client.read() > 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<999; ++i){
          if(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.

    • This topic was modified 7 years, 2 months ago by Encom.
    #2003
    Klaus
    Participant

    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.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.