]> granicus.if.org Git - esp-idf/commitdiff
esp_wifi: wifi support new event mechanism
authorliu zhifu <liuzhifu@espressif.com>
Fri, 5 Jul 2019 08:58:04 +0000 (16:58 +0800)
committerbot <bot@espressif.com>
Tue, 20 Aug 2019 09:39:51 +0000 (09:39 +0000)
1. WiFi support new event mechanism
2. Update examples to use new event mechanism

44 files changed:
components/driver/test/test_adc2.c
components/esp_event/event_send.c
components/esp_event/include/esp_event_legacy.h
components/esp_event/include/esp_event_loop.h
components/esp_event/test/test_event.c
components/esp_websocket_client/include/esp_websocket_client.h
components/esp_wifi/include/esp_mesh.h
components/esp_wifi/include/esp_private/esp_wifi_private.h
components/esp_wifi/include/esp_private/esp_wifi_types_private.h
components/esp_wifi/include/esp_wifi.h
components/esp_wifi/include/esp_wifi_types.h
components/esp_wifi/lib_esp32
components/esp_wifi/test/test_wifi.c
components/mdns/include/mdns.h
components/mqtt/esp-mqtt
components/tcpip_adapter/event_handlers.c
components/tcpip_adapter/tcpip_adapter_lwip.c
components/wifi_provisioning/include/wifi_provisioning/manager.h
components/wifi_provisioning/src/wifi_provisioning_priv.h
components/wpa_supplicant/src/esp_supplicant/esp_wifi_driver.h
components/wpa_supplicant/src/esp_supplicant/esp_wps.c
examples/bluetooth/bluedroid/ble/ble_hid_device_demo/main/ble_hidd_demo_main.c
examples/bluetooth/bluedroid/ble/blufi/main/blufi_example_main.c
examples/bluetooth/bluedroid/ble/blufi/main/blufi_security.c
examples/bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist/components/iperf/cmd_wifi.c
examples/ethernet/eth2ap/main/ethernet_example_main.c
examples/peripherals/spi_slave/receiver/main/app_main.c
examples/peripherals/spi_slave/sender/main/app_main.c
examples/protocols/http_server/advanced_tests/main/main.c
examples/protocols/http_server/file_serving/main/main.c
examples/protocols/http_server/persistent_sockets/main/main.c
examples/protocols/http_server/restful_server/main/esp_rest_main.c
examples/protocols/https_server/main/main.c
examples/protocols/websocket/main/websocket_example.c
examples/provisioning/ble_prov/main/app_prov.h
examples/provisioning/console_prov/main/app_prov.h
examples/provisioning/custom_config/main/app_prov.h
examples/provisioning/softap_prov/main/app_prov.h
examples/system/esp_event/default_event_loop/main/event_source.h
examples/system/esp_event/user_event_loops/main/event_source.h
examples/system/network_tests/main/net_suite.c
examples/system/ota/advanced_https_ota/main/advanced_https_ota_example.c
examples/system/ota/native_ota_example/main/native_ota_example.c
examples/system/ota/simple_ota_example/main/simple_ota_example.c

index 40549428efcd7b28a76162cafeebca802f0c3e4f..1438ae4d5caadc5e672f9bc497c60da0f14563d0 100644 (file)
@@ -6,7 +6,7 @@
 #include "driver/dac.h"
 #include "unity.h"
 #include "esp_system.h"
-#include "esp_event_loop.h"
+#include "esp_event.h"
 #include "esp_wifi.h"
 #include "esp_log.h"
 #include "nvs_flash.h"
@@ -17,27 +17,56 @@ static const char* TAG = "test_adc2";
 #define DEFAULT_SSID "TEST_SSID"
 #define DEFAULT_PWD "TEST_PASS"
 
-static esp_err_t event_handler(void *ctx, system_event_t *event)
+static void wifi_event_handler(void* arg, esp_event_base_t event_base,
+                                int32_t event_id, void* event_data)
 {
     printf("ev_handle_called.\n");
-    switch(event->event_id) {
-        case SYSTEM_EVENT_STA_START:
-            ESP_LOGI(TAG, "SYSTEM_EVENT_STA_START");
+    switch(event_id) {
+        case WIFI_EVENT_STA_START:
+            ESP_LOGI(TAG, "WIFI_EVENT_STA_START");
     //do not actually connect in test case
             //;
             break;
-        case SYSTEM_EVENT_STA_GOT_IP:
-            ESP_LOGI(TAG, "SYSTEM_EVENT_STA_GOT_IP");
-            ESP_LOGI(TAG, "got ip:%s\n",
-            ip4addr_ntoa(&event->event_info.got_ip.ip_info.ip));
-            break;
-        case SYSTEM_EVENT_STA_DISCONNECTED:
-            ESP_LOGI(TAG, "SYSTEM_EVENT_STA_DISCONNECTED");
+        case WIFI_EVENT_STA_DISCONNECTED:
+            ESP_LOGI(TAG, "WIFI_EVENT_STA_DISCONNECTED");
             TEST_ESP_OK(esp_wifi_connect());
             break;
         default:
             break;
     }
+    return ;
+}
+
+static void ip_event_handler(void* arg, esp_event_base_t event_base,
+                                int32_t event_id, void* event_data)
+{
+    ip_event_got_ip_t *event;
+    printf("ev_handle_called.\n");
+    switch(event_id) {
+        case IP_EVENT_STA_GOT_IP:
+            event = (ip_event_got_ip_t*)event_data;
+            ESP_LOGI(TAG, "IP_EVENT_STA_GOT_IP");
+            ESP_LOGI(TAG, "got ip:%s\n", ip4addr_ntoa(&event->ip_info.ip));
+            break;
+        default:
+            break;
+    }
+
+    return ;
+}
+
+static int event_init(void)
+{
+    TEST_ESP_OK(esp_event_loop_create_default());
+    ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &wifi_event_handler, NULL));
+    ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, ESP_EVENT_ANY_ID, &ip_event_handler, NULL));
+    return ESP_OK;
+}
+
+static int event_deinit(void)
+{
+    ESP_ERROR_CHECK(esp_event_handler_unregister(WIFI_EVENT, ESP_EVENT_ANY_ID, &wifi_event_handler));
+    ESP_ERROR_CHECK(esp_event_handler_unregister(IP_EVENT, ESP_EVENT_ANY_ID, &ip_event_handler));
     return ESP_OK;
 }
 
@@ -66,7 +95,7 @@ TEST_CASE("adc2 work with wifi","[adc]")
     } 
     TEST_ESP_OK( r);
     tcpip_adapter_init();
