fix: only touch the task watchdog from tasks that are subscribed to it

Only loop() is subscribed.  setConnected() runs on the WiFi event task
and reached SocketEmitter::endEmit(), whose plain esp_task_wdt_reset()
logged "esp_task_wdt_reset(707): task not found" on every boot.  The web
and socket handlers on async_tcp did the same.

/scanaps on async_tcp called esp_task_wdt_add(NULL) after the scan,
subscribing a task that nothing resets, so the board could panic 15 s
after a scan from the UI.

TaskWdt.h resets only a subscribed task and re-adds a task after a long
call only when it was watched before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
cjkas 2026-10-21 13:45:04 +02:00
parent e9109c56e0
commit 609cd455c6
10 changed files with 154 additions and 57 deletions

View file

@ -1,6 +1,6 @@
#include <Arduino.h>
#include <ArduinoJson.h>
#include <esp_task_wdt.h>
#include "TaskWdt.h"
#include "esp_log.h"
#include "SocketEmitter.h"
#include "ConfigSettings.h"
@ -112,7 +112,7 @@ void SocketEmitter::endEmit(uint8_t num) {
uint32_t asyncId = getAsyncId(num);
this->json.endEvent(asyncId);
}
esp_task_wdt_reset();
resetTaskWdt();
}
void SocketEmitter::endEmitRoom(uint8_t room) {
if(room < SOCK_MAX_ROOMS) {
@ -136,7 +136,7 @@ void SocketEmitter::initClients() {
uint32_t asyncId = getAsyncId(slot);
if(asyncId != 0 && ws.hasClient(asyncId)) {
ESP_LOGD(TAG, "Initializing Socket Client %u (asyncId=%lu)", slot, asyncId);
esp_task_wdt_reset();
resetTaskWdt();
ElapsedTimer total, step;
settings.emitSockets(slot);
logElapsed(TAG, "Socket init settings", step.lap());
@ -150,7 +150,7 @@ void SocketEmitter::initClients() {
net.emitSockets(slot);
logElapsed(TAG, "Socket init network", step.lap());
logElapsed(TAG, "Socket init total", total.us());
esp_task_wdt_reset();
resetTaskWdt();
}
this->newClients[i] = 255;
}

View file

@ -1,4 +1,4 @@
#include <esp_task_wdt.h>
#include "TaskWdt.h"
#include "Somfy.h"
#include "SomfyEditor.h"
#include "SocketEmitter.h"
@ -128,7 +128,7 @@ void SomfyShadeController::emitState(uint8_t num) {
for(uint8_t i = 0; i < SOMFY_MAX_SHADES; i++) {
SomfyShade *shade = &this->shades[i];
if(shade->getShadeId() == 255) continue;
esp_task_wdt_reset();
resetTaskWdt();
shade->emitState(num);
}
}