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:
6
firmware/lib/net_guard/library.json
Normal file
6
firmware/lib/net_guard/library.json
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"name": "net_guard",
|
||||||
|
"build": {
|
||||||
|
"flags": ["-I$PROJECT_SRC_DIR"]
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
#include "ble_scanner.h"
|
#include "ble_scanner.h"
|
||||||
#include "reporter.h"
|
#include "reporter.h"
|
||||||
#include "event_log.h"
|
#include "event_log.h"
|
||||||
|
#include "net_guard.h"
|
||||||
#include <esp_system.h>
|
#include <esp_system.h>
|
||||||
|
|
||||||
// LED on GPIO2 (TimerCamera-F built-in LED) — verify against board schematic
|
// LED on GPIO2 (TimerCamera-F built-in LED) — verify against board schematic
|
||||||
@@ -172,6 +173,7 @@ void setup() {
|
|||||||
ESP.restart();
|
ESP.restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
net_guard_start(g_cfg);
|
||||||
led_set(false); // off = connected
|
led_set(false); // off = connected
|
||||||
|
|
||||||
// NTP sync (UTC)
|
// NTP sync (UTC)
|
||||||
@@ -208,15 +210,14 @@ void setup() {
|
|||||||
void loop() {
|
void loop() {
|
||||||
ArduinoOTA.handle();
|
ArduinoOTA.handle();
|
||||||
check_factory_reset();
|
check_factory_reset();
|
||||||
|
net_guard_tick();
|
||||||
|
|
||||||
if (WiFi.status() != WL_CONNECTED) {
|
static bool s_was_up = true;
|
||||||
led_set(true); // on = no WiFi
|
bool up = net_guard_is_up();
|
||||||
WiFi.reconnect();
|
if (up != s_was_up) {
|
||||||
delay(5000);
|
led_set(!up); // LED on when NOT up
|
||||||
if (WiFi.status() == WL_CONNECTED) {
|
if (up) reporter_flush(g_cfg);
|
||||||
led_set(false);
|
s_was_up = up;
|
||||||
reporter_flush(g_cfg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
delay(1000);
|
delay(200);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user