Problem mit reboot (wdt reset)

Mehr
20 Jun 2021 16:10 #780 von jbaben
jbaben erstellte das Thema Problem mit reboot (wdt reset)
Hallo,

ich habe das Problem "wdt reset" mit dem folgenden Programm:
#include "Arduino.h"
#include <EMailSender.h>
#include <ESP8266WiFi.h>

const char* ssid = "*************";
const char* password = "*************";

uint8_t connection_state = 0;
uint16_t reconnect_interval = 5000;

#define BUTTON_ALARM 9
#define BUTTON_FENCE 9

EMailSender emailSend("xy@gmail.com", "password");

uint8_t WiFiConnect(const char* nSSID = nullptr, const char* nPassword = nullptr)
{
    static uint16_t attempt = 0;
    Serial.print("Connecting to ");
    if(nSSID) {
        WiFi.begin(nSSID, nPassword);
        Serial.println(nSSID);
    }

    uint8_t i = 0;
    while(WiFi.status()!= WL_CONNECTED && i++ < 50)
    {
        delay(200);
        Serial.print(".");
    }
    ++attempt;
    Serial.println("");
    if(i == 51) {
        Serial.print("Connection: TIMEOUT on attempt: ");
        Serial.println(attempt);
        if(attempt % 2 == 0)
            Serial.println("Check if access point available or SSID and Password\r\n");
        return false;
    }
    Serial.println("Connection: ESTABLISHED");
    Serial.print("Got IP address: ");
    Serial.println(WiFi.localIP());
    return true;
}

void Awaits()
{
    uint32_t ts = millis();
    while(!connection_state)
    {
        delay(50);
        if(millis() > (ts + reconnect_interval) && !connection_state){
            connection_state = WiFiConnect();
            ts = millis();
        }
    }
}

void setup()
{
    Serial.begin(115200);
    delay(100);
    Serial.println("************************************");
    Serial.println("EMailSenderEsp8266GMailTest");
    Serial.println("***************************"**********);

    pinMode(BUTTON_ALARM,INPUT);
    pinMode(BUTTON_FENCE,INPUT);
 
    
    connection_state = WiFiConnect(ssid, password);
    if(!connection_state)  // if not connected to WIFI
        Awaits();          // constantly trying to connect

    /*
    EMailSender::EMailMessage message;
    message.subject = "Alert: Renosterkop R13a";
    message.message = "Help, we are attacked";

    EMailSender::Response resp = emailSend.send("xy@gmx.de", message);

    Serial.println("Sending status: ");

    Serial.println(resp.status);
    Serial.println(resp.code);
    Serial.println(resp.desc); 
    */
}

void loop()
{
    if (digitalRead(BUTTON_ALARM) == 0) {
    EMailSender::EMailMessage message;
    message.subject = "Alert: Renosterkop R13a";
    message.message = "Help, we are attacked";

    EMailSender::Response resp = emailSend.send("xy@gmx.de", message);

    Serial.println("Sending status: ");

    Serial.println(resp.status);
    Serial.println(resp.code);
    Serial.println(resp.desc);
    }
}
wenn ich den E-Mail Code in den "LOOP-Abschnitt" verwende (in "Setup" --> OK).
Die Funktion soll sein: wenn der Eingang "BUTTON_ALARM" betätigt wird soll die E-Mail gesendet werden.
Kontroller: ESP8266 bzw. ESP07

Ich habe das schon mit mehreren Libs und entsprechenden Programm-Code geteste, aber wenn ich den entsprechenden E-Mail Abschnitt im "LOOP" verwende --> wdt reset.

Mit der Lib: ESP32_MailClient.h und dem Kontroller ESP32 Dev Modul funktioniert es.
Ich möchte aber den ESP07 mit externer Antenne verwenden.

MfG

Juergen B.

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

Mehr
20 Jun 2021 16:16 #781 von jbaben
Problem mit reboot (wdt reset)
Hallo,
mit diesem Programm-Code für den ESP32 funktioniert es:
#include <WiFi.h>
#include "ESP32_MailClient.h"

// REPLACE WITH YOUR NETWORK CREDENTIALS
const char* ssid = "ssid";
const char* password = "password";

// To send Email using Gmail use port 465 (SSL) and SMTP Server smtp.gmail.com
// YOU MUST ENABLE less secure app option https://myaccount.google.com/lesssecureapps?pli=1
#define emailSenderAccount    "xy@gmail.com"
#define emailSenderPassword   "password"
#define smtpServer            "smtp.gmail.com"
#define smtpServerPort        465
#define emailSubject          "[ALERT] Renosterkop R13a"

#define BUTTON_ALARM 18
#define BUTTON_FENCE 18

// Default Recipient Email Address
String inputMessage = "xy@gmx.de";
String enableEmailChecked = "checked";
String inputMessage2 = "true";

// Flag variable to keep track if email notification was sent or not
bool emailSent = false;

// The Email Sending data object contains config and data to send
SMTPData smtpData;

void setup() {
  Serial.begin(115200);
  delay(100);
  Serial.println("***************************");
  Serial.println("ESP32_Email_Alert_01");
  Serial.println("***************************");

  pinMode(BUTTON_ALARM,INPUT);
  pinMode(BUTTON_FENCE,INPUT);
  
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  if (WiFi.waitForConnectResult() != WL_CONNECTED) {
    Serial.println("WiFi Failed!");
    return;
  }
  Serial.println();
  Serial.print("ESP32 IP Address: http://");
  Serial.println(WiFi.localIP());
  
 }

void loop() {
      
    // Check if temperature is above threshold and if it needs to send the Email alert
    if(digitalRead(BUTTON_ALARM) == 0 && !emailSent){
      String emailMessage = String("Help, we are attacked, Please send Help"); 
      
      if(sendEmailNotification(emailMessage)) {
        Serial.println(emailMessage);
        emailSent = true;
      }
      else {
        Serial.println("Email failed to send");
      }    
    }
     
}

bool sendEmailNotification(String emailMessage){
  // Set the SMTP Server Email host, port, account and password
  smtpData.setLogin(smtpServer, smtpServerPort, emailSenderAccount, emailSenderPassword);

  // For library version 1.2.0 and later which STARTTLS protocol was supported,the STARTTLS will be 
  // enabled automatically when port 587 was used, or enable it manually using setSTARTTLS function.
  //smtpData.setSTARTTLS(true);

  // Set the sender name and Email
  smtpData.setSender("ESP32", emailSenderAccount);

  // Set Email priority or importance High, Normal, Low or 1 to 5 (1 is highest)
  smtpData.setPriority("High");

  // Set the subject
  smtpData.setSubject(emailSubject);

  // Set the message with HTML format
  smtpData.setMessage(emailMessage, true);

  // Add recipients
  smtpData.addRecipient(inputMessage);

  smtpData.setSendCallback(sendCallback);

  // Start sending Email, can be set callback function to track the status
  if (!MailClient.sendMail(smtpData)) {
    Serial.println("Error sending Email, " + MailClient.smtpErrorReason());
    return false;
  }
  // Clear all data from Email object to free memory
  smtpData.empty();
  return true;
}

// Callback function to get the Email sending status
void sendCallback(SendStatus msg) {
  // Print the current status
  Serial.println(msg.info());

  // Do something when complete
  if (msg.success()) {
    Serial.println("----------------");
  }
}

MFG

Juergen B.
Folgende Benutzer bedankten sich: supportteam

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

Powered by Kunena Forum