mirror of
https://github.com/esphome/esphome.git
synced 2025-11-16 14:55:50 +00:00
cleanup
This commit is contained in:
@@ -174,7 +174,8 @@ void WiFiComponent::loop() {
|
|||||||
// All APs tried, fall back to scanning
|
// All APs tried, fall back to scanning
|
||||||
this->start_scanning();
|
this->start_scanning();
|
||||||
} else {
|
} else {
|
||||||
// NOTE: This check may not make sense here as it could interfere with AP cycling
|
// Safety check: Ensure selected_sta_index_ is valid before retrying
|
||||||
|
// (should already be set by retry_connect(), but check for robustness)
|
||||||
this->reset_selected_ap_to_first_if_invalid_();
|
this->reset_selected_ap_to_first_if_invalid_();
|
||||||
this->start_connecting_to_selected_(false);
|
this->start_connecting_to_selected_(false);
|
||||||
}
|
}
|
||||||
@@ -708,11 +709,6 @@ void WiFiComponent::check_scanning_finished() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_WIFI_FAST_CONNECT
|
|
||||||
// Scan found a network, reset exhausted flag to allow fast connect to work next time
|
|
||||||
this->fast_connect_exhausted_ = false;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
yield();
|
yield();
|
||||||
|
|
||||||
this->start_connecting_to_selected_(false);
|
this->start_connecting_to_selected_(false);
|
||||||
@@ -923,11 +919,13 @@ bool WiFiComponent::load_fast_connect_settings_() {
|
|||||||
void WiFiComponent::save_fast_connect_settings_() {
|
void WiFiComponent::save_fast_connect_settings_() {
|
||||||
bssid_t bssid = wifi_bssid();
|
bssid_t bssid = wifi_bssid();
|
||||||
uint8_t channel = get_wifi_channel();
|
uint8_t channel = get_wifi_channel();
|
||||||
|
int8_t ap_index = this->selected_sta_index_ >= 0 ? this->selected_sta_index_ : 0;
|
||||||
|
|
||||||
// Skip save if settings haven't changed (compare with current scan result if available)
|
// Skip save if settings haven't changed (compare with previously saved settings to reduce flash wear)
|
||||||
if (!this->scan_result_.empty()) {
|
SavedWifiFastConnectSettings previous_save{};
|
||||||
const WiFiScanResult &scan = this->scan_result_[0];
|
if (this->fast_connect_pref_.load(&previous_save)) {
|
||||||
if (bssid == scan.get_bssid() && channel == scan.get_channel()) {
|
if (memcmp(previous_save.bssid, bssid.data(), 6) == 0 && previous_save.channel == channel &&
|
||||||
|
previous_save.ap_index == ap_index) {
|
||||||
return; // No change, nothing to save
|
return; // No change, nothing to save
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -935,7 +933,7 @@ void WiFiComponent::save_fast_connect_settings_() {
|
|||||||
SavedWifiFastConnectSettings fast_connect_save{};
|
SavedWifiFastConnectSettings fast_connect_save{};
|
||||||
memcpy(fast_connect_save.bssid, bssid.data(), 6);
|
memcpy(fast_connect_save.bssid, bssid.data(), 6);
|
||||||
fast_connect_save.channel = channel;
|
fast_connect_save.channel = channel;
|
||||||
fast_connect_save.ap_index = this->selected_sta_index_ >= 0 ? this->selected_sta_index_ : 0;
|
fast_connect_save.ap_index = ap_index;
|
||||||
|
|
||||||
this->fast_connect_pref_.save(&fast_connect_save);
|
this->fast_connect_pref_.save(&fast_connect_save);
|
||||||
|
|
||||||
|
|||||||
@@ -218,6 +218,8 @@ class WiFiComponent : public Component {
|
|||||||
WiFiComponent();
|
WiFiComponent();
|
||||||
|
|
||||||
void set_sta(const WiFiAP &ap);
|
void set_sta(const WiFiAP &ap);
|
||||||
|
// Returns a copy of the currently selected AP configuration
|
||||||
|
// Note: This copies the 88-byte WiFiAP. Only used by WiFiConfigureAction for state save/restore.
|
||||||
WiFiAP get_sta();
|
WiFiAP get_sta();
|
||||||
void init_sta(size_t count);
|
void init_sta(size_t count);
|
||||||
void add_sta(const WiFiAP &ap);
|
void add_sta(const WiFiAP &ap);
|
||||||
@@ -471,6 +473,7 @@ class WiFiComponent : public Component {
|
|||||||
uint8_t num_retried_{0};
|
uint8_t num_retried_{0};
|
||||||
// Index into sta_ array for the currently selected AP configuration (-1 = none selected)
|
// Index into sta_ array for the currently selected AP configuration (-1 = none selected)
|
||||||
// Used to access password, manual_ip, priority, EAP settings, and hidden flag
|
// Used to access password, manual_ip, priority, EAP settings, and hidden flag
|
||||||
|
// int8_t limits to 127 APs which should be sufficient for all practical use cases
|
||||||
int8_t selected_sta_index_{-1};
|
int8_t selected_sta_index_{-1};
|
||||||
#if USE_NETWORK_IPV6
|
#if USE_NETWORK_IPV6
|
||||||
uint8_t num_ipv6_addresses_{0};
|
uint8_t num_ipv6_addresses_{0};
|
||||||
|
|||||||
Reference in New Issue
Block a user