-    TEST_ESP_OK(esp_event_loop_init(event_handler, NULL));
+    event_init();
     wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
     TEST_ESP_OK(esp_wifi_init(&cfg));
     wifi_config_t wifi_config = {
@@ -100,6 +129,7 @@ TEST_CASE("adc2 work with wifi","[adc]")
     printf("wifi stop...\n");
     TEST_ESP_OK( esp_wifi_stop() );
     TEST_ESP_OK(esp_wifi_deinit());
+    event_deinit();
     nvs_flash_deinit();
 
     //test read value
index 2c31ee0f6cb7a2e2a529240dabde64aa5dc84dd0..80fe464a810d6d8726c8ecdf9d44112796aa43d5 100644 (file)
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-
+#include <string.h>
+#include "esp_log.h"
 #include "esp_event.h"
 #include "esp_event_legacy.h"
 
-esp_err_t esp_event_send_noop(system_event_t *event);
+#define TAG "event_send"
 
+esp_err_t esp_event_send_noop(system_event_t *event);
 extern esp_err_t esp_event_send_legacy(system_event_t *event) __attribute__((weak, alias("esp_event_send_noop")));
 extern esp_err_t esp_event_send_to_default_loop(system_event_t *event) __attribute((weak, alias("esp_event_send_noop")));
 
-
 esp_err_t esp_event_send_noop(system_event_t *event)
 {
     return ESP_OK;
 }
 
+static system_event_id_t esp_event_legacy_wifi_event_id(int32_t event_id)
+{
+    switch (event_id) {
+    case WIFI_EVENT_WIFI_READY:
+        return SYSTEM_EVENT_WIFI_READY;
+
+    case WIFI_EVENT_SCAN_DONE:
+        return SYSTEM_EVENT_SCAN_DONE;
+
+    case WIFI_EVENT_STA_START:
+        return SYSTEM_EVENT_STA_START;
+
+    case WIFI_EVENT_STA_STOP:
+        return SYSTEM_EVENT_STA_STOP;
+
+    case WIFI_EVENT_STA_CONNECTED:
+        return SYSTEM_EVENT_STA_CONNECTED;
+
+    case WIFI_EVENT_STA_DISCONNECTED:
+        return SYSTEM_EVENT_STA_DISCONNECTED;
+
+    case WIFI_EVENT_STA_AUTHMODE_CHANGE:
+        return SYSTEM_EVENT_STA_AUTHMODE_CHANGE;
+
+    case WIFI_EVENT_STA_WPS_ER_SUCCESS:
+        return SYSTEM_EVENT_STA_WPS_ER_SUCCESS;
+
+    case WIFI_EVENT_STA_WPS_ER_FAILED:
+        return SYSTEM_EVENT_STA_WPS_ER_FAILED;
+
+    case WIFI_EVENT_STA_WPS_ER_TIMEOUT:
+        return SYSTEM_EVENT_STA_WPS_ER_TIMEOUT;
+
+    case WIFI_EVENT_STA_WPS_ER_PIN:
+        return SYSTEM_EVENT_STA_WPS_ER_PIN;
+
+    case WIFI_EVENT_STA_WPS_ER_PBC_OVERLAP:
+        return SYSTEM_EVENT_STA_WPS_ER_PBC_OVERLAP;
+
+    case WIFI_EVENT_AP_START:
+        return SYSTEM_EVENT_AP_START;
+
+    case WIFI_EVENT_AP_STOP:
+        return SYSTEM_EVENT_AP_STOP;
+
+    case WIFI_EVENT_AP_STACONNECTED:
+        return SYSTEM_EVENT_AP_STACONNECTED;
+
+    case WIFI_EVENT_AP_STADISCONNECTED:
+        return SYSTEM_EVENT_AP_STADISCONNECTED;
+
+    case WIFI_EVENT_AP_PROBEREQRECVED:
+        return SYSTEM_EVENT_AP_PROBEREQRECVED;
+
+    default:
+        ESP_LOGE(TAG, "invalid wifi event id %d", event_id);
+        return SYSTEM_EVENT_MAX;
+    }
+}
+
+static system_event_id_t esp_event_legacy_ip_event_id(int32_t event_id)
+{
+    switch (event_id) {
+    case IP_EVENT_STA_GOT_IP:
+        return SYSTEM_EVENT_STA_GOT_IP;
+
+    case IP_EVENT_STA_LOST_IP:
+        return SYSTEM_EVENT_STA_LOST_IP;
+
+    case IP_EVENT_AP_STAIPASSIGNED:
+        return SYSTEM_EVENT_AP_STAIPASSIGNED;
+
+    case IP_EVENT_GOT_IP6:
+        return SYSTEM_EVENT_GOT_IP6;
+
+    case IP_EVENT_ETH_GOT_IP:
+        return SYSTEM_EVENT_ETH_GOT_IP;
+
+    default:
+        ESP_LOGE(TAG, "invalid ip event id %d", event_id);
+        return SYSTEM_EVENT_MAX;
+    }
+}
+
+
+static system_event_id_t esp_event_legacy_event_id(esp_event_base_t event_base, int32_t event_id)
+{
+    if (event_base == WIFI_EVENT) {
+        return esp_event_legacy_wifi_event_id(event_id);
+    } else if (event_base == IP_EVENT) {
+        return esp_event_legacy_ip_event_id(event_id);
+    } else {
+        ESP_LOGE(TAG, "invalid event base %s", event_base);
+        return SYSTEM_EVENT_MAX;
+    }
+}
+
 esp_err_t esp_event_send(system_event_t *event)
 {
     // send the event to the new style event loop
@@ -43,3 +141,27 @@ esp_err_t esp_event_send(system_event_t *event)
 
     return ESP_OK;
 }
+
+esp_err_t esp_event_send_internal(esp_event_base_t event_base,
+                            int32_t event_id,
+                            void* event_data,
+                            size_t event_data_size,
+                            TickType_t ticks_to_wait)
+{
+    system_event_t event;
+
+    // send the event to the new style event loop
+    esp_err_t err = esp_event_post(event_base, event_id, event_data, event_data_size, ticks_to_wait);
+    if (err != ESP_OK) {
+        return err;
+    }
+
+    event.event_id = esp_event_legacy_event_id(event_base, event_id);
+
+    if (event_data) {
+        memcpy(&event.event_info, event_data, event_data_size);
+    }
+
+    return esp_event_send_legacy(&event);
+}
+
index 9509ce6a754217a9536e834fa91d5ce04dfb45be..139c81763dcfcd34a6244b337cd1606ce18e668d 100644 (file)
@@ -121,7 +121,11 @@ typedef struct {
 } system_event_t;
 
 /** Event handler function type */
-typedef esp_err_t (*system_event_handler_t)(system_event_t *event);
+typedef esp_err_t (*system_event_handler_t)(esp_event_base_t event_base,
+                                            int32_t event_id,
+                                            void* event_data,
+                                            size_t event_data_size,
+                                            TickType_t ticks_to_wait);
 
 /**
   * @brief  Send a event to event task
@@ -135,7 +139,29 @@ typedef esp_err_t (*system_event_handler_t)(system_event_t *event);
   * @return ESP_OK : succeed
   * @return others : fail
   */
-esp_err_t esp_event_send(system_event_t *event);
+esp_err_t esp_event_send(system_event_t *event) __attribute__ ((deprecated));
+
+/**
+  * @brief  Send a event to event task
+  *
+  * @note This API is used by WiFi Driver only.
+  *
+  * Other task/modules, such as the tcpip_adapter, can call this API to send an event to event task
+  *
+  * @param[in] event_base the event base that identifies the event
+  * @param[in] event_id the event id that identifies the event
+  * @param[in] event_data the data, specific to the event occurence, that gets passed to the handler
+  * @param[in] event_data_size the size of the event data
+  * @param[in] ticks_to_wait number of ticks to block on a full event queue
+  *
+  * @return ESP_OK : succeed
+  * @return others : fail
+  */
+esp_err_t esp_event_send_internal(esp_event_base_t event_base,
+                            int32_t event_id,
+                            void* event_data,
+                            size_t event_data_size,
+                            TickType_t ticks_to_wait);
 
 /**
  * @brief  Default event handler for system events
@@ -152,7 +178,7 @@ esp_err_t esp_event_send(system_event_t *event);
  * @param  event   pointer to event to be handled
  * @return ESP_OK if an event was handled successfully
  */
-esp_err_t esp_event_process_default(system_event_t *event);
+esp_err_t esp_event_process_default(system_event_t *event) __attribute__ ((deprecated));
 
 /**
   * @brief  Install default event handlers for Ethernet interface
@@ -167,7 +193,7 @@ void esp_event_set_default_eth_handlers(void);
   *
   * @note This API is part of the legacy event system. New code should use event library API in esp_event.h
   */
-void esp_event_set_default_wifi_handlers(void);
+void esp_event_set_default_wifi_handlers(void) __attribute__ ((deprecated));
 
 /**
  * @brief  Application specified event callback function
@@ -198,7 +224,7 @@ typedef esp_err_t (*system_event_cb_t)(void *ctx, system_event_t *event);
  *    - ESP_OK: succeed
  *    - others: fail
  */
-esp_err_t esp_event_loop_init(system_event_cb_t cb, void *ctx);
+esp_err_t esp_event_loop_init(system_event_cb_t cb, void *ctx) __attribute__ ((deprecated));
 
 /**
  * @brief  Set application specified event callback function
@@ -214,7 +240,7 @@ esp_err_t esp_event_loop_init(system_event_cb_t cb, void *ctx);
  *
  * @return old callback
  */
-system_event_cb_t esp_event_loop_set_cb(system_event_cb_t cb, void *ctx);
+system_event_cb_t esp_event_loop_set_cb(system_event_cb_t cb, void *ctx) __attribute__ ((deprecated));
 
 #ifdef __cplusplus
 }
