From 90e9c95c30aaea47f598cbf36b41a86a1955316c Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Sun, 13 Jan 2019 17:34:05 +0100 Subject: [PATCH] cpu/esp32: registration of RX callback in esp_wifi RX callback function should be register when WiFi has been connected to AP successfully and should be unregistered when WiFi disconnects from AP. Therefore, esp_wifi_internal_reg_rxcb is called now in event handler on event SYSTEM_EVENT_STA_CONNECTED. It is reset now on event SYSTEM_EVENT_STA_DISCONNECTED. --- cpu/esp32/esp-wifi/esp_wifi_netdev.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cpu/esp32/esp-wifi/esp_wifi_netdev.c b/cpu/esp32/esp-wifi/esp_wifi_netdev.c index dfe2b5451e..8516cab0cd 100644 --- a/cpu/esp32/esp-wifi/esp_wifi_netdev.c +++ b/cpu/esp32/esp-wifi/esp_wifi_netdev.c @@ -122,18 +122,28 @@ static esp_err_t IRAM_ATTR _esp_system_event_handler(void *ctx, system_event_t * case SYSTEM_EVENT_STA_CONNECTED: DEBUG("%s WiFi connected\n", __func__); + + /* register RX callback function */ + esp_wifi_internal_reg_rxcb(ESP_IF_WIFI_STA, _esp_wifi_rx_cb); + _esp_wifi_dev.connected = true; _esp_wifi_dev.event = SYSTEM_EVENT_ETH_CONNECTED; _esp_wifi_dev.netdev.event_callback(&_esp_wifi_dev.netdev, NETDEV_EVENT_ISR); + break; case SYSTEM_EVENT_STA_DISCONNECTED: DEBUG("%s WiFi disconnected from ssid %s, reason %d\n", __func__, event->event_info.disconnected.ssid, event->event_info.disconnected.reason); + + /* unregister RX callback function */ + esp_wifi_internal_reg_rxcb(ESP_IF_WIFI_STA, NULL); + _esp_wifi_dev.connected = false; _esp_wifi_dev.event = SYSTEM_EVENT_ETH_DISCONNECTED; _esp_wifi_dev.netdev.event_callback(&_esp_wifi_dev.netdev, NETDEV_EVENT_ISR); + break; default: