Merge pull request #2657 from poelzi/watchdog
Enable ESP watchdog by default
This commit is contained in:
commit
902c11d074
@ -276,6 +276,44 @@ void WLED::loop()
|
|||||||
loops++;
|
loops++;
|
||||||
#endif // WLED_DEBUG
|
#endif // WLED_DEBUG
|
||||||
toki.resetTick();
|
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::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()
|
||||||
@ -302,6 +340,8 @@ void WLED::setup()
|
|||||||
DEBUG_PRINT(F("heap "));
|
DEBUG_PRINT(F("heap "));
|
||||||
DEBUG_PRINTLN(ESP.getFreeHeap());
|
DEBUG_PRINTLN(ESP.getFreeHeap());
|
||||||
|
|
||||||
|
enableWatchdog();
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_PSRAM)
|
#if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_PSRAM)
|
||||||
if (psramFound()) {
|
if (psramFound()) {
|
||||||
// GPIO16/GPIO17 reserved for SPI RAM
|
// GPIO16/GPIO17 reserved for SPI RAM
|
||||||
@ -401,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);
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,12 @@
|
|||||||
// filesystem specific debugging
|
// filesystem specific debugging
|
||||||
//#define WLED_DEBUG_FS
|
//#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.
|
//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
|
//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
|
//#define WLED_DISABLE_BROWNOUT_DET
|
||||||
@ -78,6 +84,7 @@
|
|||||||
#else
|
#else
|
||||||
#include <LittleFS.h>
|
#include <LittleFS.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include "esp_task_wdt.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "src/dependencies/network/Network.h"
|
#include "src/dependencies/network/Network.h"
|
||||||
@ -704,5 +711,7 @@ public:
|
|||||||
void initConnection();
|
void initConnection();
|
||||||
void initInterfaces();
|
void initInterfaces();
|
||||||
void handleStatusLED();
|
void handleStatusLED();
|
||||||
|
void enableWatchdog();
|
||||||
|
void disableWatchdog();
|
||||||
};
|
};
|
||||||
#endif // WLED_H
|
#endif // WLED_H
|
||||||
|
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user