index 6267ee37d951cfb6b3f06fe0088ee0f7a90de323..14ab627e511251a5f3b7929b0d08bf57e24ba3d9 100644 (file)
@@ -1 +1,3 @@
-#include "esp_event_legacy.h"
+#pragma once
+#warning "esp_event_loop.h is deprecated, please include esp_event.h instead"
+#include "esp_event.h"
index b375d3f90a10e2deba85944e3bbc6ad6c43a56bd..c016f48f3c862f4650b1dd41151a3ea3c91accc1 100644 (file)
@@ -5,7 +5,7 @@
 #include "sdkconfig.h"
 
 #include "freertos/FreeRTOS.h"
-#include "esp_event_loop.h"
+#include "esp_event.h"
 #include "freertos/task.h"
 #include "freertos/portmacro.h"
 #include "esp_log.h"
index 898fab5ae0b843be269f1f656ec0d96af0c3ab46..a8bcc5e2f48a7692c41461267e62cc601cff8b4f 100644 (file)
@@ -22,7 +22,6 @@
 #include "freertos/FreeRTOS.h"
 #include "esp_err.h"
 #include "esp_event.h"
-#include "esp_event_loop.h"
 
 #ifdef __cplusplus
 extern "C" {
index 0666b182e01e78c20f7338b64abd8c9089ca34d4..4e52e649d8508fc874133f3cc80607e100834498 100644 (file)
@@ -281,7 +281,7 @@ typedef struct {
  * @brief Parent connected information
  */
 typedef struct {
-    system_event_sta_connected_t connected; /**< parent information, same as Wi-Fi event SYSTEM_EVENT_STA_CONNECTED does */
+    wifi_event_sta_connected_t connected; /**< parent information, same as Wi-Fi event SYSTEM_EVENT_STA_CONNECTED does */
     uint8_t self_layer;                     /**< layer */
 } mesh_event_connected_t;
 
@@ -324,11 +324,6 @@ typedef struct {
     uint8_t router_bssid[6];    /**< router BSSID */
 } mesh_event_find_network_t;
 
-/**
- * @brief IP settings from LwIP stack
- */
-typedef system_event_sta_got_ip_t mesh_event_root_got_ip_t;
-
 /**
  * @brief Root address
  */
@@ -337,17 +332,17 @@ typedef mesh_addr_t mesh_event_root_address_t;
 /**
  * @brief Parent disconnected information
  */
-typedef system_event_sta_disconnected_t mesh_event_disconnected_t;
+typedef wifi_event_sta_disconnected_t mesh_event_disconnected_t;
 
 /**
  * @brief Child connected information
  */
-typedef system_event_ap_staconnected_t mesh_event_child_connected_t;
+typedef wifi_event_ap_staconnected_t mesh_event_child_connected_t;
 
 /**
  * @brief Child disconnected information
  */
-typedef system_event_ap_stadisconnected_t mesh_event_child_disconnected_t;
+typedef wifi_event_ap_stadisconnected_t mesh_event_child_disconnected_t;
 
 /**
  * @brief Root switch request information
@@ -398,7 +393,7 @@ typedef struct {
 /**
  * @brief New router information
  */
-typedef system_event_sta_connected_t mesh_event_router_switch_t;
+typedef wifi_event_sta_connected_t mesh_event_router_switch_t;
 
 /**
  * @brief Mesh event information
@@ -417,7 +412,7 @@ typedef union {
                                                                 packets out. If not, devices had better to wait until this state changes to be
                                                                 MESH_TODS_REACHABLE. */
     mesh_event_vote_started_t vote_started;                /**< vote started */
-    mesh_event_root_got_ip_t got_ip;                       /**< root obtains IP address */
+    //mesh_event_root_got_ip_t got_ip;                       /**< root obtains IP address */
     mesh_event_root_address_t root_addr;                   /**< root address */
     mesh_event_root_switch_req_t switch_req;               /**< root switch request */
     mesh_event_root_conflict_t root_conflict;              /**< other powerful root */
index 80828aa886b6965ebd259b6acb026289d1351e14..087a4a16643b0b298333367b56ede394c1a43677 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD
+// Copyright 2019 Espressif Systems (Shanghai) PTE LTD
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
index 3a1eebac61336a05cffb1b6a4e054f5cae3d7480..55c70c77ca5780754bd4ad4dc4d67f37a70292c0 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD
+// Copyright 2019 Espressif Systems (Shanghai) PTE LTD
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
index 57014b8d9a2c3138b1d630d6bfe68e37637626b9..ad13bd6c7fbea10a439ad538f59ae87cc8748a32 100644 (file)
@@ -190,7 +190,7 @@ extern const wpa_crypto_funcs_t g_wifi_default_wpa_crypto_funcs;
 #endif
 
 #define WIFI_INIT_CONFIG_DEFAULT() { \
-    .event_handler = &esp_event_send, \
+    .event_handler = &esp_event_send_internal, \
     .osi_funcs = &g_wifi_osi_funcs, \
     .wpa_crypto_funcs = g_wifi_default_wpa_crypto_funcs, \
     .static_rx_buf_num = CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM,\
index fea3f14676944c5e7a057775f04127f925a32209..4dae5dc6c8d65f0c9c16174c52f561ea97b54460 100644 (file)
@@ -509,8 +509,9 @@ typedef enum {
     WIFI_EVENT_AP_STOP,                  /**< ESP32 soft-AP stop */
     WIFI_EVENT_AP_STACONNECTED,          /**< a station connected to ESP32 soft-AP */
     WIFI_EVENT_AP_STADISCONNECTED,       /**< a station disconnected from ESP32 soft-AP */
-
     WIFI_EVENT_AP_PROBEREQRECVED,        /**< Receive probe request packet in soft-AP interface */
+
+    WIFI_EVENT_MAX,                      /**< Invalid WiFi event ID */
 } wifi_event_t;
 
 /** @cond **/
index 09ed80c2b047ae5bb41ddbfb9be44ec2bc71fedd..00ed323d855e71eab0e7cbf114733de92bf0d6bb 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 09ed80c2b047ae5bb41ddbfb9be44ec2bc71fedd
+Subproject commit 00ed323d855e71eab0e7cbf114733de92bf0d6bb
index 08996d9de3a5d13e14ecbdc01735d7fb941940e3..b3d950e08e97540c1ae402f15a09202c63ade0c5 100644 (file)
@@ -5,7 +5,7 @@
 #include "esp_system.h"
 #include "unity.h"
 #include "esp_system.h"
-#include "esp_event_loop.h"
+#include "esp_event.h"
 #include "esp_wifi.h"
 #include "esp_wifi_types.h"
 #include "esp_log.h"
@@ -28,25 +28,18 @@ static uint32_t wifi_event_handler_flag;
 
 static EventGroupHandle_t wifi_events;
 
-static esp_err_t event_handler(void *ctx, system_event_t *event)
+static void wifi_event_handler(void* arg, esp_event_base_t event_base,
+                                int32_t event_id, void* event_data)
 {
-    printf("ev_handle_called.\n");
-    switch(event->event_id) {
-        case SYSTEM_EVENT_STA_START:
-            ESP_LOGI(TAG, "SYSTEM_EVENT_STA_START");
+    printf("wifi ev_handle_called.\n");
+    switch(event_id) {
+        case WIFI_EVENT_STA_START:
+            ESP_LOGI(TAG, "WIFI_EVENT_STA_START");
     //do not actually connect in test case
             //;
             break;
-        case SYSTEM_EVENT_STA_GOT_IP:
-            ESP_LOGI(TAG, "SYSTEM_EVENT_STA_GOT_IP");
-            ESP_LOGI(TAG, "got ip:%s\n",
-            ip4addr_ntoa(&event->event_info.got_ip.ip_info.ip));
-            if (wifi_events) {
-                xEventGroupSetBits(wifi_events, GOT_IP_EVENT);
-            }
-            break;
-        case SYSTEM_EVENT_STA_DISCONNECTED:
-            ESP_LOGI(TAG, "SYSTEM_EVENT_STA_DISCONNECTED");
+        case WIFI_EVENT_STA_DISCONNECTED:
+            ESP_LOGI(TAG, "WIFI_EVENT_STA_DISCONNECTED");
             if (! (EVENT_HANDLER_FLAG_DO_NOT_AUTO_RECONNECT & wifi_event_handler_flag) ) {
                 TEST_ESP_OK(esp_wifi_connect());
             }
@@ -57,6 +50,37 @@ static esp_err_t event_handler(void *ctx, system_event_t *event)
         default:
             break;
     }
+    return;
+}
+
+
+static void ip_event_handler(void* arg, esp_event_base_t event_base,
+                                int32_t event_id, void* event_data)
+{
+    ip_event_got_ip_t *event;
+
+    printf("ip ev_handle_called.\n");
+    switch(event_id) {
+        case IP_EVENT_STA_GOT_IP:
+            event = (ip_event_got_ip_t*)event_data;
+            ESP_LOGI(TAG, "IP_EVENT_STA_GOT_IP");
+            ESP_LOGI(TAG, "got ip:%s\n",
+            ip4addr_ntoa(&event->ip_info.ip));
+            if (wifi_events) {
+                xEventGroupSetBits(wifi_events, GOT_IP_EVENT);
+            }
+            break;
+        default:
+            break;
+    }
+    return;
+}
+
+static esp_err_t event_init(void)
+{
+    ESP_ERROR_CHECK(esp_event_loop_create_default());
+    ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &wifi_event_handler, NULL));
+    ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, ESP_EVENT_ANY_ID, &ip_event_handler, NULL));
     return ESP_OK;
 }
 
