1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-18 15:55:46 +00:00

Merge branch 'retry_hidden_no_stuck_last_networks_visible' into integration

This commit is contained in:
J. Nick Koston
2025-11-11 09:17:11 -06:00
2 changed files with 13 additions and 8 deletions

View File

@@ -253,8 +253,9 @@ bool WiFiComponent::ssid_was_seen_in_scan_(const std::string &ssid) const {
return false; return false;
} }
int8_t WiFiComponent::find_next_hidden_sta_(int8_t start_index, bool include_explicit_hidden) { int8_t WiFiComponent::find_next_hidden_sta_(int8_t start_index) {
// Find next SSID that wasn't in scan results (might be hidden) // Find next SSID that wasn't in scan results (might be hidden)
bool include_explicit_hidden = !this->went_through_explicit_hidden_phase_();
// Start searching from start_index + 1 // Start searching from start_index + 1
for (size_t i = start_index + 1; i < this->sta_.size(); i++) { for (size_t i = start_index + 1; i < this->sta_.size(); i++) {
const auto &sta = this->sta_[i]; const auto &sta = this->sta_[i];
@@ -1167,7 +1168,7 @@ WiFiRetryPhase WiFiComponent::determine_next_phase_() {
// Its priority has been decreased, so on next scan it will be sorted lower // Its priority has been decreased, so on next scan it will be sorted lower
// and we'll try the next best BSSID. // and we'll try the next best BSSID.
// Check if there are any potentially hidden networks to try // Check if there are any potentially hidden networks to try
if (this->find_next_hidden_sta_(-1, !this->went_through_explicit_hidden_phase_()) >= 0) { if (this->find_next_hidden_sta_(-1) >= 0) {
return WiFiRetryPhase::RETRY_HIDDEN; // Found hidden networks to try return WiFiRetryPhase::RETRY_HIDDEN; // Found hidden networks to try
} }
// No hidden networks - always go through RESTARTING_ADAPTER phase // No hidden networks - always go through RESTARTING_ADAPTER phase
@@ -1184,8 +1185,13 @@ WiFiRetryPhase WiFiComponent::determine_next_phase_() {
// Exhausted retries on current SSID - check if there are more potentially hidden SSIDs to try // Exhausted retries on current SSID - check if there are more potentially hidden SSIDs to try
if (this->selected_sta_index_ < static_cast<int8_t>(this->sta_.size()) - 1) { if (this->selected_sta_index_ < static_cast<int8_t>(this->sta_.size()) - 1) {
// More SSIDs available - stay in RETRY_HIDDEN, advance will happen in retry_connect() // Check if find_next_hidden_sta_() would actually find another hidden SSID
return WiFiRetryPhase::RETRY_HIDDEN; // as it might have been seen in the scan results and we want to skip those
// otherwise we will get stuck in RETRY_HIDDEN phase
if (this->find_next_hidden_sta_(this->selected_sta_index_) != -1) {
// More hidden SSIDs available - stay in RETRY_HIDDEN, advance will happen in retry_connect()
return WiFiRetryPhase::RETRY_HIDDEN;
}
} }
} }
// Exhausted all potentially hidden SSIDs - always go through RESTARTING_ADAPTER // Exhausted all potentially hidden SSIDs - always go through RESTARTING_ADAPTER
@@ -1269,7 +1275,7 @@ bool WiFiComponent::transition_to_phase_(WiFiRetryPhase new_phase) {
// If first network is marked hidden, we went through EXPLICIT_HIDDEN phase // If first network is marked hidden, we went through EXPLICIT_HIDDEN phase
// In that case, skip networks marked hidden:true (already tried) // In that case, skip networks marked hidden:true (already tried)
// Otherwise, include them (they haven't been tried yet) // Otherwise, include them (they haven't been tried yet)
this->selected_sta_index_ = this->find_next_hidden_sta_(-1, !this->went_through_explicit_hidden_phase_()); this->selected_sta_index_ = this->find_next_hidden_sta_(-1);
if (this->selected_sta_index_ == -1) { if (this->selected_sta_index_ == -1) {
ESP_LOGD(TAG, "All SSIDs visible or already tried, skipping hidden mode"); ESP_LOGD(TAG, "All SSIDs visible or already tried, skipping hidden mode");
@@ -1430,8 +1436,7 @@ void WiFiComponent::advance_to_next_target_or_increment_retry_() {
// If first network is marked hidden, we went through EXPLICIT_HIDDEN phase // If first network is marked hidden, we went through EXPLICIT_HIDDEN phase
// In that case, skip networks marked hidden:true (already tried) // In that case, skip networks marked hidden:true (already tried)
// Otherwise, include them (they haven't been tried yet) // Otherwise, include them (they haven't been tried yet)
int8_t next_index = int8_t next_index = this->find_next_hidden_sta_(this->selected_sta_index_);
this->find_next_hidden_sta_(this->selected_sta_index_, !this->went_through_explicit_hidden_phase_());
if (next_index != -1) { if (next_index != -1) {
// Found another potentially hidden SSID // Found another potentially hidden SSID
this->selected_sta_index_ = next_index; this->selected_sta_index_ = next_index;

View File

@@ -393,7 +393,7 @@ class WiFiComponent : public Component {
/// Returns index of next potentially hidden SSID, or -1 if none found /// Returns index of next potentially hidden SSID, or -1 if none found
/// @param start_index Start searching from index after this (-1 to start from beginning) /// @param start_index Start searching from index after this (-1 to start from beginning)
/// @param include_explicit_hidden If true, include SSIDs marked hidden:true. If false, only find truly hidden SSIDs. /// @param include_explicit_hidden If true, include SSIDs marked hidden:true. If false, only find truly hidden SSIDs.
int8_t find_next_hidden_sta_(int8_t start_index, bool include_explicit_hidden = true); int8_t find_next_hidden_sta_(int8_t start_index);
/// Log failed connection and decrease BSSID priority to avoid repeated attempts /// Log failed connection and decrease BSSID priority to avoid repeated attempts
void log_and_adjust_priority_for_failed_connect_(); void log_and_adjust_priority_for_failed_connect_();
/// Clear BSSID priority tracking if all priorities are at minimum (saves memory) /// Clear BSSID priority tracking if all priorities are at minimum (saves memory)