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(); + } + } } }