@@ -124,8 +148,8 @@ TEST_CASE("wifi stop and deinit","[wifi]")
     ESP_LOGI(TAG, EMPH_STR("tcpip_adapter_init"));
     tcpip_adapter_init();
     //init event loop
-    ESP_LOGI(TAG, EMPH_STR("esp_event_loop_init"));
-    TEST_ESP_OK(esp_event_loop_init(event_handler, NULL));
+    ESP_LOGI(TAG, EMPH_STR("event_init"));
+    event_init();
     
     ESP_LOGI(TAG, "test wifi init & deinit...");
     test_wifi_init_deinit(&cfg, &wifi_config);
@@ -158,7 +182,7 @@ static void start_wifi_as_softap(void)
         .ap.beacon_interval = 100,
     };
 
-    TEST_ESP_OK(esp_event_loop_init(event_handler, NULL));
+    event_init();
 
     // can't deinit event loop, need to reset leak check
     unity_reset_leak_checks();
@@ -180,7 +204,7 @@ static void start_wifi_as_sta(void)
 
     // do not auto connect
     wifi_event_handler_flag |= EVENT_HANDLER_FLAG_DO_NOT_AUTO_RECONNECT;
-    TEST_ESP_OK(esp_event_loop_init(event_handler, NULL));
+    event_init();
 
     // can't deinit event loop, need to reset leak check
     unity_reset_leak_checks();
index a30534640d4bed0ae6eaaa2ab5a3f29c051f9f1b..1ffa312c05aa71893f052bd23b13f1ec2eeeccef 100644 (file)
@@ -354,7 +354,7 @@ esp_err_t mdns_query_aaaa(const char * host_name, uint32_t timeout, ip6_addr_t *
  * @param  ctx          The system event context
  * @param  event        The system event
  */
-esp_err_t mdns_handle_system_event(void *ctx, system_event_t *event);
+esp_err_t mdns_handle_system_event(void *ctx, system_event_t *event) __attribute__((deprecated));
 
 #ifdef __cplusplus
 }
index 117eef2dad54e0f9e25b3005fcfc18e7695ff29e..fb3d2107cdac440d84f2fab81ea9b5217aa4ba1f 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 117eef2dad54e0f9e25b3005fcfc18e7695ff29e
+Subproject commit fb3d2107cdac440d84f2fab81ea9b5217aa4ba1f
index 5e3717c568af5aa576c02caca8019fcb76291658..6d2128e526931f8ebb26f851d8020ac183804128 100644 (file)
@@ -32,8 +32,6 @@ do{\
     }\
 } while(0)
 
-typedef esp_err_t (*system_event_handler_t)(system_event_t *e);
-
 static void handle_ap_start(void *arg, esp_event_base_t base, int32_t event_id, void *data);
 static void handle_ap_stop(void *arg, esp_event_base_t base, int32_t event_id, void *data);
 static void handle_sta_start(void *arg, esp_event_base_t base, int32_t event_id, void *data);
@@ -79,13 +77,12 @@ static void handle_eth_connected(void *arg, esp_event_base_t base, int32_t event
         tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_ETH, &eth_ip);
 
         if (!(ip4_addr_isany_val(eth_ip.ip) || ip4_addr_isany_val(eth_ip.netmask))) {
-            system_event_t evt;
+            ip_event_got_ip_t evt;
 
             //notify event
-            evt.event_id = SYSTEM_EVENT_ETH_GOT_IP;
-            memcpy(&evt.event_info.got_ip.ip_info, &eth_ip, sizeof(tcpip_adapter_ip_info_t));
-
-            esp_event_send(&evt);
+            evt.if_index = TCPIP_ADAPTER_IF_ETH;
+            memcpy(&evt.ip_info, &eth_ip, sizeof(tcpip_adapter_ip_info_t));
+            API_CALL_CHECK("handle_eth_connected", esp_event_send_internal(IP_EVENT, IP_EVENT_ETH_GOT_IP, &evt, sizeof(evt), 0), ESP_OK);
         } else {
             ESP_LOGE(TAG, "invalid static ip");
         }
