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'.
This commit is contained in:
@@ -332,16 +332,29 @@ void loop() {
|
|||||||
|
|
||||||
if (wifiRetry.currentRetry >= 5 && WiFi.getMode() != WIFI_AP_STA) {
|
if (wifiRetry.currentRetry >= 5 && WiFi.getMode() != WIFI_AP_STA) {
|
||||||
Serial.println("Enabling fallback AP (dual mode)");
|
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.mode(WIFI_AP_STA);
|
||||||
WiFi.softAP("TJ56654-Setup", "12345678");
|
WiFi.softAP("TJ56654-Setup", "12345678");
|
||||||
Serial.print("Fallback AP IP: ");
|
Serial.print("Fallback AP IP: ");
|
||||||
Serial.println(WiFi.softAPIP());
|
Serial.println(WiFi.softAPIP());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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) {
|
if (strlen(config.password) > 0) {
|
||||||
WiFi.begin(config.ssid, config.password);
|
WiFi.begin(config.ssid, config.password);
|
||||||
} else {
|
} else {
|
||||||
WiFi.begin();
|
WiFi.begin(config.ssid);
|
||||||
|
}
|
||||||
|
WiFi.mode(WIFI_AP_STA); // Restore AP_STA after begin() may have reset it
|
||||||
|
} else {
|
||||||
|
if (strlen(config.password) > 0) {
|
||||||
|
WiFi.begin(config.ssid, config.password);
|
||||||
|
} else {
|
||||||
|
WiFi.begin(config.ssid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
wifiConnState = WIFI_CONN_CONNECTING;
|
wifiConnState = WIFI_CONN_CONNECTING;
|
||||||
wifiConnectStart = millis();
|
wifiConnectStart = millis();
|
||||||
|
|||||||
Reference in New Issue
Block a user