diff --git a/firmware/lib/net_guard/library.json b/firmware/lib/net_guard/library.json new file mode 100644 index 0000000..fe445e3 --- /dev/null +++ b/firmware/lib/net_guard/library.json @@ -0,0 +1,6 @@ +{ + "name": "net_guard", + "build": { + "flags": ["-I$PROJECT_SRC_DIR"] + } +} diff --git a/firmware/src/main.cpp b/firmware/src/main.cpp index 475bae5..4cb595d 100644 --- a/firmware/src/main.cpp +++ b/firmware/src/main.cpp @@ -9,6 +9,7 @@ #include "ble_scanner.h" #include "reporter.h" #include "event_log.h" +#include "net_guard.h" #include // 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); }