@@ -171,20 +168,21 @@ static void handle_sta_connected(void *arg, esp_event_base_t base, int32_t event
         tcpip_adapter_get_old_ip_info(TCPIP_ADAPTER_IF_STA, &sta_old_ip);
 
         if (!(ip4_addr_isany_val(sta_ip.ip) || ip4_addr_isany_val(sta_ip.netmask))) {
-            system_event_t evt;
+            
+            ip_event_got_ip_t evt;
 
-            evt.event_id = SYSTEM_EVENT_STA_GOT_IP;
-            evt.event_info.got_ip.ip_changed = false;
+            evt.if_index = TCPIP_ADAPTER_IF_STA;
+            evt.ip_changed = false;
 
             if (memcmp(&sta_ip, &sta_old_ip, sizeof(sta_ip))) {
-                evt.event_info.got_ip.ip_changed = true;
+                evt.ip_changed = true;
             }
 
-            memcpy(&evt.event_info.got_ip.ip_info, &sta_ip, sizeof(tcpip_adapter_ip_info_t));
+            memcpy(&evt.ip_info, &sta_ip, sizeof(tcpip_adapter_ip_info_t));
             tcpip_adapter_set_old_ip_info(TCPIP_ADAPTER_IF_STA, &sta_ip);
 
-            esp_event_send(&evt);
-            ESP_LOGD(TAG, "static ip: ip changed=%d", evt.event_info.got_ip.ip_changed);
+            API_CALL_CHECK("handle_sta_connected", esp_event_send_internal(IP_EVENT, IP_EVENT_STA_GOT_IP, &evt, sizeof(evt), 0), ESP_OK);
+            ESP_LOGD(TAG, "static ip: ip changed=%d", evt.ip_changed);
         } else {
             ESP_LOGE(TAG, "invalid static ip");
         }
index 237b082a34f9f940d945b437d3c95b17b745bf78..307babe3a63650893aaaf7b61761b875974741ae 100644 (file)
@@ -92,13 +92,18 @@ static void tcpip_adapter_api_cb(void *api_msg)
 
 static void tcpip_adapter_dhcps_cb(u8_t client_ip[4])
 {
+    int ret;
+
     ESP_LOGI(TAG, "softAP assign IP to station,IP is: %d.%d.%d.%d",
              client_ip[0], client_ip[1], client_ip[2], client_ip[3]);
-    system_event_t evt;
-    memset(&evt, 0, sizeof(system_event_t));
-    evt.event_id = SYSTEM_EVENT_AP_STAIPASSIGNED;
-    memcpy((char *)&evt.event_info.ap_staipassigned.ip.addr, (char *)client_ip, sizeof(evt.event_info.ap_staipassigned.ip.addr));
-    esp_event_send(&evt);
+    ip_event_ap_staipassigned_t evt;
+
+    memset(&evt, 0, sizeof(ip_event_ap_staipassigned_t));
+    memcpy((char *)&evt.ip.addr, (char *)client_ip, sizeof(evt.ip.addr));
+    ret = esp_event_send_internal(IP_EVENT, IP_EVENT_AP_STAIPASSIGNED, &evt, sizeof(evt), 0);
+    if (ESP_OK != ret) {
+        ESP_LOGE(TAG, "dhcps cb: failed to post IP_EVENT_AP_STAIPASSIGNED (%x)", ret);
+    }
 }
 
 void tcpip_adapter_init(void)
@@ -447,23 +452,31 @@ esp_err_t tcpip_adapter_set_ip_info(tcpip_adapter_if_t tcpip_if, const tcpip_ada
         netif_set_addr(p_netif, &ip_info->ip, &ip_info->netmask, &ip_info->gw);
         if (tcpip_if == TCPIP_ADAPTER_IF_STA || tcpip_if == TCPIP_ADAPTER_IF_ETH) {
             if (!(ip4_addr_isany_val(ip_info->ip) || ip4_addr_isany_val(ip_info->netmask) || ip4_addr_isany_val(ip_info->gw))) {
-                system_event_t evt;
-                memset(&evt, 0, sizeof(system_event_t));
-                if (tcpip_if == TCPIP_ADAPTER_IF_STA) {
-                    evt.event_id = SYSTEM_EVENT_STA_GOT_IP;
-                } else if (tcpip_if == TCPIP_ADAPTER_IF_ETH) {
-                    evt.event_id = SYSTEM_EVENT_ETH_GOT_IP;
-                }
-                evt.event_info.got_ip.ip_changed = false;
+
+                ip_event_t evt_id = IP_EVENT_STA_GOT_IP;
+                ip_event_got_ip_t evt;
+                int ret;
+
+                memset(&evt, 0, sizeof(ip_event_got_ip_t));
+                evt.if_index = tcpip_if;
+                evt.ip_changed = false;
 
                 if (memcmp(ip_info, &esp_ip_old[tcpip_if], sizeof(tcpip_adapter_ip_info_t))) {
-                    evt.event_info.got_ip.ip_changed = true;
+                    evt.ip_changed = true;
+                }
+
+                if (tcpip_if == TCPIP_ADAPTER_IF_ETH) {
+                    evt_id = IP_EVENT_ETH_GOT_IP;
                 }
 
-                memcpy(&evt.event_info.got_ip.ip_info, ip_info, sizeof(tcpip_adapter_ip_info_t));
+                memcpy(&evt.ip_info, ip_info, sizeof(tcpip_adapter_ip_info_t));
                 memcpy(&esp_ip_old[tcpip_if], ip_info, sizeof(tcpip_adapter_ip_info_t));
-                esp_event_send(&evt);
-                ESP_LOGD(TAG, "if%d tcpip adapter set static ip: ip changed=%d", tcpip_if, evt.event_info.got_ip.ip_changed);
+                ret = esp_event_send_internal(IP_EVENT, evt_id, &evt, sizeof(evt), 0);
+                if (ESP_OK != ret) {
+                    ESP_LOGE(TAG, "set ip info: failed to post got ip event (%x)", ret);
+                }
+
+                ESP_LOGD(TAG, "if%d tcpip adapter set static ip: ip changed=%d", tcpip_if, evt.ip_changed);
             }
         }
     }
@@ -479,13 +492,12 @@ static esp_err_t tcpip_adapter_set_ip_info_api(tcpip_adapter_api_msg_t *msg)
 static void tcpip_adapter_nd6_cb(struct netif *p_netif, uint8_t ip_idex)
 {
     tcpip_adapter_ip6_info_t *ip6_info;
+    int ret;
 
-    system_event_t evt;
-    memset(&evt, 0, sizeof(system_event_t));
+    ip_event_got_ip6_t evt;
+    memset(&evt, 0, sizeof(ip_event_got_ip6_t));
     //notify event
 
-    evt.event_id = SYSTEM_EVENT_GOT_IP6;
-
     if (!p_netif) {
         ESP_LOGD(TAG, "null p_netif=%p", p_netif);
         return;
@@ -493,21 +505,24 @@ static void tcpip_adapter_nd6_cb(struct netif *p_netif, uint8_t ip_idex)
 
     if (p_netif == esp_netif[TCPIP_ADAPTER_IF_STA]) {
         ip6_info = &esp_ip6[TCPIP_ADAPTER_IF_STA];
-        evt.event_info.got_ip6.if_index = TCPIP_ADAPTER_IF_STA;
+        evt.if_index = TCPIP_ADAPTER_IF_STA;
     } else if (p_netif == esp_netif[TCPIP_ADAPTER_IF_AP]) {
         ip6_info = &esp_ip6[TCPIP_ADAPTER_IF_AP];
-        evt.event_info.got_ip6.if_index = TCPIP_ADAPTER_IF_AP;
+        evt.if_index = TCPIP_ADAPTER_IF_AP;
     } else if (p_netif == esp_netif[TCPIP_ADAPTER_IF_ETH]) {
         ip6_info = &esp_ip6[TCPIP_ADAPTER_IF_ETH];
-        evt.event_info.got_ip6.if_index = TCPIP_ADAPTER_IF_ETH;
+        evt.if_index = TCPIP_ADAPTER_IF_ETH;
     } else {
         return;
     }
 
     ip6_addr_set(&ip6_info->ip, ip_2_ip6(&p_netif->ip6_addr[ip_idex]));
 
-    memcpy(&evt.event_info.got_ip6.ip6_info, ip6_info, sizeof(tcpip_adapter_ip6_info_t));
-    esp_event_send(&evt);
+    memcpy(&evt.ip6_info, ip6_info, sizeof(tcpip_adapter_ip6_info_t));
+    ret = esp_event_send_internal(IP_EVENT, IP_EVENT_GOT_IP6, &evt, sizeof(evt), 0);
+    if (ESP_OK != ret) {
+        ESP_LOGE(TAG, "nd6 cb: failed to post IP_EVENT_GOT_IP6 (%x)", ret);
+    }
 }
 
 esp_err_t tcpip_adapter_create_ip6_linklocal(tcpip_adapter_if_t tcpip_if)
@@ -921,30 +936,37 @@ static void tcpip_adapter_dhcpc_cb(struct netif *netif)
         if ( !ip4_addr_cmp(ip_2_ip4(&netif->ip_addr), (&ip_info->ip)) ||
                 !ip4_addr_cmp(ip_2_ip4(&netif->netmask), (&ip_info->netmask)) ||
                 !ip4_addr_cmp(ip_2_ip4(&netif->gw), (&ip_info->gw)) ) {
-            system_event_t evt;
-            memset(&evt, 0, sizeof(system_event_t));
+            ip_event_got_ip_t evt;
+            ip_event_t evt_id;
+            int ret;
+
+            memset(&evt, 0, sizeof(ip_event_got_ip_t));
 
             ip4_addr_set(&ip_info->ip, ip_2_ip4(&netif->ip_addr));
             ip4_addr_set(&ip_info->netmask, ip_2_ip4(&netif->netmask));
             ip4_addr_set(&ip_info->gw, ip_2_ip4(&netif->gw));
 
             //notify event
+            evt.if_index = tcpip_if;
             if (tcpip_if == TCPIP_ADAPTER_IF_ETH) {
-                evt.event_id = SYSTEM_EVENT_ETH_GOT_IP;
-                evt.event_info.got_ip.ip_changed = true;
+                evt_id = IP_EVENT_ETH_GOT_IP;
+                evt.ip_changed = true;
             } else {
-                evt.event_id = SYSTEM_EVENT_STA_GOT_IP;
-                evt.event_info.got_ip.ip_changed = false;
+                evt_id = IP_EVENT_STA_GOT_IP;
+                evt.ip_changed = false;
             }
 
             if (memcmp(ip_info, ip_info_old, sizeof(tcpip_adapter_ip_info_t))) {
-                evt.event_info.got_ip.ip_changed = true;
+                evt.ip_changed = true;
             }
 
-            memcpy(&evt.event_info.got_ip.ip_info, ip_info, sizeof(tcpip_adapter_ip_info_t));
+            memcpy(&evt.ip_info, ip_info, sizeof(tcpip_adapter_ip_info_t));
             memcpy(ip_info_old, ip_info, sizeof(tcpip_adapter_ip_info_t));
-            ESP_LOGD(TAG, "if%d ip changed=%d", tcpip_if, evt.event_info.got_ip.ip_changed);
-            esp_event_send(&evt);
+            ESP_LOGD(TAG, "if%d ip changed=%d", tcpip_if, evt.ip_changed);
+            ret = esp_event_send_internal(IP_EVENT, evt_id, &evt, sizeof(evt), 0);
+            if (ESP_OK != ret) {
+                ESP_LOGE(TAG, "dhcpc cb: failed to post got ip event (%x)", ret);
+            }
         } else {
             ESP_LOGD(TAG, "if%d ip unchanged", tcpip_if);
         }
@@ -997,13 +1019,17 @@ static void tcpip_adapter_ip_lost_timer(void *arg)
         struct netif *netif = esp_netif[tcpip_if];
 
         if ( (!netif) || (netif && ip4_addr_cmp(ip_2_ip4(&netif->ip_addr), IP4_ADDR_ANY4))) {
-            system_event_t evt;
-            memset(&evt, 0, sizeof(system_event_t));
+            ip_event_got_ip_t evt;
+            int ret;
+            memset(&evt, 0, sizeof(ip_event_got_ip_t));
 
             ESP_LOGD(TAG, "if%d ip lost tmr: raise ip lost event", tcpip_if);
+            evt.if_index = tcpip_if;
             memset(&esp_ip_old[tcpip_if], 0, sizeof(tcpip_adapter_ip_info_t));
-            evt.event_id = SYSTEM_EVENT_STA_LOST_IP;
-            esp_event_send(&evt);
+            ret = esp_event_send_internal(IP_EVENT, IP_EVENT_STA_LOST_IP, &evt, sizeof(evt), 0);
+            if (ESP_OK != ret) {
+                ESP_LOGE(TAG, "ip lost timer: failed to post lost ip event (%x)", ret);
+            }
         } else {
             ESP_LOGD(TAG, "if%d ip lost tmr: no need raise ip lost event", tcpip_if);
         }
index 8f31aedba506bf9ac037df80a71697f872dd4096..2edd43fee94d62354dafea03e5a9701b895e7ab2 100644 (file)
@@ -14,9 +14,9 @@
 
 #pragma once
 
-#include <esp_event_loop.h>
 #include <protocomm.h>
 
+#include "esp_event.h"
 #include "wifi_provisioning/wifi_config.h"
 
 #ifdef __cplusplus
index 756e82f452765355d742eeda7410db4a402c2817..a607b49dcb1d04ed22745c7098d99bf31dbaa372 100644 (file)
@@ -14,8 +14,6 @@
 
 #pragma once
 
-#include <esp_event_loop.h>
-
 #include <protocomm.h>
 #include <protocomm_security.h>
 
index 62d2d6246ec9062851ce620da63e4d44bcab9c20..820b71392442deb9446d11de4f78740288be47e7 100644 (file)
@@ -213,7 +213,6 @@ bool esp_wifi_get_sniffer_internal(void);
 int esp_wifi_set_wps_cb_internal(struct wps_funcs *wps_cb);
 bool esp_wifi_enable_sta_privacy_internal(void);
 uint8_t esp_wifi_get_user_init_flag_internal(void);
-esp_err_t esp_wifi_send_event_internal(system_event_t *evt);
 esp_err_t esp_wifi_internal_supplicant_header_md5_check(const char *md5);
 int esp_wifi_sta_update_ap_info_internal(void);
 uint8_t *esp_wifi_sta_get_ap_info_prof_pmk_internal(void);
index cbcd35197320cea271eea3b8620d24acd71c8742..16f6f9965ba0a2a6a0c6d87fac003bae81f0ef05 100644 (file)
@@ -413,10 +413,9 @@ struct wps_data *wps_init(void)
             os_bzero(tmpp, 9);
             memcpy(tmpp, data->dev_password, 8);
             wpa_printf(MSG_DEBUG, "WPS PIN [%s]", tmpp);
-            system_event_t evt;
-            evt.event_id = SYSTEM_EVENT_STA_WPS_ER_PIN;
-            memcpy(evt.event_info.sta_er_pin.pin_code, data->dev_password, 8);
-            esp_wifi_send_event_internal(&evt);
+            wifi_event_sta_wps_er_pin_t evt;
+            memcpy(evt.pin_code, data->dev_password, 8);
+            esp_event_send_internal(WIFI_EVENT, WIFI_EVENT_STA_WPS_ER_PIN, &evt, sizeof(evt), portMAX_DELAY);
         } while (0);
     } else if (wps_get_type() == WPS_TYPE_PBC) {
         data->pbc = 1;
@@ -931,7 +930,7 @@ int wps_start_pending(void)
     return wps_tx_start();
 }
 
