mirror of
https://github.com/esphome/esphome.git
synced 2025-11-17 15:26:01 +00:00
[wifi] Fix infinite retry loop when no hidden networks and captive portal active (#11831)
This commit is contained in:
@@ -1163,11 +1163,9 @@ WiFiRetryPhase WiFiComponent::determine_next_phase_() {
|
|||||||
if (this->find_next_hidden_sta_(-1, !this->went_through_explicit_hidden_phase_()) >= 0) {
|
if (this->find_next_hidden_sta_(-1, !this->went_through_explicit_hidden_phase_()) >= 0) {
|
||||||
return WiFiRetryPhase::RETRY_HIDDEN; // Found hidden networks to try
|
return WiFiRetryPhase::RETRY_HIDDEN; // Found hidden networks to try
|
||||||
}
|
}
|
||||||
// No hidden networks - skip directly to restart/rescan
|
// No hidden networks - always go through RESTARTING_ADAPTER phase
|
||||||
if (this->is_captive_portal_active_() || this->is_esp32_improv_active_()) {
|
// This ensures num_retried_ gets reset and a fresh scan is triggered
|
||||||
return this->went_through_explicit_hidden_phase_() ? WiFiRetryPhase::EXPLICIT_HIDDEN
|
// The actual adapter restart will be skipped if captive portal/improv is active
|
||||||
: WiFiRetryPhase::SCAN_CONNECTING;
|
|
||||||
}
|
|
||||||
return WiFiRetryPhase::RESTARTING_ADAPTER;
|
return WiFiRetryPhase::RESTARTING_ADAPTER;
|
||||||
|
|
||||||
case WiFiRetryPhase::RETRY_HIDDEN:
|
case WiFiRetryPhase::RETRY_HIDDEN:
|
||||||
@@ -1183,16 +1181,9 @@ WiFiRetryPhase WiFiComponent::determine_next_phase_() {
|
|||||||
return WiFiRetryPhase::RETRY_HIDDEN;
|
return WiFiRetryPhase::RETRY_HIDDEN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Exhausted all potentially hidden SSIDs - rescan to try next BSSID
|
// Exhausted all potentially hidden SSIDs - always go through RESTARTING_ADAPTER
|
||||||
// If captive portal/improv is active, skip adapter restart and go back to start
|
// This ensures num_retried_ gets reset and a fresh scan is triggered
|
||||||
// Otherwise restart adapter to clear any stuck state
|
// The actual adapter restart will be skipped if captive portal/improv is active
|
||||||
if (this->is_captive_portal_active_() || this->is_esp32_improv_active_()) {
|
|
||||||
// Go back to explicit hidden if we went through it initially, otherwise scan
|
|
||||||
return this->went_through_explicit_hidden_phase_() ? WiFiRetryPhase::EXPLICIT_HIDDEN
|
|
||||||
: WiFiRetryPhase::SCAN_CONNECTING;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Restart adapter
|
|
||||||
return WiFiRetryPhase::RESTARTING_ADAPTER;
|
return WiFiRetryPhase::RESTARTING_ADAPTER;
|
||||||
|
|
||||||
case WiFiRetryPhase::RESTARTING_ADAPTER:
|
case WiFiRetryPhase::RESTARTING_ADAPTER:
|
||||||
@@ -1280,7 +1271,12 @@ bool WiFiComponent::transition_to_phase_(WiFiRetryPhase new_phase) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case WiFiRetryPhase::RESTARTING_ADAPTER:
|
case WiFiRetryPhase::RESTARTING_ADAPTER:
|
||||||
this->restart_adapter();
|
// Skip actual adapter restart if captive portal/improv is active
|
||||||
|
// This allows state machine to reset num_retried_ and trigger fresh scan
|
||||||
|
// without disrupting the captive portal/improv connection
|
||||||
|
if (!this->is_captive_portal_active_() && !this->is_esp32_improv_active_()) {
|
||||||
|
this->restart_adapter();
|
||||||
|
}
|
||||||
// Return true to indicate we should wait (go to COOLDOWN) instead of immediately connecting
|
// Return true to indicate we should wait (go to COOLDOWN) instead of immediately connecting
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user