[wifi] Fix ESP8266 disconnect callback order to set error flag before notifying listeners

This commit is contained in:
J. Nick Koston
2026-01-13 08:13:37 -10:00
parent 3d40979c96
commit 714188cfd8

View File

@@ -543,6 +543,9 @@ void WiFiComponent::wifi_event_callback(System_Event_t *event) {
}
s_sta_connected = false;
s_sta_connecting = false;
// Set error flag BEFORE notifying listeners so is_connected() returns
// correct state during listener callbacks (matches ESP-IDF behavior)
global_wifi_component->error_from_callback_ = true;
#ifdef USE_WIFI_LISTENERS
static constexpr uint8_t EMPTY_BSSID[6] = {};
for (auto *listener : global_wifi_component->connect_state_listeners_) {
@@ -635,10 +638,6 @@ void WiFiComponent::wifi_event_callback(System_Event_t *event) {
break;
}
if (event->event == EVENT_STAMODE_DISCONNECTED) {
global_wifi_component->error_from_callback_ = true;
}
WiFiMockClass::_event_callback(event);
}