From c9684af5c20d63d5b497381ff5e49ed9fbb734d5 Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Sun, 13 Jan 2019 17:36:09 +0100 Subject: [PATCH] cpu/esp32: automatic reconnect after disconnect If WiFi is disconnected, e.g., because of timeout for beacon frame, it is tried to reconnect automatically. --- cpu/esp32/esp-wifi/esp_wifi_netdev.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/cpu/esp32/esp-wifi/esp_wifi_netdev.c b/cpu/esp32/esp-wifi/esp_wifi_netdev.c index 8516cab0cd..46619f4ae5 100644 --- a/cpu/esp32/esp-wifi/esp_wifi_netdev.c +++ b/cpu/esp32/esp-wifi/esp_wifi_netdev.c @@ -144,6 +144,21 @@ static esp_err_t IRAM_ATTR _esp_system_event_handler(void *ctx, system_event_t * _esp_wifi_dev.event = SYSTEM_EVENT_ETH_DISCONNECTED; _esp_wifi_dev.netdev.event_callback(&_esp_wifi_dev.netdev, NETDEV_EVENT_ISR); + /* call disconnect to reset internal state */ + result = esp_wifi_disconnect(); + if (result != ESP_OK) { + LOG_TAG_ERROR("esp_wifi", "esp_wifi_disconnect failed with " + "return value %d\n", result); + return result; + } + + /* try to reconnect */ + result = esp_wifi_connect(); + if (result != ESP_OK) { + LOG_TAG_ERROR("esp_wifi", "esp_wifi_connect failed with " + "return value %d\n", result); + } + break; default: @@ -313,6 +328,7 @@ static int _esp_wifi_send(netdev_t *netdev, const iolist_t *iolist) } mutex_unlock(&dev->dev_lock); + return ret; }