From 1f6aca5c17ff1c3c3280adf362a2c912c2b9bd07 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 18 Nov 2025 10:08:44 -0600 Subject: [PATCH 1/4] fixes --- esphome/components/wifi/wifi_component.cpp | 7 ------- esphome/components/wifi/wifi_component.h | 1 - 2 files changed, 8 deletions(-) diff --git a/esphome/components/wifi/wifi_component.cpp b/esphome/components/wifi/wifi_component.cpp index dcb81a80a0..f8a3728288 100644 --- a/esphome/components/wifi/wifi_component.cpp +++ b/esphome/components/wifi/wifi_component.cpp @@ -618,9 +618,6 @@ void WiFiComponent::set_sta(const WiFiAP &ap) { this->init_sta(1); this->add_sta(ap); this->selected_sta_index_ = 0; - // Force scan on next attempt even if captive portal is still active - // This ensures new credentials are tried with proper BSSID selection after provisioning - this->force_scan_after_provision_ = true; } WiFiAP WiFiComponent::build_params_for_current_phase_() { @@ -683,10 +680,6 @@ void WiFiComponent::save_wifi_sta(const std::string &ssid, const std::string &pa sta.set_password(password); this->set_sta(sta); - // Force scan on next attempt even if captive portal is still active - // This ensures new credentials are tried with proper BSSID selection after provisioning - this->force_scan_after_provision_ = true; - // Trigger connection attempt (exits cooldown if needed, no-op if already connecting/connected) this->connect_soon_(); } diff --git a/esphome/components/wifi/wifi_component.h b/esphome/components/wifi/wifi_component.h index 5e58c41bc0..ff438b2927 100644 --- a/esphome/components/wifi/wifi_component.h +++ b/esphome/components/wifi/wifi_component.h @@ -532,7 +532,6 @@ class WiFiComponent : public Component { bool enable_on_boot_; bool got_ipv4_address_{false}; bool keep_scan_results_{false}; - bool force_scan_after_provision_{false}; bool did_scan_this_cycle_{false}; bool skip_cooldown_next_cycle_{false}; From 53a3a5ddeab5963e8613b5ed140533c7b51841bc Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 18 Nov 2025 10:08:53 -0600 Subject: [PATCH 2/4] fixes --- esphome/components/wifi/wifi_component.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/esphome/components/wifi/wifi_component.cpp b/esphome/components/wifi/wifi_component.cpp index f8a3728288..45ad331c37 100644 --- a/esphome/components/wifi/wifi_component.cpp +++ b/esphome/components/wifi/wifi_component.cpp @@ -896,8 +896,6 @@ void WiFiComponent::start_scanning() { ESP_LOGD(TAG, "Starting scan"); this->wifi_scan_start_(this->passive_scan_); this->state_ = WIFI_COMPONENT_STATE_STA_SCANNING; - // Clear the force scan flag after starting the scan - this->force_scan_after_provision_ = false; } /// Comparator for WiFi scan result sorting - determines which network should be tried first From 62c9d83777fd8ea9d3a2bd64fb9a92503414fdec Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 18 Nov 2025 10:09:14 -0600 Subject: [PATCH 3/4] fixes --- esphome/components/wifi/wifi_component.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/esphome/components/wifi/wifi_component.cpp b/esphome/components/wifi/wifi_component.cpp index 45ad331c37..075b70a266 100644 --- a/esphome/components/wifi/wifi_component.cpp +++ b/esphome/components/wifi/wifi_component.cpp @@ -1268,9 +1268,7 @@ WiFiRetryPhase WiFiComponent::determine_next_phase_() { } // Skip scanning when captive portal/improv is active to avoid disrupting AP // Even passive scans can cause brief AP disconnections on ESP32 - // UNLESS new credentials were just provisioned - then we need to scan - if ((this->is_captive_portal_active_() || this->is_esp32_improv_active_()) && - !this->force_scan_after_provision_) { + if (this->is_captive_portal_active_() || this->is_esp32_improv_active_()) { return WiFiRetryPhase::RETRY_HIDDEN; } return WiFiRetryPhase::SCAN_CONNECTING; From 92e19c497eb87a5b2898d0af7f18a2880b0d1404 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 18 Nov 2025 10:13:03 -0600 Subject: [PATCH 4/4] fixes --- esphome/components/wifi/wifi_component.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/esphome/components/wifi/wifi_component.cpp b/esphome/components/wifi/wifi_component.cpp index 075b70a266..30340601fb 100644 --- a/esphome/components/wifi/wifi_component.cpp +++ b/esphome/components/wifi/wifi_component.cpp @@ -618,6 +618,8 @@ void WiFiComponent::set_sta(const WiFiAP &ap) { this->init_sta(1); this->add_sta(ap); this->selected_sta_index_ = 0; + // When new credentials are set (e.g., from improv), skip cooldown to retry immediately + this->skip_cooldown_next_cycle_ = true; } WiFiAP WiFiComponent::build_params_for_current_phase_() { @@ -693,14 +695,6 @@ void WiFiComponent::connect_soon_() { } void WiFiComponent::start_connecting(const WiFiAP &ap) { - // If already connecting/connected, set flag to skip cooldown on next cycle - // Caller (e.g., improv) already called set_sta() with new credentials, state machine will retry - if (this->state_ == WIFI_COMPONENT_STATE_STA_CONNECTING || this->state_ == WIFI_COMPONENT_STATE_STA_CONNECTED) { - ESP_LOGD(TAG, "Already connecting, will retry on next cycle"); - this->skip_cooldown_next_cycle_ = true; - return; - } - // Log connection attempt at INFO level with priority char bssid_s[18]; int8_t priority = 0;