From 72e4d036c2f63e3326a5ea65f0ddefa373232bde Mon Sep 17 00:00:00 2001 From: "torlando-agent[bot]" <281092095+torlando-agent[bot]@users.noreply.github.com> Date: Sat, 20 Jun 2026 20:19:45 -0400 Subject: [PATCH] fix(wifi): auto-reconnect after the AP drops the association connect_wifi() never enabled auto-reconnect, and the loop's "WiFi reconnect check" only re-attempted on the manual Settings -> Reconnect button. So a dropped association left the device offline (no TCP, no AutoInterface, "no connection" in the status bar) until a reboot. Enable WiFi.setAutoReconnect(true) + persistent, and add a non-blocking backstop in the main loop that re-issues WiFi.begin() every ~15s while disconnected -- setAutoReconnect alone doesn't cover every disconnect reason. Verified the SSID/AP are fine (connects at boot); closes the stay-offline-until-reboot gap. Co-Authored-By: Claude Opus 4.8 (1M context) Claude-Session: https://claude.ai/code/session_01UWZuYkHBRqNb6BZHV8sTG5 --- src/main.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 1bdcf49c..9a5111ea 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -539,6 +539,10 @@ void setup_wifi() { INFO(msg.c_str()); WiFi.mode(WIFI_STA); + // Reconnect automatically if the AP drops the association — without this the + // device stays offline until a reboot or a manual Settings -> Reconnect. + WiFi.setAutoReconnect(true); + WiFi.persistent(true); WiFi.begin(app_settings.wifi_ssid.c_str(), app_settings.wifi_password.c_str()); // Don't block boot waiting for WiFi association — the main loop @@ -2445,6 +2449,20 @@ void loop() { start_auto_interface(); } } + // Backstop auto-reconnect: WiFi.setAutoReconnect() handles most drops in + // the background, but not every disconnect reason — without an explicit + // retry the device can sit offline until a reboot (which is exactly what + // happened). Re-issue begin() every ~15s while down. Non-blocking; the + // connected-edge above picks up once association lands. + if (!wifi_connected && app_settings.wifi_ssid.length() > 0) { + static uint32_t last_wifi_retry = 0; + uint32_t nowms = millis(); + if (last_wifi_retry == 0 || (nowms - last_wifi_retry) >= 15000) { + last_wifi_retry = nowms; + INFO("WiFi down — attempting reconnect"); + WiFi.begin(app_settings.wifi_ssid.c_str(), app_settings.wifi_password.c_str()); + } + } last_wifi_connected = wifi_connected; bool tcp_online = tcp_interface && tcp_interface->online();