Soft WDT reset - ESP 01

My name is Ernesto, i’m working on a project with module esp01, the idea is to have a door alarma with magnetic sensor. In the developing phase I’ve runned into a Soft WDT reset issue.

This is my code:

#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h>
#include <ArduinoJson.h>

// Wifi network station credentials
#define WIFI_SSID "Imperio1"
#define WIFI_PASSWORD "Sistemas20"
// Telegram BOT Token (Get from Botfather)
#define BOT_TOKEN "5081397447:AAGoQ0SzdLuZHgQAcHOiEhPgT6oDxCzYSBo"
#define CHAT_ID "-680973127"

X509List cert(TELEGRAM_CERTIFICATE_ROOT);
WiFiClientSecure secured_client;
UniversalTelegramBot bot(BOT_TOKEN, secured_client);

const unsigned long BOT_MTBS = 1000; // tiempo medio entre mensajes escaneados
unsigned long bot_lasttime;          // última vez que se realizó el escaneo de mensajes
const int sensorPuerta = 2;
int abierto = 0;
int cerrado = 0;
bool estadoAlarma = 0;
//String chat_id;


void setup() {
  Serial.begin(115200);
  Serial.println();

 // attempt to connect to Wifi network:
  Serial.print("Connecting to Wifi SSID ");
  Serial.print(WIFI_SSID);
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  secured_client.setTrustAnchors(&cert); // Add root certificate for api.telegram.org
  while (WiFi.status() != WL_CONNECTED)
  {
    Serial.print(".");
    delay(500);
  }
  Serial.print("\nWiFi connected. IP address: ");
  Serial.println(WiFi.localIP());

  Serial.print("Retrieving time: ");
  configTime(0, 0, "pool.ntp.org"); // get UTC time via NTP
  time_t now = time(nullptr);
  while (now < 24 * 3600)
  {
    Serial.print(".");
    delay(100);
    now = time(nullptr);
  }
  Serial.println(now);
  bot.sendMessage(CHAT_ID, "📡 Wifi Conectado!!", "");

  pinMode(sensorPuerta, INPUT);
  
}

void loop()
{
   if (millis() - bot_lasttime > BOT_MTBS)
  {
    int numNewMessages = bot.getUpdates(bot.last_message_received + 1);

    while (numNewMessages)
    {
      //Serial.println("Llego un mensaje!!");
      handleNewMessages(numNewMessages);
      numNewMessages = bot.getUpdates(bot.last_message_received + 1);
    }

    bot_lasttime = millis();
  }

  int lectura = digitalRead(sensorPuerta);
  delay(100);
  if (estadoAlarma == 1 && lectura == 0){
    abierto ++;
    imprimeAbierto(abierto, lectura);
    cerrado = 0;
  }else if(estadoAlarma == 1 && lectura == 1){
    //Serial.println(lectura);
    abierto = 0;
    cerrado ++;
    imprimeCerrado(cerrado, lectura);
  }
  
}


void handleNewMessages(int numNewMessages)
{
  Serial.print("handleNewMessages ");
  Serial.println(numNewMessages);

  for (int i = 0; i < numNewMessages; i++)
  {
    String chat_id = bot.messages[i].chat_id;
    String text = bot.messages[i].text;

    String from_name = bot.messages[i].from_name;
    if (from_name == "") from_name = "Guest";

    if (text == "/armado"){
      estadoAlarma = 1;
      Serial.print("Panel de alarmas: ARMADO - ");
      Serial.println(estadoAlarma);
      bot.sendMessage(chat_id, "📟 Panel de alarmas: ✅ ARMADO", "");
    }else if (text == "/desarmado"){
      estadoAlarma = 0;
      Serial.print("Panel de alarmas: DESARMADO - ");
      Serial.println(estadoAlarma);
      bot.sendMessage(chat_id, "📟 Panel de alarmas: ❌ DESARMADO", "");
    }else{
      Serial.print("Comando No reonocido...");
      bot.sendMessage(chat_id, "Comando No reconocido 🚫", "");
      }
      
          
  }
}

void imprimeAbierto(int abierto, int lectura){
  if (abierto < 2){
    Serial.print("Puerta Abierta - ");
    Serial.println(lectura);
    bot.sendMessage(CHAT_ID, " Puerta Abierta 🚪🟢", "");
  }        
}

void imprimeCerrado(int cerrado, int lectura){
  if (cerrado < 2){
    Serial.print("Puerta Cerrada - ");
    Serial.println(lectura);
    bot.sendMessage(CHAT_ID, " Puerta Cerrada 🚪🔴", "");
  
    }
}
type or paste code here

This is the error

handleNewMessages 1
Panel de alarmas: ARMADO - 1

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

Soft WDT reset

>>>stack>>>

ctx: cont
sp: 3ffffcc0 end: 3fffffc0 offset: 01a0
3ffffe60:  03d19744 00000020 3fff23bc 401008de  
3ffffe70:  3ffef000 00000000 4020bc28 00000000  
3ffffe80:  0000dbb5 00000000 3ffef050 40206b87  
3ffffe90:  00000000 003d003f 00000000 00000000  
3ffffea0:  000b000f 00000000 00000020 40100908  
3ffffeb0:  3fffff10 00000000 3fff8498 00000000  
3ffffec0:  3fffff10 3ffffef8 3ffe8fd9 40204968  
3ffffed0:  3ffe8f8f 3ffffef8 00000000 3fffff6c  
3ffffee0:  3fffff78 3ffef050 00000000 40206ce9  
3ffffef0:  3ffe885c 00000020 3fff7edc 3fff7f00  
3fffff00:  3fff8498 3fff84b8 3ffef000 4020779e  
3fffff10:  3fff84a8 3fff8498 00000020 3ffef248  
3fffff20:  3fffff10 3ffffef8 3fffff6c 40208663  
3fffff30:  3fffff60 00000000 3fffff78 402086d4  
3fffff40:  3fffdad0 3ffe8f8f 3fffff78 3ffef248  
3fffff50:  3fffdad0 3ffef04c 00000001 40201121  
3fffff60:  3038362d 31333739 0a003732 3fff23d4  
3fffff70:  0018001f 80000000 00000000 40208cf8  
3fffff80:  00000000 00000064 3ffef248 402093a6  
3fffff90:  3fffdad0 3ffef04c 00000001 402014c4  
3fffffa0:  3fffdad0 00000000 3ffef234 40208e18  
3fffffb0:  feefeffe feefeffe 3ffe8640 40100b99  
<<<stack<<<

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

 ets Jan  8 2013,rst cause:2, boot mode:(3,7)

load 0x4010f000, len 3460, room 16 
tail 4
chksum 0xcc
load 0x3fff20b8, len 40, room 4 
tail 4
chksum 0xc9
csum 0xc9
v00063480
~ld

pls helpme

You got a software watchdog reset, what about the while() inside the loop() function?

Try to put a delay(1) inside and check the result.

This is blocking code, and I suspect that this is the root of the problem.
Try putting a yield(); into the while loop to reset the WDT.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.