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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user