Skip to content

Commit 05d72f9

Browse files
committed
fix WiFi STA going into loop in some cases of disconnect
1 parent b14f82b commit 05d72f9

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

libraries/WiFi/src/WiFiGeneric.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -365,14 +365,17 @@ esp_err_t WiFiGenericClass::_eventCallback(void *arg, system_event_t *event)
365365
} else if(reason == WIFI_REASON_BEACON_TIMEOUT || reason == WIFI_REASON_HANDSHAKE_TIMEOUT) {
366366
WiFiSTAClass::_setStatus(WL_CONNECTION_LOST);
367367
} else if(reason == WIFI_REASON_AUTH_EXPIRE) {
368-
if(WiFi.getAutoReconnect()){
369-
WiFi.begin();
370-
}
368+
371369
} else {
372370
WiFiSTAClass::_setStatus(WL_DISCONNECTED);
373371
}
374372
clearStatusBits(STA_CONNECTED_BIT | STA_HAS_IP_BIT | STA_HAS_IP6_BIT);
375-
if(reason >= WIFI_REASON_BEACON_TIMEOUT && reason != WIFI_REASON_AUTH_FAIL && WiFi.getAutoReconnect()){
373+
if(((reason == WIFI_REASON_AUTH_EXPIRE) ||
374+
(reason >= WIFI_REASON_BEACON_TIMEOUT && reason != WIFI_REASON_AUTH_FAIL)) &&
375+
WiFi.getAutoReconnect())
376+
{
377+
WiFi.enableSTA(false);
378+
WiFi.enableSTA(true);
376379
WiFi.begin();
377380
}
378381
} else if(event->event_id == SYSTEM_EVENT_STA_GOT_IP) {

0 commit comments

Comments
 (0)