mirror of
https://github.com/torlando-tech/pyxis.git
synced 2026-08-14 06:39:54 +00:00
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) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UWZuYkHBRqNb6BZHV8sTG5
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
d7518eb187
commit
72e4d036c2
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user