diff --git a/platformio.ini b/platformio.ini index 25a2b69a..c7ebc600 100644 --- a/platformio.ini +++ b/platformio.ini @@ -43,7 +43,7 @@ build_flags = -std=gnu++2b -I conf -Wno-deprecated-declarations -Wno-attributes - -D CORE_DEBUG_LEVEL=1 + -D CORE_DEBUG_LEVEL=0 build_src_flags = -Wformat=2 -Wformat-truncation -Wall diff --git a/src/main.cpp b/src/main.cpp index 926557d3..a3465247 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -142,11 +142,19 @@ namespace fabomatic if (!initialized) { constexpr auto msecs = std::chrono::duration_cast(conf::tasks::WATCHDOG_TIMEOUT).count(); - constexpr esp_task_wdt_config_t conf{.timeout_ms = msecs, .idle_core_mask = 0, .trigger_panic = true}; - esp_task_wdt_init(&conf); // enable panic so ESP32 restarts - ESP_LOGI(TAG, "taskEspWatchdog - initialized %lld milliseconds", msecs); - esp_task_wdt_add(NULL); // add current thread to WDT watch - initialized = true; + constexpr esp_task_wdt_config_t conf{.timeout_ms = msecs, .idle_core_mask = 1, .trigger_panic = true}; + esp_task_wdt_deinit(); + auto result = esp_task_wdt_init(&conf); // enable panic so ESP32 restarts + if (result == ESP_OK) + { + ESP_LOGI(TAG, "taskEspWatchdog - initialized %lld milliseconds", msecs); + esp_task_wdt_add(NULL); // add current thread to WDT watch + initialized = true; + } + else + { + ESP_LOGE(TAG, "taskEspWatchdog - failed to initialize with %lld milliseconds", msecs); + } } esp_task_wdt_reset(); // Signal the hardware watchdog } @@ -470,7 +478,8 @@ void setup() if (!hw_init) { // If hardware initialization failed, wait for OTA for 3 minutes - constexpr esp_task_wdt_config_t conf{.timeout_ms = 60 * 3 * 1000, .idle_core_mask = 0, .trigger_panic = true}; + constexpr esp_task_wdt_config_t conf{.timeout_ms = 60 * 3 * 1000, .idle_core_mask = 1, .trigger_panic = true}; + esp_task_wdt_deinit(); esp_task_wdt_init(&conf); // enable panic so ESP32 restarts esp_task_wdt_add(NULL); // add current thread to WDT watch while (true) diff --git a/test/test_mqtt/test_mqtt.cpp b/test/test_mqtt/test_mqtt.cpp index 4521647d..f715f3d4 100644 --- a/test/test_mqtt/test_mqtt.cpp +++ b/test/test_mqtt/test_mqtt.cpp @@ -277,11 +277,19 @@ namespace fabomatic::tests { if (!initialized) { - constexpr auto msecs = std::chrono::duration_cast(conf::tasks::WATCHDOG_TIMEOUT).count(); - constexpr esp_task_wdt_config_t conf{.timeout_ms = msecs, .idle_core_mask = 0, .trigger_panic = true}; - TEST_ASSERT_EQUAL_MESSAGE(ESP_OK, esp_task_wdt_init(&conf), "taskEspWatchdog - esp_task_wdt_init failed"); - ESP_LOGI(TAG3, "taskEspWatchdog - initialized %lld seconds", msecs); - TEST_ASSERT_EQUAL_MESSAGE(ESP_OK, esp_task_wdt_add(NULL), "taskEspWatchdog - esp_task_wdt_add failed"); + constexpr uint32_t msecs{std::chrono::duration_cast(conf::tasks::WATCHDOG_TIMEOUT).count()}; + constexpr esp_task_wdt_config_t conf{.timeout_ms = msecs, .idle_core_mask = 1, .trigger_panic = true}; + + auto deinit = esp_task_wdt_deinit(); + TEST_ASSERT_EQUAL_INT_MESSAGE(ESP_OK, deinit, "taskEspWatchdog - esp_task_wdt_deinit failed"); + + auto result = esp_task_wdt_init(&conf); + TEST_ASSERT_EQUAL_INT_MESSAGE(ESP_OK, result, "taskEspWatchdog - esp_task_wdt_init failed"); + + ESP_LOGI(TAG3, "taskEspWatchdog - initialized %lu seconds", msecs); + + auto result2 = esp_task_wdt_add(NULL); + TEST_ASSERT_EQUAL_INT_MESSAGE(ESP_OK, result2, "taskEspWatchdog - esp_task_wdt_add failed"); initialized = true; } TEST_ASSERT_EQUAL_MESSAGE(ESP_OK, esp_task_wdt_reset(), "taskEspWatchdog - esp_task_wdt_reset failed");