witnessmenow / Universal-Arduino-Telegram-Bot

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

WDT reset with weak WIFI on ESP32 #226

Open lukjj opened 3 years ago

lukjj commented 3 years ago

I have good working project with esp32 on table near wifi. But if I take it outdoor I have every 1-20minutes very long connection time and watchdog reset it (30s watchdog). I think there are sometimes lost packets and this make problems. Also I'm using getUpdates only every 5s (this help also).

I was found first thing - while loop without timeout in readHTTPAnswer and I was add it (in UniversalTelegramBot.cpp):

while (millis() - now < longPoll * 1000 + waitForResponse) {
    while ((client->available()) && (millis() - now < longPoll * 1000 + waitForResponse)) {
      char c = client->read();

I think it can be there to be sure (I'm using only short messages), but this not help and later I was log this:

01:36:37;bot read GET Update Messages 01:36:37;[BOT]Connecting to server 01:37:02;E (115045) task_wdt: Task watchdog got triggered.

But there is only connect command and this make problem. I was found possibility to use connect with timeout, but client.h have not this extension. My solution is use #include <WiFiClient.h> instead of #include <Client.h> in UniversalTelegramBot.h And then is possible on all connect commands put timeout (in UniversalTelegramBot.cpp): client->connect(TELEGRAM_HOST, TELEGRAM_SSL_PORT,3000)

Now I have stable run without reset. When is some connection problem, there is connection error and it stops trying max in 15s (maybe some repeating tryies of connect function lwip libary). Its ok for me because fast part of program is running on second core. I hope this help to somebody