esp32/modnetwork: Fix wifi.isconnected to return False after disconnect.
esp_wifi_connect will return ESP_OK for the normal path of execution which just means the reconnect is started, not that it is actually reconnected. In such a case wifi.isconnected() should return False until the reconnection is complete. After reconnect a GOT_IP event is called and it will change wifi_sta_connected back to True.
This commit is contained in:
parent
55ff562c70
commit
21f9329d5d
@ -169,7 +169,7 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) {
|
||||
}
|
||||
ESP_LOGI("wifi", "STA_DISCONNECTED, reason:%d%s", disconn->reason, message);
|
||||
|
||||
bool reconnected = false;
|
||||
wifi_sta_connected = false;
|
||||
if (wifi_sta_connect_requested) {
|
||||
wifi_mode_t mode;
|
||||
if (esp_wifi_get_mode(&mode) == ESP_OK) {
|
||||
@ -178,16 +178,10 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) {
|
||||
esp_err_t e = esp_wifi_connect();
|
||||
if (e != ESP_OK) {
|
||||
ESP_LOGI("wifi", "error attempting to reconnect: 0x%04x", e);
|
||||
} else {
|
||||
reconnected = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (wifi_sta_connected && !reconnected) {
|
||||
// If already connected and we fail to reconnect
|
||||
wifi_sta_connected = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_GOT_IP6:
|
||||
|
Loading…
Reference in New Issue
Block a user