Fix: skip update_connected_state_ only when already connected

After wifi_loop_() processes the STA_CONNECTED event, state_ is still
CONNECTING (state machine hasn't run yet). update_connected_state_()
runs but is_connected_() returns false. Then check_connecting_finished()
transitions to STA_CONNECTED. Next iteration: no events, state is
STA_CONNECTED, so we skipped update — connected_ stayed false forever.

Fix: check connected_ instead of state_. Only skip when connected_ is
already true (steady state). When connected_ is false, always re-evaluate
so the flag gets set after the state machine transitions.
This commit is contained in:
J. Nick Koston
2026-04-01 12:32:11 -10:00
parent f7222e39bb
commit 7b222f773f
+3 -1
View File
@@ -735,7 +735,9 @@ void WiFiComponent::loop() {
// Connection state can only change when events are processed (ESP-IDF/LibreTiny)
// or polled (ESP8266/Pico W). Skip the expensive wifi_sta_connect_status_() call
// when no events arrived and we're already in steady state.
if (events_processed || this->state_ != WIFI_COMPONENT_STATE_STA_CONNECTED) {
// Must also run when connected_ is false — after state transitions to STA_CONNECTED,
// connected_ won't be set until update_connected_state_() runs.
if (events_processed || !this->connected_) {
this->update_connected_state_();
}