-int wps_stop_process(system_event_sta_wps_fail_reason_t reason_code)
+int wps_stop_process(wifi_event_sta_wps_fail_reason_t reason_code)
 {
     struct wps_sm *sm = gWpsSm;
 
@@ -955,10 +954,8 @@ int wps_stop_process(system_event_sta_wps_fail_reason_t reason_code)
     esp_wifi_disconnect();
 
     wpa_printf(MSG_DEBUG, "Write wps_fail_information");
-    system_event_t evt;
-    evt.event_id = SYSTEM_EVENT_STA_WPS_ER_FAILED;
-    evt.event_info.sta_er_fail_reason = reason_code;
-    esp_wifi_send_event_internal(&evt);
+    
+    esp_event_send_internal(WIFI_EVENT, WIFI_EVENT_STA_WPS_ER_FAILED, &reason_code, sizeof(reason_code), portMAX_DELAY);
 
     return ESP_OK;
 }
@@ -976,9 +973,7 @@ int wps_finish(void)
         wifi_config_t *config = (wifi_config_t *)os_zalloc(sizeof(wifi_config_t));
 
         if (config == NULL) {
-            system_event_t evt;
-            evt.event_id = SYSTEM_EVENT_STA_WPS_ER_FAILED;
-            esp_wifi_send_event_internal(&evt);
+            esp_event_send_internal(WIFI_EVENT, WIFI_EVENT_STA_WPS_ER_FAILED, 0, 0, portMAX_DELAY);
             return ESP_FAIL;
         }
 
@@ -1251,9 +1246,7 @@ out:
         esp_wifi_disarm_sta_connection_timer_internal();
         ets_timer_disarm(&sm->wps_timeout_timer);
 
-        system_event_t evt;
-        evt.event_id = SYSTEM_EVENT_STA_WPS_ER_FAILED;
-        esp_wifi_send_event_internal(&evt);
+        esp_event_send_internal(WIFI_EVENT, WIFI_EVENT_STA_WPS_ER_FAILED, 0, 0, portMAX_DELAY);
 
         return ret;
     }
@@ -1456,9 +1449,7 @@ wifi_station_wps_timeout_internal(void)
 
     wps_set_status(WPS_STATUS_DISABLE);
 
-    system_event_t evt;
-    evt.event_id = SYSTEM_EVENT_STA_WPS_ER_TIMEOUT;
-    esp_wifi_send_event_internal(&evt);
+    esp_event_send_internal(WIFI_EVENT, WIFI_EVENT_STA_WPS_ER_TIMEOUT, 0, 0, portMAX_DELAY);
 }
 
 void wifi_station_wps_timeout(void)
@@ -1503,9 +1494,7 @@ void wifi_station_wps_msg_timeout(void)
 
 void wifi_station_wps_success_internal(void)
 {
-    system_event_t evt;
-    evt.event_id = SYSTEM_EVENT_STA_WPS_ER_SUCCESS;
-    esp_wifi_send_event_internal(&evt);
+    esp_event_send_internal(WIFI_EVENT, WIFI_EVENT_STA_WPS_ER_SUCCESS, 0, 0, portMAX_DELAY);
 }
 
 void wifi_station_wps_success(void)
@@ -1780,10 +1769,7 @@ wifi_wps_scan_done(void *arg, STATUS status)
     } else {
         wpa_printf(MSG_INFO, "PBC session overlap!");
         wps_set_status(WPS_STATUS_DISABLE);
-
-        system_event_t evt;
-        evt.event_id = SYSTEM_EVENT_STA_WPS_ER_PBC_OVERLAP;
-        esp_wifi_send_event_internal(&evt);
+        esp_event_send_internal(WIFI_EVENT, WIFI_EVENT_STA_WPS_ER_PBC_OVERLAP, 0, 0, portMAX_DELAY);
     }
 
     wpa_printf(MSG_DEBUG, "wps scan_done discover_ssid_cnt = %d", sm->discover_ssid_cnt);
index b7584735a9a76f2f9f9010e12e2a691c3e05688e..f7900d59bafc32c662397bdd86a06f0b13df6435 100644 (file)
@@ -12,7 +12,7 @@
 #include "freertos/event_groups.h"
 #include "esp_system.h"
 #include "esp_wifi.h"
