Watchdog: disable watchdog while OTA is running

This commit is contained in:
Daniel Poelzleithner 2022-05-23 22:30:13 +00:00
parent 213e3e998a
commit 26fa38d052
3 changed files with 39 additions and 15 deletions

View File

@ -287,6 +287,35 @@ void WLED::loop()
#endif #endif
} }
void WLED::enableWatchdog() {
#if WLED_WATCHDOG_TIMEOUT > 0
#ifdef ARDUINO_ARCH_ESP32
esp_err_t watchdog = esp_task_wdt_init(WLED_WATCHDOG_TIMEOUT, true);
DEBUG_PRINT(F("Watchdog enabled: "));
if (watchdog == ESP_OK) {
DEBUG_PRINTLN(F("OK"));
} else {
DEBUG_PRINTLN(watchdog);
return;
}
esp_task_wdt_add(NULL);
#else
ESP.wdtEnable(WLED_WATCHDOG_TIMEOUT * 1000);
#endif
#endif
}
void WLED::disableWatchdog() {
#if WLED_WATCHDOG_TIMEOUT > 0
DEBUG_PRINTLN(F("Watchdog: disabled"));
#ifdef ARDUINO_ARCH_ESP32
esp_task_wdt_delete(NULL);
#else
ESP.wdtDisable();
#endif
#endif
}
void WLED::setup() void WLED::setup()
{ {
#if defined(ARDUINO_ARCH_ESP32) && defined(WLED_DISABLE_BROWNOUT_DET) #if defined(ARDUINO_ARCH_ESP32) && defined(WLED_DISABLE_BROWNOUT_DET)
@ -311,21 +340,7 @@ void WLED::setup()
DEBUG_PRINT(F("heap ")); DEBUG_PRINT(F("heap "));
DEBUG_PRINTLN(ESP.getFreeHeap()); DEBUG_PRINTLN(ESP.getFreeHeap());
#if WLED_WATCHDOG_TIMEOUT > 0 enableWatchdog();
#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 defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_PSRAM)
if (psramFound()) { if (psramFound()) {
@ -426,8 +441,13 @@ void WLED::setup()
#ifdef ESP8266 #ifdef ESP8266
wifi_set_sleep_type(NONE_SLEEP_T); wifi_set_sleep_type(NONE_SLEEP_T);
#endif #endif
WLED::instance().disableWatchdog();
DEBUG_PRINTLN(F("Start ArduinoOTA")); DEBUG_PRINTLN(F("Start ArduinoOTA"));
}); });
ArduinoOTA.onError([](ota_error_t error) {
// reenable watchdog on failed update
WLED::instance().enableWatchdog();
});
if (strlen(cmDNS) > 0) if (strlen(cmDNS) > 0)
ArduinoOTA.setHostname(cmDNS); ArduinoOTA.setHostname(cmDNS);
} }

View File

@ -703,5 +703,7 @@ public:
void initConnection(); void initConnection();
void initInterfaces(); void initInterfaces();
void handleStatusLED(); void handleStatusLED();
void enableWatchdog();
void disableWatchdog();
}; };
#endif // WLED_H #endif // WLED_H

View File

@ -203,6 +203,7 @@ void initServer()
},[](AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final){ },[](AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final){
if(!index){ if(!index){
DEBUG_PRINTLN(F("OTA Update Start")); DEBUG_PRINTLN(F("OTA Update Start"));
WLED::instance().disableWatchdog();
#ifdef ESP8266 #ifdef ESP8266
Update.runAsync(true); Update.runAsync(true);
#endif #endif
@ -214,6 +215,7 @@ void initServer()
DEBUG_PRINTLN(F("Update Success")); DEBUG_PRINTLN(F("Update Success"));
} else { } else {
DEBUG_PRINTLN(F("Update Failed")); DEBUG_PRINTLN(F("Update Failed"));
WLED::instance().enableWatchdog();
} }
} }
}); });