[wifi] Keep ESP8266's report of a replaced attempt from failing the next one (#20183)

This commit is contained in:
J. Nick Koston
2026-10-05 10:21:52 -05:00
committed by GitHub
parent 9a97419cfc
commit 1110857ffa
2 changed files with 8 additions and 7 deletions
+4 -3
View File
@@ -762,7 +762,7 @@ void WiFiComponent::restart_adapter() {
// and check_connecting_finished() is called after cooldown without going
// through start_connecting() first. Without this clear, stale errors would
// trigger spurious "failed (callback)" logs. The canonical clear location
// is in start_connecting(); this is the only exception to that pattern.
// is in start_connecting() (ESP8266 also clears after wifi_station_connect()).
this->error_from_callback_ = false;
}
@@ -1218,8 +1218,9 @@ void WiFiComponent::start_connecting(const WiFiAP &ap) {
// Clear any stale error from previous connection attempt.
// This is the canonical location for clearing the flag since all connection
// attempts go through start_connecting(). The only other clear is in
// restart_adapter() which enters COOLDOWN without calling start_connecting().
// attempts go through start_connecting(). restart_adapter() also clears it, as it
// enters COOLDOWN without calling start_connecting(), and ESP8266 clears it again
// after wifi_station_connect(), whose callbacks fire synchronously.
this->error_from_callback_ = false;
if (!this->wifi_sta_connect_(ap)) {
@@ -376,17 +376,17 @@ bool WiFiComponent::wifi_sta_connect_(const WiFiAP &ap) {
this->wifi_apply_hostname_();
// Reset flags, do this _before_ wifi_station_connect as the callback method
// may be called from wifi_station_connect
this->sta_state_ = static_cast<uint8_t>(ESP8266WiFiSTAState::CONNECTING);
ETS_UART_INTR_DISABLE();
ret = wifi_station_connect();
ETS_UART_INTR_ENABLE();
if (!ret) {
ESP_LOGV(TAG, "wifi_station_connect failed");
this->sta_state_ = static_cast<uint8_t>(ESP8266WiFiSTAState::ERROR_FAILED);
return false;
}
// Reset after, not before: wifi_station_connect() synchronously reports the attempt it replaces as failed
this->sta_state_ = static_cast<uint8_t>(ESP8266WiFiSTAState::CONNECTING);
this->error_from_callback_ = false;
#if USE_NETWORK_IPV6
bool connected = false;