From fc07796acf63aed3a4c64e73bb95163c5f464ee5 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 5 Mar 2026 00:05:22 -1000 Subject: [PATCH] [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(). --- esphome/components/wifi/wifi_component_pico_w.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/esphome/components/wifi/wifi_component_pico_w.cpp b/esphome/components/wifi/wifi_component_pico_w.cpp index 6927c99c79..b9758b6963 100644 --- a/esphome/components/wifi/wifi_component_pico_w.cpp +++ b/esphome/components/wifi/wifi_component_pico_w.cpp @@ -35,11 +35,6 @@ bool WiFiComponent::wifi_mode_(optional sta, optional 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(); } }