From 7e1d25859cacefcd8cc3dca25f133f921129bbc6 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 26 Feb 2026 11:39:42 -1000 Subject: [PATCH] [wifi] Enable CYW43 STA mode before scanning on RP2040 Call cyw43_arch_enable_sta_mode() in wifi_mode_() when STA is requested. Without this, cyw43_wifi_scan() fails on initial boot because the radio isn't initialized yet - it only got enabled later inside beginNoBlock(). This caused the state machine to skip scanning, fall through to RETRY_HIDDEN, and do a wasteful blind SSID-only connect for non-hidden networks. --- esphome/components/wifi/wifi_component_pico_w.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/esphome/components/wifi/wifi_component_pico_w.cpp b/esphome/components/wifi/wifi_component_pico_w.cpp index e4a6dbaaa4..b67d689e3a 100644 --- a/esphome/components/wifi/wifi_component_pico_w.cpp +++ b/esphome/components/wifi/wifi_component_pico_w.cpp @@ -24,8 +24,11 @@ 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) { - // STA mode is enabled by WiFi.beginNoBlock() via cyw43_arch_enable_sta_mode(), - // so we don't need to call cyw43_wifi_set_up() directly for STA. + if (sta.has_value() && sta.value()) { + // Enable STA mode so scanning works before the first beginNoBlock() call. + // Without this, cyw43_wifi_scan() fails because the radio isn't initialized. + cyw43_arch_enable_sta_mode(); + } bool ap_state = false; if (ap.has_value()) {