From bad6a622269bd85537d77662e7862ead4005c2f8 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 4 Mar 2026 23:39:58 -1000 Subject: [PATCH 01/11] [wifi] Fix RP2040 falsely reporting WiFi connected after AP fallback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two bugs combined to make the RP2040 Pico W immediately think it was connected to WiFi after starting the fallback AP, causing it to disable the AP and stop retrying: 1. wifi_mode_(false, {}) was a no-op for STA disable — restart_adapter() calls this to tear down STA, but the implementation only handled sta=true. The CYW43 STA link state remained CYW43_LINK_JOIN from the timed-out connection attempt. 2. wifi_ap_ip_config_() called WiFi.config(192.168.4.1) which configured the STA interface's IP (not the AP's). When wifi_sta_connect_status_() checked WiFi.status(), CYW43lwIP::status() saw CYW43_LINK_JOIN + localIP().isSet() and returned WL_CONNECTED. Fix wifi_mode_() to call WiFi.disconnect() when sta=false to clear stale link state. Remove the WiFi.config() call from wifi_ap_ip_config_() since WiFi.beginAP() already configures the AP IP internally. Also fix wifi_soft_ap_ip() to use WiFi.softAPIP() instead of WiFi.localIP(). --- .../components/wifi/wifi_component_pico_w.cpp | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/esphome/components/wifi/wifi_component_pico_w.cpp b/esphome/components/wifi/wifi_component_pico_w.cpp index 270425d8c2..f371495975 100644 --- a/esphome/components/wifi/wifi_component_pico_w.cpp +++ b/esphome/components/wifi/wifi_component_pico_w.cpp @@ -27,6 +27,11 @@ 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(); } } @@ -188,19 +193,11 @@ bool WiFiComponent::wifi_scan_start_(bool passive) { #ifdef USE_WIFI_AP bool WiFiComponent::wifi_ap_ip_config_(const optional &manual_ip) { - esphome::network::IPAddress ip_address, gateway, subnet, dns; - if (manual_ip.has_value()) { - ip_address = manual_ip->static_ip; - gateway = manual_ip->gateway; - subnet = manual_ip->subnet; - dns = manual_ip->static_ip; - } else { - ip_address = network::IPAddress(192, 168, 4, 1); - gateway = network::IPAddress(192, 168, 4, 1); - subnet = network::IPAddress(255, 255, 255, 0); - dns = network::IPAddress(192, 168, 4, 1); - } - WiFi.config(ip_address, dns, gateway, subnet); + // AP IP is configured by WiFi.beginAP() internally using defaults (192.168.4.1). + // Do NOT use WiFi.config() here — that configures the STA interface's IP, which + // poisons the STA localIP() and causes wifi_sta_connect_status_() to falsely + // report CONNECTED when the AP is active. + // Manual AP IP is not currently supported on RP2040. return true; } @@ -224,7 +221,7 @@ bool WiFiComponent::wifi_start_ap_(const WiFiAP &ap) { return true; } -network::IPAddress WiFiComponent::wifi_soft_ap_ip() { return {(const ip_addr_t *) WiFi.localIP()}; } +network::IPAddress WiFiComponent::wifi_soft_ap_ip() { return {(const ip_addr_t *) WiFi.softAPIP()}; } #endif // USE_WIFI_AP bool WiFiComponent::wifi_disconnect_() { From b71965b031d8fa82fbd9761e9413daa19b152942 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 4 Mar 2026 23:56:27 -1000 Subject: [PATCH 02/11] fix --- esphome/components/wifi/wifi_component_pico_w.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/esphome/components/wifi/wifi_component_pico_w.cpp b/esphome/components/wifi/wifi_component_pico_w.cpp index f371495975..76ccaa47d3 100644 --- a/esphome/components/wifi/wifi_component_pico_w.cpp +++ b/esphome/components/wifi/wifi_component_pico_w.cpp @@ -134,8 +134,11 @@ WiFiSTAConnectStatus WiFiComponent::wifi_sta_connect_status_() const { int status = cyw43_wifi_link_status(&cyw43_state, CYW43_ITF_STA); switch (status) { case CYW43_LINK_JOIN: - // WiFi joined, check if we have an IP address via the Arduino framework's WiFi class - if (WiFi.status() == WL_CONNECTED) { + // Check if STA has an IP address directly via WiFi.localIP() which returns + // the STA-specific IP (_wifi.localIP()). Do NOT use WiFi.status() here — in + // AP-only mode it unconditionally returns WL_CONNECTED regardless of STA state, + // causing false CONNECTED reports when the fallback AP is active. + if (WiFi.localIP().isSet()) { return WiFiSTAConnectStatus::CONNECTED; } return WiFiSTAConnectStatus::CONNECTING; @@ -285,9 +288,9 @@ void WiFiComponent::wifi_loop_() { // Poll for connection state changes // The arduino-pico WiFi library doesn't have event callbacks like ESP8266/ESP32, // so we need to poll the link status to detect state changes. - // Use WiFi.connected() which checks both the WiFi link and IP address via the - // Arduino framework's own netif (not the SDK's uninitialized one). - bool is_connected = WiFi.connected(); + // Check STA link status + IP directly instead of WiFi.connected() which returns + // true in AP-only mode regardless of STA state. + bool is_connected = cyw43_wifi_link_status(&cyw43_state, CYW43_ITF_STA) == CYW43_LINK_JOIN && WiFi.localIP().isSet(); // Detect connection state change if (is_connected && !s_sta_was_connected) { From de85e75bfbad9cdd2656724fc19628d39b031717 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 4 Mar 2026 23:58:42 -1000 Subject: [PATCH 03/11] fix --- .../components/wifi/wifi_component_pico_w.cpp | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/esphome/components/wifi/wifi_component_pico_w.cpp b/esphome/components/wifi/wifi_component_pico_w.cpp index 76ccaa47d3..6927c99c79 100644 --- a/esphome/components/wifi/wifi_component_pico_w.cpp +++ b/esphome/components/wifi/wifi_component_pico_w.cpp @@ -18,6 +18,14 @@ namespace esphome::wifi { static const char *const TAG = "wifi_pico_w"; +// Check if STA is fully connected (WiFi joined + has IP address). +// Do NOT use WiFi.status() or WiFi.connected() for this — in AP-only mode they +// unconditionally return true regardless of STA state, causing false positives +// when the fallback AP is active. +static bool wifi_sta_connected() { + return cyw43_wifi_link_status(&cyw43_state, CYW43_ITF_STA) == CYW43_LINK_JOIN && WiFi.localIP().isSet(); +} + // Track previous state for detecting changes static bool s_sta_was_connected = false; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) static bool s_sta_had_ip = false; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) @@ -134,11 +142,8 @@ WiFiSTAConnectStatus WiFiComponent::wifi_sta_connect_status_() const { int status = cyw43_wifi_link_status(&cyw43_state, CYW43_ITF_STA); switch (status) { case CYW43_LINK_JOIN: - // Check if STA has an IP address directly via WiFi.localIP() which returns - // the STA-specific IP (_wifi.localIP()). Do NOT use WiFi.status() here — in - // AP-only mode it unconditionally returns WL_CONNECTED regardless of STA state, - // causing false CONNECTED reports when the fallback AP is active. - if (WiFi.localIP().isSet()) { + // WiFi joined, check if STA has an IP address via wifi_sta_connected() + if (wifi_sta_connected()) { return WiFiSTAConnectStatus::CONNECTED; } return WiFiSTAConnectStatus::CONNECTING; @@ -251,7 +256,7 @@ const char *WiFiComponent::wifi_ssid_to(std::span buffer buffer[len] = '\0'; return buffer.data(); } -int8_t WiFiComponent::wifi_rssi() { return WiFi.status() == WL_CONNECTED ? WiFi.RSSI() : WIFI_RSSI_DISCONNECTED; } +int8_t WiFiComponent::wifi_rssi() { return this->is_connected() ? WiFi.RSSI() : WIFI_RSSI_DISCONNECTED; } int32_t WiFiComponent::get_wifi_channel() { return WiFi.channel(); } network::IPAddresses WiFiComponent::wifi_sta_ip_addresses() { @@ -288,9 +293,7 @@ void WiFiComponent::wifi_loop_() { // Poll for connection state changes // The arduino-pico WiFi library doesn't have event callbacks like ESP8266/ESP32, // so we need to poll the link status to detect state changes. - // Check STA link status + IP directly instead of WiFi.connected() which returns - // true in AP-only mode regardless of STA state. - bool is_connected = cyw43_wifi_link_status(&cyw43_state, CYW43_ITF_STA) == CYW43_LINK_JOIN && WiFi.localIP().isSet(); + bool is_connected = wifi_sta_connected(); // Detect connection state change if (is_connected && !s_sta_was_connected) { From fc07796acf63aed3a4c64e73bb95163c5f464ee5 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 5 Mar 2026 00:05:22 -1000 Subject: [PATCH 04/11] [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(); } } From 58329c52de78f1097d5e552d3517c1b2b48abec4 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 5 Mar 2026 00:37:42 -1000 Subject: [PATCH 05/11] bump --- .clang-tidy.hash | 2 +- esphome/components/rp2040/__init__.py | 6 +-- .../components/wifi/wifi_component_pico_w.cpp | 44 +++++++++++++++++-- platformio.ini | 2 +- 4 files changed, 45 insertions(+), 9 deletions(-) diff --git a/.clang-tidy.hash b/.clang-tidy.hash index 767da3f33e..adcebadeb4 100644 --- a/.clang-tidy.hash +++ b/.clang-tidy.hash @@ -1 +1 @@ -b97e16a84153b2a4cfc51137cd6121db3c32374504b2bea55144413b3e573052 +b6f8c16c1ddd222134bf4a71910b4c832e764e23caf49f9bce3280b079955fcf diff --git a/esphome/components/rp2040/__init__.py b/esphome/components/rp2040/__init__.py index ea269a47c5..1442a0a7f7 100644 --- a/esphome/components/rp2040/__init__.py +++ b/esphome/components/rp2040/__init__.py @@ -91,7 +91,7 @@ def _parse_platform_version(value): # The default/recommended arduino framework version # - https://github.com/earlephilhower/arduino-pico/releases # - https://api.registry.platformio.org/v3/packages/earlephilhower/tool/framework-arduinopico -RECOMMENDED_ARDUINO_FRAMEWORK_VERSION = cv.Version(5, 5, 0) +RECOMMENDED_ARDUINO_FRAMEWORK_VERSION = cv.Version(5, 5, 1) # The raspberrypi platform version to use for arduino frameworks # - https://github.com/maxgerhardt/platform-raspberrypi/tags @@ -101,8 +101,8 @@ RECOMMENDED_ARDUINO_PLATFORM_VERSION = "v1.4.0-gcc14-arduinopico460" def _arduino_check_versions(value): value = value.copy() lookups = { - "dev": (cv.Version(5, 5, 0), "https://github.com/earlephilhower/arduino-pico"), - "latest": (cv.Version(5, 5, 0), None), + "dev": (cv.Version(5, 5, 1), "https://github.com/earlephilhower/arduino-pico"), + "latest": (cv.Version(5, 5, 1), None), "recommended": (RECOMMENDED_ARDUINO_FRAMEWORK_VERSION, None), } diff --git a/esphome/components/wifi/wifi_component_pico_w.cpp b/esphome/components/wifi/wifi_component_pico_w.cpp index b9758b6963..dd56170493 100644 --- a/esphome/components/wifi/wifi_component_pico_w.cpp +++ b/esphome/components/wifi/wifi_component_pico_w.cpp @@ -23,7 +23,19 @@ static const char *const TAG = "wifi_pico_w"; // unconditionally return true regardless of STA state, causing false positives // when the fallback AP is active. static bool wifi_sta_connected() { - return cyw43_wifi_link_status(&cyw43_state, CYW43_ITF_STA) == CYW43_LINK_JOIN && WiFi.localIP().isSet(); + int link = cyw43_wifi_link_status(&cyw43_state, CYW43_ITF_STA); + bool ip_set = WiFi.localIP().isSet(); + if (link == CYW43_LINK_JOIN && ip_set) { + // Verify the IP is a real STA IP, not the AP's IP leaking through + IPAddress local = WiFi.localIP(); + IPAddress ap_ip = WiFi.softAPIP(); + if (local == ap_ip) { + ESP_LOGV(TAG, "wifi_sta_connected: localIP %s matches AP IP, ignoring", local.toString().c_str()); + return false; + } + return true; + } + return false; } // Track previous state for detecting changes @@ -32,6 +44,8 @@ static bool s_sta_had_ip = false; // NOLINT(cppcoreguidelines-avoid-non- static size_t s_scan_result_count = 0; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) bool WiFiComponent::wifi_mode_(optional sta, optional ap) { + ESP_LOGD(TAG, "wifi_mode_(sta=%s, ap=%s)", sta.has_value() ? (sta.value() ? "true" : "false") : "nullopt", + ap.has_value() ? (ap.value() ? "true" : "false") : "nullopt"); if (sta.has_value()) { if (sta.value()) { cyw43_wifi_set_up(&cyw43_state, CYW43_ITF_STA, true, CYW43_COUNTRY_WORLDWIDE); @@ -86,12 +100,19 @@ bool WiFiComponent::wifi_sta_connect_(const WiFiAP &ap) { return false; #endif + ESP_LOGD(TAG, "wifi_sta_connect_: STA link=%d, WiFi.status()=%d, mode=%d, localIP=%s, softAPIP=%s", + cyw43_wifi_link_status(&cyw43_state, CYW43_ITF_STA), WiFi.status(), (int) WiFi.getMode(), + WiFi.localIP().toString().c_str(), WiFi.softAPIP().toString().c_str()); + // Use beginNoBlock to avoid WiFi.begin()'s additional 2x timeout wait loop on top of // CYW43::begin()'s internal blocking join. CYW43::begin() blocks for up to 10 seconds // (default timeout) to complete the join - this is required because the LwipIntfDev netif // setup depends on begin() succeeding. beginNoBlock() skips the outer wait loop, saving // up to 20 additional seconds of blocking per attempt. auto ret = WiFi.beginNoBlock(ap.ssid_.c_str(), ap.password_.c_str()); + ESP_LOGD(TAG, "wifi_sta_connect_: beginNoBlock returned %d, STA link=%d, mode=%d, localIP=%s", ret, + cyw43_wifi_link_status(&cyw43_state, CYW43_ITF_STA), (int) WiFi.getMode(), + WiFi.localIP().toString().c_str()); if (ret == WL_IDLE_STATUS) return false; @@ -135,6 +156,9 @@ WiFiSTAConnectStatus WiFiComponent::wifi_sta_connect_status_() const { // flags and would only fall through to cyw43_wifi_link_status when the flags aren't set. // Using cyw43_wifi_link_status directly gives us the actual WiFi radio join state. int status = cyw43_wifi_link_status(&cyw43_state, CYW43_ITF_STA); + int ap_status = cyw43_wifi_link_status(&cyw43_state, CYW43_ITF_AP); + ESP_LOGV(TAG, "connect_status: STA link=%d, AP link=%d, localIP=%s, softAPIP=%s, WiFi.status()=%d", status, ap_status, + WiFi.localIP().toString().c_str(), WiFi.softAPIP().toString().c_str(), WiFi.status()); switch (status) { case CYW43_LINK_JOIN: // WiFi joined, check if STA has an IP address via wifi_sta_connected() @@ -205,6 +229,9 @@ bool WiFiComponent::wifi_ap_ip_config_(const optional &manual_ip) { } bool WiFiComponent::wifi_start_ap_(const WiFiAP &ap) { + ESP_LOGD(TAG, "wifi_start_ap_: STA link=%d, AP link=%d, WiFi.status()=%d, mode=%d, localIP=%s", + cyw43_wifi_link_status(&cyw43_state, CYW43_ITF_STA), cyw43_wifi_link_status(&cyw43_state, CYW43_ITF_AP), + WiFi.status(), (int) WiFi.getMode(), WiFi.localIP().toString().c_str()); if (!this->wifi_mode_({}, true)) return false; #ifdef USE_WIFI_MANUAL_IP @@ -220,6 +247,8 @@ bool WiFiComponent::wifi_start_ap_(const WiFiAP &ap) { #endif WiFi.beginAP(ap.ssid_.c_str(), ap.password_.c_str(), ap.has_channel() ? ap.get_channel() : 1); + ESP_LOGD(TAG, "wifi_start_ap_: after beginAP, WiFi.status()=%d, mode=%d, softAPIP=%s, localIP=%s", WiFi.status(), + (int) WiFi.getMode(), WiFi.softAPIP().toString().c_str(), WiFi.localIP().toString().c_str()); return true; } @@ -228,9 +257,16 @@ network::IPAddress WiFiComponent::wifi_soft_ap_ip() { return {(const ip_addr_t * #endif // USE_WIFI_AP bool WiFiComponent::wifi_disconnect_() { - // Use Arduino WiFi.disconnect() instead of raw cyw43_wifi_leave() to properly - // clean up the lwIP netif, DHCP client, and internal Arduino state. - WiFi.disconnect(); + // Use cyw43_wifi_leave() directly instead of WiFi.disconnect(). + // WiFi.disconnect() sets _wifiHWInitted=false and _mode=WIFI_OFF in the Arduino + // framework, which causes WiFi.beginAP() to enter AP-only mode (IP 192.168.42.1) + // instead of AP_STA mode (IP 192.168.4.1). In AP-only mode, _beginInternal() + // redirects all subsequent STA connect attempts to beginAP() via the ESP8266 + // compat hack, creating an infinite connect/disconnect loop. + ESP_LOGD(TAG, "wifi_disconnect_: STA link=%d, AP link=%d, WiFi.status()=%d, mode=%d", + cyw43_wifi_link_status(&cyw43_state, CYW43_ITF_STA), cyw43_wifi_link_status(&cyw43_state, CYW43_ITF_AP), + WiFi.status(), (int) WiFi.getMode()); + cyw43_wifi_leave(&cyw43_state, CYW43_ITF_STA); return true; } diff --git a/platformio.ini b/platformio.ini index 16a1b18211..87f992759c 100644 --- a/platformio.ini +++ b/platformio.ini @@ -196,7 +196,7 @@ board_build.filesystem_size = 0.5m platform = https://github.com/maxgerhardt/platform-raspberrypi.git#v1.4.0-gcc14-arduinopico460 platform_packages = ; earlephilhower/framework-arduinopico@~1.20602.0 ; Cannot use the platformio package until old releases stop getting deleted - earlephilhower/framework-arduinopico@https://github.com/earlephilhower/arduino-pico/releases/download/5.5.0/rp2040-5.5.0.zip + earlephilhower/framework-arduinopico@https://github.com/earlephilhower/arduino-pico/releases/download/5.5.1/rp2040-5.5.1.zip framework = arduino lib_deps = From 837ac62b7e3234a5499ec32e79efd8b70ce35913 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 5 Mar 2026 00:46:52 -1000 Subject: [PATCH 06/11] fix --- esphome/components/wifi/wifi_component_pico_w.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/esphome/components/wifi/wifi_component_pico_w.cpp b/esphome/components/wifi/wifi_component_pico_w.cpp index dd56170493..a2eb898b7b 100644 --- a/esphome/components/wifi/wifi_component_pico_w.cpp +++ b/esphome/components/wifi/wifi_component_pico_w.cpp @@ -49,6 +49,10 @@ 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 { + // Leave the STA network so the radio is free for scanning. + // Use cyw43_wifi_leave directly to avoid corrupting Arduino framework state. + cyw43_wifi_leave(&cyw43_state, CYW43_ITF_STA); } } @@ -246,7 +250,10 @@ bool WiFiComponent::wifi_start_ap_(const WiFiAP &ap) { } #endif - WiFi.beginAP(ap.ssid_.c_str(), ap.password_.c_str(), ap.has_channel() ? ap.get_channel() : 1); + // Pass nullptr for empty password — CYW43 uses the password pointer (not length) + // to choose between OPEN and WPA2 auth mode. + const char *ap_password = ap.password_.empty() ? nullptr : ap.password_.c_str(); + WiFi.beginAP(ap.ssid_.c_str(), ap_password, ap.has_channel() ? ap.get_channel() : 1); ESP_LOGD(TAG, "wifi_start_ap_: after beginAP, WiFi.status()=%d, mode=%d, softAPIP=%s, localIP=%s", WiFi.status(), (int) WiFi.getMode(), WiFi.softAPIP().toString().c_str(), WiFi.localIP().toString().c_str()); From 1ea0ea935fbc4adf1b560224fb69fb29cf2301b7 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 5 Mar 2026 00:52:24 -1000 Subject: [PATCH 07/11] Remove debug logging --- .../components/wifi/wifi_component_pico_w.cpp | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/esphome/components/wifi/wifi_component_pico_w.cpp b/esphome/components/wifi/wifi_component_pico_w.cpp index a2eb898b7b..4b141d99e4 100644 --- a/esphome/components/wifi/wifi_component_pico_w.cpp +++ b/esphome/components/wifi/wifi_component_pico_w.cpp @@ -44,8 +44,6 @@ static bool s_sta_had_ip = false; // NOLINT(cppcoreguidelines-avoid-non- static size_t s_scan_result_count = 0; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) bool WiFiComponent::wifi_mode_(optional sta, optional ap) { - ESP_LOGD(TAG, "wifi_mode_(sta=%s, ap=%s)", sta.has_value() ? (sta.value() ? "true" : "false") : "nullopt", - ap.has_value() ? (ap.value() ? "true" : "false") : "nullopt"); if (sta.has_value()) { if (sta.value()) { cyw43_wifi_set_up(&cyw43_state, CYW43_ITF_STA, true, CYW43_COUNTRY_WORLDWIDE); @@ -104,19 +102,12 @@ bool WiFiComponent::wifi_sta_connect_(const WiFiAP &ap) { return false; #endif - ESP_LOGD(TAG, "wifi_sta_connect_: STA link=%d, WiFi.status()=%d, mode=%d, localIP=%s, softAPIP=%s", - cyw43_wifi_link_status(&cyw43_state, CYW43_ITF_STA), WiFi.status(), (int) WiFi.getMode(), - WiFi.localIP().toString().c_str(), WiFi.softAPIP().toString().c_str()); - // Use beginNoBlock to avoid WiFi.begin()'s additional 2x timeout wait loop on top of // CYW43::begin()'s internal blocking join. CYW43::begin() blocks for up to 10 seconds // (default timeout) to complete the join - this is required because the LwipIntfDev netif // setup depends on begin() succeeding. beginNoBlock() skips the outer wait loop, saving // up to 20 additional seconds of blocking per attempt. auto ret = WiFi.beginNoBlock(ap.ssid_.c_str(), ap.password_.c_str()); - ESP_LOGD(TAG, "wifi_sta_connect_: beginNoBlock returned %d, STA link=%d, mode=%d, localIP=%s", ret, - cyw43_wifi_link_status(&cyw43_state, CYW43_ITF_STA), (int) WiFi.getMode(), - WiFi.localIP().toString().c_str()); if (ret == WL_IDLE_STATUS) return false; @@ -160,9 +151,6 @@ WiFiSTAConnectStatus WiFiComponent::wifi_sta_connect_status_() const { // flags and would only fall through to cyw43_wifi_link_status when the flags aren't set. // Using cyw43_wifi_link_status directly gives us the actual WiFi radio join state. int status = cyw43_wifi_link_status(&cyw43_state, CYW43_ITF_STA); - int ap_status = cyw43_wifi_link_status(&cyw43_state, CYW43_ITF_AP); - ESP_LOGV(TAG, "connect_status: STA link=%d, AP link=%d, localIP=%s, softAPIP=%s, WiFi.status()=%d", status, ap_status, - WiFi.localIP().toString().c_str(), WiFi.softAPIP().toString().c_str(), WiFi.status()); switch (status) { case CYW43_LINK_JOIN: // WiFi joined, check if STA has an IP address via wifi_sta_connected() @@ -233,9 +221,6 @@ bool WiFiComponent::wifi_ap_ip_config_(const optional &manual_ip) { } bool WiFiComponent::wifi_start_ap_(const WiFiAP &ap) { - ESP_LOGD(TAG, "wifi_start_ap_: STA link=%d, AP link=%d, WiFi.status()=%d, mode=%d, localIP=%s", - cyw43_wifi_link_status(&cyw43_state, CYW43_ITF_STA), cyw43_wifi_link_status(&cyw43_state, CYW43_ITF_AP), - WiFi.status(), (int) WiFi.getMode(), WiFi.localIP().toString().c_str()); if (!this->wifi_mode_({}, true)) return false; #ifdef USE_WIFI_MANUAL_IP @@ -254,8 +239,6 @@ bool WiFiComponent::wifi_start_ap_(const WiFiAP &ap) { // to choose between OPEN and WPA2 auth mode. const char *ap_password = ap.password_.empty() ? nullptr : ap.password_.c_str(); WiFi.beginAP(ap.ssid_.c_str(), ap_password, ap.has_channel() ? ap.get_channel() : 1); - ESP_LOGD(TAG, "wifi_start_ap_: after beginAP, WiFi.status()=%d, mode=%d, softAPIP=%s, localIP=%s", WiFi.status(), - (int) WiFi.getMode(), WiFi.softAPIP().toString().c_str(), WiFi.localIP().toString().c_str()); return true; } @@ -270,9 +253,6 @@ bool WiFiComponent::wifi_disconnect_() { // instead of AP_STA mode (IP 192.168.4.1). In AP-only mode, _beginInternal() // redirects all subsequent STA connect attempts to beginAP() via the ESP8266 // compat hack, creating an infinite connect/disconnect loop. - ESP_LOGD(TAG, "wifi_disconnect_: STA link=%d, AP link=%d, WiFi.status()=%d, mode=%d", - cyw43_wifi_link_status(&cyw43_state, CYW43_ITF_STA), cyw43_wifi_link_status(&cyw43_state, CYW43_ITF_AP), - WiFi.status(), (int) WiFi.getMode()); cyw43_wifi_leave(&cyw43_state, CYW43_ITF_STA); return true; } From caa50ca1990d929bc178fdb34a3659fdd9656b3d Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 5 Mar 2026 01:05:30 -1000 Subject: [PATCH 08/11] [captive_portal] Enable support for RP2040 --- esphome/components/captive_portal/__init__.py | 9 ++++----- tests/components/captive_portal/test.rp2040-ard.yaml | 1 + 2 files changed, 5 insertions(+), 5 deletions(-) create mode 100644 tests/components/captive_portal/test.rp2040-ard.yaml diff --git a/esphome/components/captive_portal/__init__.py b/esphome/components/captive_portal/__init__.py index 6c190814c0..cd877fc879 100644 --- a/esphome/components/captive_portal/__init__.py +++ b/esphome/components/captive_portal/__init__.py @@ -13,6 +13,7 @@ from esphome.const import ( PLATFORM_ESP32, PLATFORM_ESP8266, PLATFORM_LN882X, + PLATFORM_RP2040, PLATFORM_RTL87XX, PlatformFramework, ) @@ -53,6 +54,7 @@ CONFIG_SCHEMA = cv.All( PLATFORM_ESP8266, PLATFORM_BK72XX, PLATFORM_LN882X, + PLATFORM_RP2040, PLATFORM_RTL87XX, ] ), @@ -103,11 +105,8 @@ async def to_code(config): if config[CONF_COMPRESSION] == "gzip": cg.add_define("USE_CAPTIVE_PORTAL_GZIP") - if CORE.using_arduino: - if CORE.is_esp8266: - cg.add_library("DNSServer", None) - if CORE.is_libretiny: - cg.add_library("DNSServer", None) + if CORE.using_arduino and (CORE.is_esp8266 or CORE.is_libretiny or CORE.is_rp2040): + cg.add_library("DNSServer", None) # Only compile the ESP-IDF DNS server when using ESP-IDF framework diff --git a/tests/components/captive_portal/test.rp2040-ard.yaml b/tests/components/captive_portal/test.rp2040-ard.yaml new file mode 100644 index 0000000000..dade44d145 --- /dev/null +++ b/tests/components/captive_portal/test.rp2040-ard.yaml @@ -0,0 +1 @@ +<<: !include common.yaml From 27898841337cc6ae845625f26011396b0e42cf15 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 5 Mar 2026 01:14:52 -1000 Subject: [PATCH 09/11] Use is_connected_() for wifi_rssi() to check internal state --- esphome/components/wifi/wifi_component_pico_w.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esphome/components/wifi/wifi_component_pico_w.cpp b/esphome/components/wifi/wifi_component_pico_w.cpp index 4b141d99e4..b1259b7fa2 100644 --- a/esphome/components/wifi/wifi_component_pico_w.cpp +++ b/esphome/components/wifi/wifi_component_pico_w.cpp @@ -274,7 +274,7 @@ const char *WiFiComponent::wifi_ssid_to(std::span buffer buffer[len] = '\0'; return buffer.data(); } -int8_t WiFiComponent::wifi_rssi() { return this->is_connected() ? WiFi.RSSI() : WIFI_RSSI_DISCONNECTED; } +int8_t WiFiComponent::wifi_rssi() { return this->is_connected_() ? WiFi.RSSI() : WIFI_RSSI_DISCONNECTED; } int32_t WiFiComponent::get_wifi_channel() { return WiFi.channel(); } network::IPAddresses WiFiComponent::wifi_sta_ip_addresses() { From 7b071793fb8c48b2de263e32f2115a378eb0d7a3 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 5 Mar 2026 01:05:30 -1000 Subject: [PATCH 10/11] [captive_portal] Enable support for RP2040 --- esphome/components/captive_portal/__init__.py | 9 ++++----- tests/components/captive_portal/test.rp2040-ard.yaml | 1 + 2 files changed, 5 insertions(+), 5 deletions(-) create mode 100644 tests/components/captive_portal/test.rp2040-ard.yaml diff --git a/esphome/components/captive_portal/__init__.py b/esphome/components/captive_portal/__init__.py index 6c190814c0..cd877fc879 100644 --- a/esphome/components/captive_portal/__init__.py +++ b/esphome/components/captive_portal/__init__.py @@ -13,6 +13,7 @@ from esphome.const import ( PLATFORM_ESP32, PLATFORM_ESP8266, PLATFORM_LN882X, + PLATFORM_RP2040, PLATFORM_RTL87XX, PlatformFramework, ) @@ -53,6 +54,7 @@ CONFIG_SCHEMA = cv.All( PLATFORM_ESP8266, PLATFORM_BK72XX, PLATFORM_LN882X, + PLATFORM_RP2040, PLATFORM_RTL87XX, ] ), @@ -103,11 +105,8 @@ async def to_code(config): if config[CONF_COMPRESSION] == "gzip": cg.add_define("USE_CAPTIVE_PORTAL_GZIP") - if CORE.using_arduino: - if CORE.is_esp8266: - cg.add_library("DNSServer", None) - if CORE.is_libretiny: - cg.add_library("DNSServer", None) + if CORE.using_arduino and (CORE.is_esp8266 or CORE.is_libretiny or CORE.is_rp2040): + cg.add_library("DNSServer", None) # Only compile the ESP-IDF DNS server when using ESP-IDF framework diff --git a/tests/components/captive_portal/test.rp2040-ard.yaml b/tests/components/captive_portal/test.rp2040-ard.yaml new file mode 100644 index 0000000000..dade44d145 --- /dev/null +++ b/tests/components/captive_portal/test.rp2040-ard.yaml @@ -0,0 +1 @@ +<<: !include common.yaml From 296b412bd34d248248ada5bdd966d1f38db08bfa Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 5 Mar 2026 01:16:37 -1000 Subject: [PATCH 11/11] Fix AP not being disabled and ap_started_ when ap is nullopt --- esphome/components/wifi/wifi_component_pico_w.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/esphome/components/wifi/wifi_component_pico_w.cpp b/esphome/components/wifi/wifi_component_pico_w.cpp index b1259b7fa2..2a7e64e377 100644 --- a/esphome/components/wifi/wifi_component_pico_w.cpp +++ b/esphome/components/wifi/wifi_component_pico_w.cpp @@ -54,14 +54,14 @@ bool WiFiComponent::wifi_mode_(optional sta, optional ap) { } } - bool ap_state = false; if (ap.has_value()) { if (ap.value()) { cyw43_wifi_set_up(&cyw43_state, CYW43_ITF_AP, true, CYW43_COUNTRY_WORLDWIDE); - ap_state = true; + } else { + cyw43_wifi_set_up(&cyw43_state, CYW43_ITF_AP, false, CYW43_COUNTRY_WORLDWIDE); } + this->ap_started_ = ap.value(); } - this->ap_started_ = ap_state; return true; }