diff --git a/tasmota/my_user_config.h b/tasmota/my_user_config.h index fa87de30e..55633bea5 100644 --- a/tasmota/my_user_config.h +++ b/tasmota/my_user_config.h @@ -348,6 +348,7 @@ #define ZIGBEE_DISTINCT_TOPICS false // [SetOption89] Enable unique device topic based on Zigbee device ShortAddr #define ZIGBEE_RMV_ZBRECEIVED false // [SetOption100] Remove ZbReceived form JSON message #define ZIGBEE_INDEX_EP false // [SetOption101] Add the source endpoint as suffix to attributes, ex `Power3` instead of `Power` if sent from endpoint 3 +#define WATCHDOG_TASK_SECONDS 5 // [ESP32 only] Task Watchdog Timer (TWDT) time in seconds - detecting Tasmota running for a prolonged period of time without yielding with `esp_task_wdt_reset()` /*********************************************************************************************\ * END OF SECTION 1 diff --git a/tasmota/support.ino b/tasmota/support.ino index f69a1e4eb..26ce2b118 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -66,6 +66,35 @@ void OsWatchTicker(void) } } +#ifdef ESP32 +#include "esp_task_wdt.h" +void TWDTInit(void) { + // enable Task Watchdog Timer + esp_task_wdt_init(WATCHDOG_TASK_SECONDS, true); + // if (ret != ESP_OK) { AddLog(LOG_LEVEL_ERROR, "HDW: cannot init Task WDT %i", ret); } + esp_task_wdt_add(nullptr); + // if (ret != ESP_OK) { AddLog(LOG_LEVEL_ERROR, "HDW: cannot start Task WDT %i", ret); } +} + +void TWDTRestore(void) { + // restore default WDT values + esp_task_wdt_init(WATCHDOG_TASK_SECONDS, false); +} + +void TWDTLoop(void) { + esp_task_wdt_reset(); +} + +// custom handler +extern "C" { + void __attribute__((weak)) esp_task_wdt_isr_user_handler(void) + { + Serial.printf(">>>>>----------\n"); + } + +} +#endif + void OsWatchInit(void) { oswatch_blocked_loop = RtcSettings.oswatch_blocked_loop; diff --git a/tasmota/tasmota.ino b/tasmota/tasmota.ino index 742d564a7..93ca203e3 100644 --- a/tasmota/tasmota.ino +++ b/tasmota/tasmota.ino @@ -317,6 +317,9 @@ void setup(void) { SettingsLoad(); SettingsDelta(); +#ifdef ESP32 + TWDTInit(); // Start Task WDT for ESP32 - FreeRTOS only +#endif OsWatchInit(); TasmotaGlobal.seriallog_level = Settings->seriallog_level; @@ -509,6 +512,9 @@ void Scheduler(void) { #endif // USE_DISCOVERY #endif // ESP8266 +#ifdef ESP32 + TWDTLoop(); +#endif OsWatchLoop(); ButtonLoop(); SwitchLoop(); diff --git a/tasmota/xdrv_01_webserver.ino b/tasmota/xdrv_01_webserver.ino index cab94ba46..9b0ff1699 100644 --- a/tasmota/xdrv_01_webserver.ino +++ b/tasmota/xdrv_01_webserver.ino @@ -2794,6 +2794,9 @@ void HandleUploadLoop(void) { Web.upload_error = 2; // Not enough space return; } +#ifdef ESP32 + TWDTLoop(); +#endif if (upload.totalSize && !(upload.totalSize % 102400)) { AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_UPLOAD "Progress %d kB"), upload.totalSize / 1024); } diff --git a/tasmota/xdrv_52_3_berry_tasmota.ino b/tasmota/xdrv_52_3_berry_tasmota.ino index f98a5820a..1e3c44214 100644 --- a/tasmota/xdrv_52_3_berry_tasmota.ino +++ b/tasmota/xdrv_52_3_berry_tasmota.ino @@ -308,6 +308,7 @@ extern "C" { // ESP object int32_t l_yield(bvm *vm); int32_t l_yield(bvm *vm) { + TWDTLoop(); // reset watchdog BrTimeoutYield(); // reset timeout be_return_nil(vm); } @@ -545,6 +546,8 @@ void berry_log(const char * berry_buf) { if (berry.log.log.length() >= BERRY_MAX_LOGS) { berry.log.log.remove(berry.log.log.head()); } + } else { + TWDTLoop(); // if REPL, printing resets the WDT } // AddLog(LOG_LEVEL_INFO, PSTR("[Add to log] %s"), berry_buf); berry.log.addString(berry_buf, pre_delimiter, "\n");