-#include "esp_event_loop.h"
+#include "esp_event.h"
 #include "esp_log.h"
 #include "nvs_flash.h"
 #include "esp_bt.h"
index bd3b86e2194f9c46e3f3bb362ca9ba077e94f1ea..cf3e15330349f5dd39104d3ba668d73413850409 100644 (file)
@@ -22,7 +22,7 @@
 #include "freertos/event_groups.h"
 #include "esp_system.h"
 #include "esp_wifi.h"
-#include "esp_event_loop.h"
+#include "esp_event.h"
 #include "esp_log.h"
 #include "nvs_flash.h"
 #include "esp_bt.h"
@@ -93,15 +93,14 @@ static int gl_sta_ssid_len;
 /* connect infor*/
 static uint8_t server_if;
 static uint16_t conn_id;
-static esp_err_t example_net_event_handler(void *ctx, system_event_t *event)
+
+static void ip_event_handler(void* arg, esp_event_base_t event_base,
+                                int32_t event_id, void* event_data)
 {
     wifi_mode_t mode;
 
-    switch (event->event_id) {
-    case SYSTEM_EVENT_STA_START:
-        esp_wifi_connect();
-        break;
-    case SYSTEM_EVENT_STA_GOT_IP: {
+    switch (event_id) {
+    case IP_EVENT_STA_GOT_IP: {
         esp_blufi_extra_info_t info;
 
         xEventGroupSetBits(wifi_event_group, CONNECTED_BIT);
@@ -115,13 +114,30 @@ static esp_err_t example_net_event_handler(void *ctx, system_event_t *event)
         esp_blufi_send_wifi_conn_report(mode, ESP_BLUFI_STA_CONN_SUCCESS, 0, &info);
         break;
     }
-    case SYSTEM_EVENT_STA_CONNECTED:
+    default:
+        break;
+    }
+    return;
+}
+
+static void wifi_event_handler(void* arg, esp_event_base_t event_base,
+                                int32_t event_id, void* event_data)
+{
+    wifi_event_sta_connected_t *event;
+    wifi_mode_t mode;
+
+    switch (event_id) {
+    case WIFI_EVENT_STA_START:
+        esp_wifi_connect();
+        break;
+    case WIFI_EVENT_STA_CONNECTED:
         gl_sta_connected = true;
-        memcpy(gl_sta_bssid, event->event_info.connected.bssid, 6);
-        memcpy(gl_sta_ssid, event->event_info.connected.ssid, event->event_info.connected.ssid_len);
-        gl_sta_ssid_len = event->event_info.connected.ssid_len;
+        event = (wifi_event_sta_connected_t*) event_data;
+        memcpy(gl_sta_bssid, event->bssid, 6);
+        memcpy(gl_sta_ssid, event->ssid, event->ssid_len);
+        gl_sta_ssid_len = event->ssid_len;
         break; 
-    case SYSTEM_EVENT_STA_DISCONNECTED:
+    case WIFI_EVENT_STA_DISCONNECTED:
         /* This is a workaround as ESP32 WiFi libs don't currently
            auto-reassociate. */
         gl_sta_connected = false;
@@ -131,7 +147,7 @@ static esp_err_t example_net_event_handler(void *ctx, system_event_t *event)
         esp_wifi_connect();
         xEventGroupClearBits(wifi_event_group, CONNECTED_BIT);
         break;
-    case SYSTEM_EVENT_AP_START:
+    case WIFI_EVENT_AP_START:
         esp_wifi_get_mode(&mode);
 
         /* TODO: get config or information of softap, then set to report extra_info */
@@ -141,7 +157,7 @@ static esp_err_t example_net_event_handler(void *ctx, system_event_t *event)
             esp_blufi_send_wifi_conn_report(mode, ESP_BLUFI_STA_CONN_FAIL, 0, NULL);
         }
         break;
-    case SYSTEM_EVENT_SCAN_DONE: {
+    case WIFI_EVENT_SCAN_DONE: {
         uint16_t apCount = 0;
         esp_wifi_scan_get_ap_num(&apCount);
         if (apCount == 0) {
@@ -176,14 +192,17 @@ static esp_err_t example_net_event_handler(void *ctx, system_event_t *event)
     default:
         break;
     }
-    return ESP_OK;
+    return;
 }
 
 static void initialise_wifi(void)
 {
     tcpip_adapter_init();
     wifi_event_group = xEventGroupCreate();
-    ESP_ERROR_CHECK( esp_event_loop_init(example_net_event_handler, NULL) );
+    ESP_ERROR_CHECK(esp_event_loop_create_default());
+    ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &wifi_event_handler, NULL));
+    ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &ip_event_handler, NULL));
+
     wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
     ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
     ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) );
index f790e58e5b34c3f790570efecccd823dad6d3196..635d5f00a2c74a6fd7a7f97b204d8922e407d594 100644 (file)
@@ -14,7 +14,7 @@
 #include "freertos/event_groups.h"
 #include "esp_system.h"
 #include "esp_wifi.h"
-#include "esp_event_loop.h"
+#include "esp_event.h"
 #include "esp_log.h"
 #include "nvs_flash.h"
 #include "esp_bt.h"
index 15ebcb21cc2d123e97ab7e92247f2bef8490107d..8fd95ce474da773fd8422a215d826016ef81dc9e 100644 (file)
@@ -17,7 +17,6 @@
 #include "freertos/event_groups.h"
 #include "esp_wifi.h"
 #include "tcpip_adapter.h"
-#include "esp_event_loop.h"
 #include "iperf.h"
 
 typedef struct {
@@ -74,22 +73,18 @@ static void scan_done_handler(void)
     free(ap_list_buffer);
 }
 
-static esp_err_t event_handler(void *ctx, system_event_t *event)
+static void wifi_event_handler(void* arg, esp_event_base_t event_base,
+                                int32_t event_id, void* event_data)
 {
-    switch (event->event_id) {
-    case SYSTEM_EVENT_STA_GOT_IP:
-        xEventGroupClearBits(wifi_event_group, DISCONNECTED_BIT);
-        xEventGroupSetBits(wifi_event_group, CONNECTED_BIT);
-        ESP_LOGI(TAG, "got ip");
-        break;
-    case SYSTEM_EVENT_SCAN_DONE:
+    switch (event_id) {
+    case WIFI_EVENT_SCAN_DONE:
         scan_done_handler();
         ESP_LOGI(TAG, "sta scan done");
         break;
-    case SYSTEM_EVENT_STA_CONNECTED:
+    case WIFI_EVENT_STA_CONNECTED:
         ESP_LOGI(TAG, "L2 connected");
         break;
-    case SYSTEM_EVENT_STA_DISCONNECTED:
+    case WIFI_EVENT_STA_DISCONNECTED:
         if (reconnect) {
             ESP_LOGI(TAG, "sta disconnect, reconnect...");
             esp_wifi_connect();
@@ -102,7 +97,22 @@ static esp_err_t event_handler(void *ctx, system_event_t *event)
     default:
         break;
     }
-    return ESP_OK;
+    return;
+}
+
+static void ip_event_handler(void* arg, esp_event_base_t event_base,
+                                int32_t event_id, void* event_data)
+{
+    switch (event_id) {
+    case IP_EVENT_STA_GOT_IP:
+        xEventGroupClearBits(wifi_event_group, DISCONNECTED_BIT);
+        xEventGroupSetBits(wifi_event_group, CONNECTED_BIT);
+        ESP_LOGI(TAG, "got ip");
+        break;
+    default:
+        break;
+    }
+    return;
 }
 
 void initialise_wifi(void)
@@ -116,7 +126,10 @@ void initialise_wifi(void)
 
     tcpip_adapter_init();
     wifi_event_group = xEventGroupCreate();
-    ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) );
+    ESP_ERROR_CHECK(esp_event_loop_create_default());
+    ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &wifi_event_handler, NULL));
+    ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &ip_event_handler, NULL));
+
     wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
     ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
     ESP_ERROR_CHECK( esp_wifi_set_ps(WIFI_PS_MIN_MODEM) ); //must call this
index 3b540fad0571dd17ec24262cdf2c6bfc06ea764f..b9b2193a2a52daedb1e9fecb784b56ad1a0a2166 100644 (file)
@@ -11,7 +11,6 @@
 #include "freertos/FreeRTOS.h"
 #include "freertos/task.h"
 #include "freertos/queue.h"
