From 02834bada1046a5fb9a633c37f1eb69511f553e4 Mon Sep 17 00:00:00 2001 From: Alex Petrochenko Date: Mon, 18 May 2026 20:52:14 +0100 Subject: [PATCH] fix(wifi): preserve AP_STA mode after WiFi.begin() kills the AP WiFi.begin() internally resets mode to STA, immediately destroying the fallback AP that was just created. Fix: restore WIFI_AP_STA mode after begin() when in AP mode, so TJ56654-Setup stays visible. This was why the fallback AP was never visible despite being 'created'. --- firmware/weather_clock/weather_clock.ino | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/firmware/weather_clock/weather_clock.ino b/firmware/weather_clock/weather_clock.ino index ec512ff..83294b2 100644 --- a/firmware/weather_clock/weather_clock.ino +++ b/firmware/weather_clock/weather_clock.ino @@ -332,16 +332,29 @@ void loop() { if (wifiRetry.currentRetry >= 5 && WiFi.getMode() != WIFI_AP_STA) { Serial.println("Enabling fallback AP (dual mode)"); + // Must set mode BEFORE WiFi.begin() — begin() resets mode to STA killing the AP WiFi.mode(WIFI_AP_STA); WiFi.softAP("TJ56654-Setup", "12345678"); Serial.print("Fallback AP IP: "); Serial.println(WiFi.softAPIP()); } - if (strlen(config.password) > 0) { - WiFi.begin(config.ssid, config.password); + // Reconnect STA side without changing mode (preserves AP_STA if active) + if (WiFi.getMode() == WIFI_AP_STA) { + // Use low-level reconnect to keep AP alive + WiFi.disconnect(false); + if (strlen(config.password) > 0) { + WiFi.begin(config.ssid, config.password); + } else { + WiFi.begin(config.ssid); + } + WiFi.mode(WIFI_AP_STA); // Restore AP_STA after begin() may have reset it } else { - WiFi.begin(); + if (strlen(config.password) > 0) { + WiFi.begin(config.ssid, config.password); + } else { + WiFi.begin(config.ssid); + } } wifiConnState = WIFI_CONN_CONNECTING; wifiConnectStart = millis();