diff --git a/wled00/wled.cpp b/wled00/wled.cpp index 54c723c8..a4204732 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -276,6 +276,15 @@ void WLED::loop() loops++; #endif // WLED_DEBUG toki.resetTick(); + +#if WLED_WATCHDOG_TIMEOUT > 0 + // we finished our mainloop, reset the watchdog timer + #ifdef ARDUINO_ARCH_ESP32 + esp_task_wdt_reset(); + #else + ESP.wdtFeed(); + #endif +#endif } void WLED::setup() @@ -302,6 +311,22 @@ void WLED::setup() DEBUG_PRINT(F("heap ")); DEBUG_PRINTLN(ESP.getFreeHeap()); +#if WLED_WATCHDOG_TIMEOUT > 0 +#ifdef ARDUINO_ARCH_ESP32 + esp_err_t watchdog = esp_task_wdt_init(WLED_WATCHDOG_TIMEOUT, true); + DEBUG_PRINT(F("Enable watchdog ")); + if (watchdog == ESP_OK) { + DEBUG_PRINTLN(F(" OK")); + } else { + DEBUG_PRINTLN(watchdog); + } + esp_task_wdt_add(NULL); +#else + // any timeout possible ? + ESP.wdtEnable(WLED_WATCHDOG_TIMEOUT * 1000); +#endif +#endif + #if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_PSRAM) if (psramFound()) { // GPIO16/GPIO17 reserved for SPI RAM diff --git a/wled00/wled.h b/wled00/wled.h index 6dabdd0b..2267f276 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -49,6 +49,12 @@ // filesystem specific debugging //#define WLED_DEBUG_FS +#ifndef WLED_WATCHDOG_TIMEOUT + // 3 seconds should be enough to detect a lockup + // define WLED_WATCHDOG_TIMEOUT=0 to disable watchdog + #define WLED_WATCHDOG_TIMEOUT 3 +#endif + //optionally disable brownout detector on ESP32. //This is generally a terrible idea, but improves boot success on boards with a 3.3v regulator + cap setup that can't provide 400mA peaks //#define WLED_DISABLE_BROWNOUT_DET @@ -78,6 +84,7 @@ #else #include #endif + #include "esp_task_wdt.h" #endif #include "src/dependencies/network/Network.h"