-#include "esp_event_loop.h"
 #include "esp_event.h"
 #include "esp_log.h"
 #include "esp_eth.h"
index 0defcb4ec5b68791fb50b51752af6edc4b608624..cd01465d86d1a507d7bb645c882ec3adf07c866c 100644 (file)
@@ -24,7 +24,6 @@
 #include "esp_wifi.h"
 #include "esp_system.h"
 #include "esp_event.h"
-#include "esp_event_loop.h"
 #include "nvs_flash.h"
 #include "soc/rtc_periph.h"
 #include "driver/spi_slave.h"
index a8bcc6e0b67caafe7886358d59d3e8fdec149872..c3a8007c7dc41cc410ee6f15ae9584319e9391e3 100644 (file)
@@ -24,7 +24,6 @@
 #include "esp_wifi.h"
 #include "esp_system.h"
 #include "esp_event.h"
-#include "esp_event_loop.h"
 #include "nvs_flash.h"
 #include "soc/rtc_periph.h"
 #include "driver/spi_master.h"
index af9ae1a87d4d87cd7b8d6d19e72cd2a798d40847..118a380a8fe91faada8ef78a60bc5b95527fc006 100644 (file)
@@ -8,7 +8,7 @@
 */
 
 #include "esp_wifi.h"
-#include "esp_event_loop.h"
+#include "esp_event.h"
 #include "esp_log.h"
 #include "esp_system.h"
 #include "nvs_flash.h"
index 421355da33ac047ded08b2fd50c0252c2b03e2f8..4a6faf5a2da0e272bc8c1cb75fe0585f0d6e0e59 100644 (file)
@@ -10,7 +10,7 @@
 #include <sys/param.h>
 
 #include "esp_wifi.h"
-#include "esp_event_loop.h"
+#include "esp_event.h"
 #include "esp_log.h"
 #include "esp_system.h"
 #include "esp_spiffs.h"
index 725de62e10536d893548bf4beacd1676089a7b52..8e6132b1e6221e7ca744cfbcfe24cd72a2c609d1 100644 (file)
@@ -8,7 +8,7 @@
 */
 
 #include <esp_wifi.h>
-#include <esp_event_loop.h>
+#include <esp_event.h>
 #include <esp_log.h>
 #include <esp_system.h>
 #include <nvs_flash.h>
index ee13bfa354921f5ca140e30b1c1f41c40189fc0d..c82711ca4b6623e9cda5f2b12edc736046f53995 100644 (file)
@@ -6,7 +6,6 @@
    software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
    CONDITIONS OF ANY KIND, either express or implied.
 */
-#include "esp_event_loop.h"
 #include "driver/sdmmc_host.h"
 #include "driver/gpio.h"
 #include "esp_vfs_semihost.h"
index a71f44e5983313fb64f035b8d0040497cc1e7bce..6d6a36931acde8f0f8fd8b61136bf2de92c82e21 100644 (file)
@@ -8,7 +8,7 @@
 */
 
 #include <esp_wifi.h>
-#include <esp_event_loop.h>
+#include <esp_event.h>
 #include <esp_log.h>
 #include <esp_system.h>
 #include <nvs_flash.h>
index 6b64ef25d04154f6e4ba7eec8e3a6c0791b7ea8f..901d2ad92c5c0bbfbc888d95da5b3fee0fa8214d 100644 (file)
@@ -12,7 +12,7 @@
 #include "esp_wifi.h"
 #include "esp_system.h"
 #include "nvs_flash.h"
-#include "esp_event_loop.h"
+#include "esp_event.h"
 #include "protocol_examples_common.h"
 
 #include "freertos/FreeRTOS.h"
@@ -23,7 +23,6 @@
 #include "esp_log.h"
 #include "esp_websocket_client.h"
 #include "esp_event.h"
-#include "esp_event_loop.h"
 
 static const char *TAG = "WEBSOCKET";
 static const char *WEBSOCKET_ECHO_ENDPOINT = CONFIG_WEBSOCKET_URI;
index 97d5abaf9cc050ccfd99da7823f41da3b4cbde6e..64e4dbe3adf2a3faafd8152c8523fef553790d18 100644 (file)
@@ -9,8 +9,6 @@
 
 #pragma once
 
-#include <esp_event_loop.h>
-
 #include <protocomm_security.h>
 #include <wifi_provisioning/wifi_config.h>
 
index c6e026bc0aa95d56498df5758274e3994b02aab1..5e6d884741c7507782b31ae938994cf71bf60886 100644 (file)
@@ -9,8 +9,6 @@
 
 #pragma once
 
-#include <esp_event_loop.h>
-
 #include <protocomm_security.h>
 #include <wifi_provisioning/wifi_config.h>
 
index b575100bf02aaf2e995747edb0f01e4634c98d22..be46b294515a0394042435b20fb27dffac710e32 100644 (file)
@@ -9,7 +9,7 @@
 
 #pragma once
 
-#include <esp_event_loop.h>
+#include <esp_event.h>
 
 #include <protocomm_security.h>
 #include <wifi_provisioning/wifi_config.h>
index 312d00e409ac18df691b7d32a00bbbaec041e3db..c87ff4f0b98cdf0a6b55ce705c1183b55ce64a3e 100644 (file)
@@ -9,7 +9,7 @@
 
 #pragma once
 
-#include <esp_event_loop.h>
+#include <esp_event.h>
 
 #include <protocomm_security.h>
 #include <wifi_provisioning/wifi_config.h>
index 91ca4f10c53931b32dcb7c583dbd6c06c7959d8f..e9733a3df48d42c9732e3216371dbc0b74bd2563 100644 (file)
@@ -11,7 +11,6 @@
 #define EVENT_SOURCE_H_
 
 #include "esp_event.h"
-#include "esp_event_loop.h"
 #include "esp_timer.h"
 
 #ifdef __cplusplus
@@ -50,4 +49,4 @@ enum {
 }
 #endif
 
-#endif // #ifndef EVENT_SOURCE_H_
\ No newline at end of file
+#endif // #ifndef EVENT_SOURCE_H_
index 73a3b69c126905416a227b03e42f4bbe85582a58..2e1787d8e24c5fade9dd637bf0c6e8515cdd04d8 100644 (file)
@@ -11,7 +11,6 @@
 #define EVENT_SOURCE_H_
 
 #include "esp_event.h"
-#include "esp_event_loop.h"
 #include "esp_timer.h"
 
 #ifdef __cplusplus
@@ -32,4 +31,4 @@ enum {
 }
 #endif
 
-#endif // #ifndef EVENT_SOURCE_H_
\ No newline at end of file
+#endif // #ifndef EVENT_SOURCE_H_
index 9b9dfe2d023e9f9433b0ddcebd845a48c13e8825..dc88173573fc312a5e4e491f73ab107960bbd3f5 100644 (file)
@@ -12,7 +12,7 @@
 #include "freertos/event_groups.h"
 #include "esp_system.h"
 #include "esp_wifi.h"
-#include "esp_event_loop.h"
+#include "esp_event.h"
 #include "esp_log.h"
 #include "nvs_flash.h"
 #include "driver/uart.h"
index aafa488883516c845a9331152110a67fc915acb0..a207a9130411501b139ca87fb00afd1a39807a3c 100644 (file)
@@ -12,7 +12,6 @@
 #include "freertos/event_groups.h"
 #include "esp_system.h"
 #include "esp_event.h"
-#include "esp_event_loop.h"
 #include "esp_log.h"
 #include "esp_ota_ops.h"
 #include "esp_http_client.h"
index 9d84cc07c6d1948a031edaeecf2fd3cfc9c4c51d..1c8ea033f7c324ffc4d62939f4715959647cfca6 100644 (file)
@@ -11,7 +11,6 @@
 #include "freertos/task.h"
 #include "esp_system.h"
 #include "esp_event.h"
-#include "esp_event_loop.h"
 #include "esp_log.h"
 #include "esp_ota_ops.h"
 #include "esp_http_client.h"
index 9d0187f3bcc17f2558513db003b253ab7bc15faf..f85186e2b67c19dd95894f4a0ab14bfe9dc0bd50 100644 (file)
@@ -10,7 +10,6 @@
 #include "freertos/task.h"
 #include "esp_system.h"
 #include "esp_event.h"
-#include "esp_event_loop.h"
 #include "esp_log.h"
 #include "esp_ota_ops.h"
 #include "esp_http_client.h"