refactor(firmware): drive WiFi reconnect from net_guard events

loop() no longer blocks for 5s after a disconnect; reconnect is
scheduled from the WiFi event handler with exponential backoff.
Buffered reports flush on every clean UP transition.
This commit is contained in:
2026-04-23 13:36:29 -07:00
parent cfa0d2563f
commit af3067d481
2 changed files with 16 additions and 9 deletions

View File

@@ -0,0 +1,6 @@
{
"name": "net_guard",
"build": {
"flags": ["-I$PROJECT_SRC_DIR"]
}
}

View File

@@ -9,6 +9,7 @@
#include "ble_scanner.h"
#include "reporter.h"
#include "event_log.h"
#include "net_guard.h"
#include <esp_system.h>
// LED on GPIO2 (TimerCamera-F built-in LED) — verify against board schematic
@@ -172,6 +173,7 @@ void setup() {
ESP.restart();
}
net_guard_start(g_cfg);
led_set(false); // off = connected
// NTP sync (UTC)
@@ -208,15 +210,14 @@ void setup() {
void loop() {
ArduinoOTA.handle();
check_factory_reset();
net_guard_tick();
if (WiFi.status() != WL_CONNECTED) {
led_set(true); // on = no WiFi
WiFi.reconnect();
delay(5000);
if (WiFi.status() == WL_CONNECTED) {
led_set(false);
reporter_flush(g_cfg);
}
static bool s_was_up = true;
bool up = net_guard_is_up();
if (up != s_was_up) {
led_set(!up); // LED on when NOT up
if (up) reporter_flush(g_cfg);
s_was_up = up;
}
delay(1000);
delay(200);
}