From f08f70a8fb27a6edd0fc8de9b452f11650eeb501 Mon Sep 17 00:00:00 2001 From: Peter Woolery Date: Thu, 23 Apr 2026 13:52:07 -0700 Subject: [PATCH] feat(firmware): software heartbeat-miss watchdog reboots after 6h offline Reporter task counts consecutive heartbeat failures from the bool returned by reporter_heartbeat (Task 5). After 6 consecutive misses (~6 hours at the hourly cadence) the device logs EVT_HEARTBEAT_MISS then EVT_REBOOT(REBOOT_HEARTBEAT_MISS) and restarts, giving the whole network stack a clean reinitialization. The 200ms delay before the restart lets NVS commit the REBOOT entry so the next boot can report it via EVT_BOOT + esp_reset_reason(). --- firmware/src/main.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/firmware/src/main.cpp b/firmware/src/main.cpp index b3eea6c..9767a87 100644 --- a/firmware/src/main.cpp +++ b/firmware/src/main.cpp @@ -137,10 +137,24 @@ static void task_reporter(void*) { reporter_submit_camera(g_cfg, cam_rec); reporter_submit_ble(g_cfg, ble_rec); - reporter_heartbeat(g_cfg, millis() / 1000, WiFi.RSSI()); + bool hb_ok = reporter_heartbeat(g_cfg, millis() / 1000, WiFi.RSSI()); ble_scanner_reinit(); led_set(false); + + static uint8_t consecutive_misses = 0; + if (hb_ok) { + consecutive_misses = 0; + } else { + consecutive_misses++; + event_log_write(EVT_HEARTBEAT_MISS, consecutive_misses, 0); + Serial.printf("[WDG] heartbeat miss %u/6\n", consecutive_misses); + if (consecutive_misses >= 6) { + event_log_write(EVT_REBOOT, REBOOT_HEARTBEAT_MISS, 0); + delay(200); // let NVS commit before reboot + ESP.restart(); + } + } } }