diff --git a/main/maxxfan-controller.c b/main/maxxfan-controller.c index 1287df8..91a68e8 100755 --- a/main/maxxfan-controller.c +++ b/main/maxxfan-controller.c @@ -116,7 +116,7 @@ static const char* html_page = "

Speed: 0%

" "

Target: 0%

" "
" -" ⚡ Ramping in progress..." +" Ramping in progress..." "
" " " " " @@ -209,15 +209,28 @@ static void apply_motor_pwm(int speed_percent); void init_watchdog(void) { ESP_LOGI(TAG, "Setting up watchdog monitoring..."); - // The system watchdog is already monitoring the main task - // We don't need to add anything, just need to reset it properly - ESP_LOGI(TAG, "Using system watchdog - will reset from main context"); + // Get current task handle and add to watchdog + main_task_handle = xTaskGetCurrentTaskHandle(); + esp_err_t result = esp_task_wdt_add(main_task_handle); + + if (result == ESP_OK) { + ESP_LOGI(TAG, "Main task added to watchdog monitoring"); + } else if (result == ESP_ERR_INVALID_ARG) { + ESP_LOGI(TAG, "Task already monitored by watchdog"); + } else { + ESP_LOGW(TAG, "Watchdog not available: %s", esp_err_to_name(result)); + main_task_handle = NULL; // Disable watchdog feeding + } } // Feed the watchdog void feed_watchdog(void) { - // Simply reset the watchdog for the current task context - esp_task_wdt_reset(); + if (main_task_handle != NULL) { + esp_err_t result = esp_task_wdt_reset(); + if (result != ESP_OK) { + ESP_LOGD(TAG, "Watchdog reset failed: %s", esp_err_to_name(result)); + } + } } // WiFi event handler