mirror of
https://github.com/esphome/esphome.git
synced 2025-11-19 16:25:50 +00:00
Merge branch 'captive_fix' into integration
This commit is contained in:
@@ -619,9 +619,8 @@ void WiFiComponent::set_sta(const WiFiAP &ap) {
|
|||||||
this->init_sta(1);
|
this->init_sta(1);
|
||||||
this->add_sta(ap);
|
this->add_sta(ap);
|
||||||
this->selected_sta_index_ = 0;
|
this->selected_sta_index_ = 0;
|
||||||
// Force scan on next attempt even if captive portal is still active
|
// When new credentials are set (e.g., from improv), skip cooldown to retry immediately
|
||||||
// This ensures new credentials are tried with proper BSSID selection after provisioning
|
this->skip_cooldown_next_cycle_ = true;
|
||||||
this->force_scan_after_provision_ = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WiFiAP WiFiComponent::build_params_for_current_phase_() {
|
WiFiAP WiFiComponent::build_params_for_current_phase_() {
|
||||||
@@ -684,10 +683,6 @@ void WiFiComponent::save_wifi_sta(const std::string &ssid, const std::string &pa
|
|||||||
sta.set_password(password);
|
sta.set_password(password);
|
||||||
this->set_sta(sta);
|
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)
|
// Trigger connection attempt (exits cooldown if needed, no-op if already connecting/connected)
|
||||||
this->connect_soon_();
|
this->connect_soon_();
|
||||||
}
|
}
|
||||||
@@ -701,14 +696,6 @@ void WiFiComponent::connect_soon_() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WiFiComponent::start_connecting(const WiFiAP &ap) {
|
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
|
// Log connection attempt at INFO level with priority
|
||||||
char bssid_s[18];
|
char bssid_s[18];
|
||||||
int8_t priority = 0;
|
int8_t priority = 0;
|
||||||
@@ -905,8 +892,6 @@ void WiFiComponent::start_scanning() {
|
|||||||
ESP_LOGD(TAG, "Starting scan");
|
ESP_LOGD(TAG, "Starting scan");
|
||||||
this->wifi_scan_start_(this->passive_scan_);
|
this->wifi_scan_start_(this->passive_scan_);
|
||||||
this->state_ = WIFI_COMPONENT_STATE_STA_SCANNING;
|
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
|
/// Comparator for WiFi scan result sorting - determines which network should be tried first
|
||||||
@@ -1279,9 +1264,7 @@ WiFiRetryPhase WiFiComponent::determine_next_phase_() {
|
|||||||
}
|
}
|
||||||
// Skip scanning when captive portal/improv is active to avoid disrupting AP
|
// Skip scanning when captive portal/improv is active to avoid disrupting AP
|
||||||
// Even passive scans can cause brief AP disconnections on ESP32
|
// 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_()) {
|
||||||
if ((this->is_captive_portal_active_() || this->is_esp32_improv_active_()) &&
|
|
||||||
!this->force_scan_after_provision_) {
|
|
||||||
return WiFiRetryPhase::RETRY_HIDDEN;
|
return WiFiRetryPhase::RETRY_HIDDEN;
|
||||||
}
|
}
|
||||||
return WiFiRetryPhase::SCAN_CONNECTING;
|
return WiFiRetryPhase::SCAN_CONNECTING;
|
||||||
|
|||||||
@@ -532,7 +532,6 @@ class WiFiComponent : public Component {
|
|||||||
bool enable_on_boot_;
|
bool enable_on_boot_;
|
||||||
bool got_ipv4_address_{false};
|
bool got_ipv4_address_{false};
|
||||||
bool keep_scan_results_{false};
|
bool keep_scan_results_{false};
|
||||||
bool force_scan_after_provision_{false};
|
|
||||||
bool did_scan_this_cycle_{false};
|
bool did_scan_this_cycle_{false};
|
||||||
bool skip_cooldown_next_cycle_{false};
|
bool skip_cooldown_next_cycle_{false};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user