1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-18 15:55:46 +00:00
This commit is contained in:
J. Nick Koston
2025-11-06 12:07:42 -06:00
parent 60d6144574
commit 25ef0043d2

View File

@@ -111,7 +111,9 @@ void WiFiComponent::start() {
#ifdef USE_WIFI_FAST_CONNECT
this->trying_loaded_ap_ = this->load_fast_connect_settings_();
if (!this->trying_loaded_ap_) {
// Fast connect failed - start from first configured AP without scan result
// FAST CONNECT FALLBACK: No saved settings available
// Set selected_sta_index_ to first config without any scan result
// build_selected_ap_() will use config data only (no SSID/BSSID/channel from scan)
this->selected_sta_index_ = 0;
}
this->start_connecting_to_selected_(false);
@@ -688,6 +690,10 @@ void WiFiComponent::check_scanning_finished() {
}
// Find matching config for on-demand connection params building
// SYNCHRONIZATION POINT: Establish link between scan_result_[0] and selected_sta_index_
// After sorting, scan_result_[0] contains the best network. Now find which sta_[i] config
// matches that network and record it in selected_sta_index_. This keeps the two indices
// synchronized so build_selected_ap_() can safely use both to build connection parameters.
const WiFiScanResult &scan_res = this->scan_result_[0];
if (!scan_res.get_matches()) {
@@ -702,7 +708,7 @@ void WiFiComponent::check_scanning_finished() {
continue;
}
this->selected_sta_index_ = i;
this->selected_sta_index_ = i; // Links scan_result_[0] with sta_[i]
break;
}
@@ -887,12 +893,15 @@ bool WiFiComponent::load_fast_connect_settings_() {
bssid_t bssid{};
std::copy(fast_connect_save.bssid, fast_connect_save.bssid + 6, bssid.begin());
// FAST CONNECT SUCCESS: Restore saved settings without scanning
// Create a temporary scan result with the fast connect BSSID and channel
this->scan_result_.init(1);
WiFiScanResult fast_connect_scan(bssid, "", fast_connect_save.channel, 0, false, false);
this->scan_result_.push_back(fast_connect_scan);
// Set index to use the loaded AP config with temporary scan result
// SYNCHRONIZATION: Link scan_result_[0] (temporary) with sta_[saved_index]
// Unlike wifi_scan_done() which sorts then finds the match, here we know exactly
// which config was used before and create a matching temporary scan result
this->selected_sta_index_ = fast_connect_save.ap_index;
ESP_LOGD(TAG, "Loaded fast_connect settings");