witnessmenow / Universal-Arduino-Telegram-Bot

Use Telegram on your Arduino (ESP8266 or Wifi-101 boards)
MIT License
1.13k stars 311 forks source link

random soft wdt reset in sendPostMessage() #75

Closed fulcrumEFX closed 6 years ago

fulcrumEFX commented 6 years ago

I have a problem where every few minutes my ESP8266 does a soft wdt reset while trying to send a Telegram message (sensor data). The sendMessage is called from within a function of the sensor lib, I tried calling yield() to reset wdt just before sending the message but it doesn't help.

The code that sends the message (it works 90% of the time):

yield();

if ((iaq > 100) && (millis() > Bot_lasttime + Bot_mtbs)) {
        Serial.println("sending telegram message"); 
        char buffer[100];
        sprintf(buffer, "Mach mal Fenster auf! (IAQ: %.2f (%i) Temp: %.2f°C Hum: %.2f%%)", iaq, iaq_accuracy, temperature, humidity);
        bot.sendMessage(CHAT_ID, buffer, "");
        Serial.println(">Message sent");
        Bot_lasttime = millis();
    }

Serial output:

...sending telegram message
SEND Post Message

Soft WDT reset

ctx: cont 
sp: 3fff0fd0 end: 40101be1 offset: 01b0

followed by stack dump.

I can't figure out where the problem is. If I change bot.sendMessage(CHAT_ID, buffer, ""); to Serial.println(buffer) wdt never causes a reset.

witnessmenow commented 6 years ago

Sending a HTTPS requests uses a huge amount of memory compared to Serial Print. I suspect you are running out of memory.

Explanation of memory here and some suggestions on how to reduce it: https://learn.adafruit.com/memories-of-an-arduino/optimizing-sram

fulcrumEFX commented 6 years ago

I'm using the code provided by Bosch and just expanded it. The problem is that I don't really understand the provided example so I'm not sure what I can cut.

But since the sketch already uses 51% of memory for global variables the lack of memory is probably the cause. I'll look into it when I find the time, thanks.