mirror of
https://github.com/esphome/esphome.git
synced 2026-07-11 01:15:33 +00:00
[wifi] Remove WiFi.disconnect() from wifi_mode_ to fix AP_STA mode
WiFi.disconnect() sets _wifiHWInitted=false and _mode=WIFI_OFF, which causes beginAP to run in AP-only mode (_mode=WIFI_AP). In AP-only mode, subsequent beginNoBlock() calls hit the ESP8266 compatibility hack in _beginInternal that redirects to beginAP() instead of starting a STA connection, creating a connect/disconnect loop. Without WiFi.disconnect(), _wifiHWInitted stays true and beginAP correctly enters AP_STA mode, allowing STA reconnection attempts to work properly alongside the fallback AP. The wifi_sta_connected() helper from the previous commit is sufficient to prevent false CONNECTED reports by checking WiFi.localIP() instead of the AP-contaminated WiFi.status().
This commit is contained in:
@@ -35,11 +35,6 @@ bool WiFiComponent::wifi_mode_(optional<bool> sta, optional<bool> ap) {
|
||||
if (sta.has_value()) {
|
||||
if (sta.value()) {
|
||||
cyw43_wifi_set_up(&cyw43_state, CYW43_ITF_STA, true, CYW43_COUNTRY_WORLDWIDE);
|
||||
} else {
|
||||
// Disconnect STA to clear stale link state (e.g. CYW43_LINK_JOIN from a
|
||||
// timed-out connection). Without this, restart_adapter() leaves the STA
|
||||
// interface joined and wifi_sta_connect_status_() can falsely report CONNECTED.
|
||||
WiFi.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user