From 003a9872b7de69d799e9d37521cfbcaff9b37e85 Mon Sep 17 00:00:00 2001 From: liu zhifu Date: Fri, 5 Jul 2019 16:58:04 +0800 Subject: [PATCH] esp_wifi: wifi support new event mechanism 1. WiFi support new event mechanism 2. Update examples to use new event mechanism --- components/driver/test/test_adc2.c | 56 ++++++-- components/esp_event/event_send.c | 128 +++++++++++++++++- .../esp_event/include/esp_event_legacy.h | 38 +++++- components/esp_event/include/esp_event_loop.h | 4 +- components/esp_event/test/test_event.c | 2 +- .../include/esp_websocket_client.h | 1 - components/esp_wifi/include/esp_mesh.h | 17 +-- .../include/esp_private/esp_wifi_private.h | 2 +- .../esp_private/esp_wifi_types_private.h | 2 +- components/esp_wifi/include/esp_wifi.h | 2 +- components/esp_wifi/include/esp_wifi_types.h | 3 +- components/esp_wifi/lib_esp32 | 2 +- components/esp_wifi/test/test_wifi.c | 64 ++++++--- components/mdns/include/mdns.h | 2 +- components/mqtt/esp-mqtt | 2 +- components/tcpip_adapter/event_handlers.c | 26 ++-- components/tcpip_adapter/tcpip_adapter_lwip.c | 106 +++++++++------ .../include/wifi_provisioning/manager.h | 2 +- .../src/wifi_provisioning_priv.h | 2 - .../src/esp_supplicant/esp_wifi_driver.h | 1 - .../src/esp_supplicant/esp_wps.c | 36 ++--- .../main/ble_hidd_demo_main.c | 2 +- .../ble/blufi/main/blufi_example_main.c | 51 ++++--- .../bluedroid/ble/blufi/main/blufi_security.c | 2 +- .../components/iperf/cmd_wifi.c | 39 ++++-- .../eth2ap/main/ethernet_example_main.c | 1 - .../spi_slave/receiver/main/app_main.c | 1 - .../spi_slave/sender/main/app_main.c | 1 - .../http_server/advanced_tests/main/main.c | 2 +- .../http_server/file_serving/main/main.c | 2 +- .../persistent_sockets/main/main.c | 2 +- .../restful_server/main/esp_rest_main.c | 1 - examples/protocols/https_server/main/main.c | 2 +- .../websocket/main/websocket_example.c | 3 +- .../provisioning/ble_prov/main/app_prov.h | 2 - .../provisioning/console_prov/main/app_prov.h | 2 - .../custom_config/main/app_prov.h | 2 +- .../provisioning/softap_prov/main/app_prov.h | 2 +- .../default_event_loop/main/event_source.h | 3 +- .../user_event_loops/main/event_source.h | 3 +- .../system/network_tests/main/net_suite.c | 2 +- .../main/advanced_https_ota_example.c | 1 - .../main/native_ota_example.c | 1 - .../main/simple_ota_example.c | 1 - 44 files changed, 425 insertions(+), 201 deletions(-) diff --git a/components/driver/test/test_adc2.c b/components/driver/test/test_adc2.c index 40549428e..1438ae4d5 100644 --- a/components/driver/test/test_adc2.c +++ b/components/driver/test/test_adc2.c @@ -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 diff --git a/components/esp_event/event_send.c b/components/esp_event/event_send.c index 2c31ee0f6..80fe464a8 100644 --- a/components/esp_event/event_send.c +++ b/components/esp_event/event_send.c @@ -12,21 +12,119 @@ // See the License for the specific language governing permissions and // limitations under the License. - +#include +#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); +} + diff --git a/components/esp_event/include/esp_event_legacy.h b/components/esp_event/include/esp_event_legacy.h index 9509ce6a7..139c81763 100644 --- a/components/esp_event/include/esp_event_legacy.h +++ b/components/esp_event/include/esp_event_legacy.h @@ -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 } diff --git a/components/esp_event/include/esp_event_loop.h b/components/esp_event/include/esp_event_loop.h index 6267ee37d..14ab627e5 100644 --- a/components/esp_event/include/esp_event_loop.h +++ b/components/esp_event/include/esp_event_loop.h @@ -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" diff --git a/components/esp_event/test/test_event.c b/components/esp_event/test/test_event.c index b375d3f90..c016f48f3 100644 --- a/components/esp_event/test/test_event.c +++ b/components/esp_event/test/test_event.c @@ -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" diff --git a/components/esp_websocket_client/include/esp_websocket_client.h b/components/esp_websocket_client/include/esp_websocket_client.h index 898fab5ae..a8bcc5e2f 100644 --- a/components/esp_websocket_client/include/esp_websocket_client.h +++ b/components/esp_websocket_client/include/esp_websocket_client.h @@ -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" { diff --git a/components/esp_wifi/include/esp_mesh.h b/components/esp_wifi/include/esp_mesh.h index 0666b182e..4e52e649d 100644 --- a/components/esp_wifi/include/esp_mesh.h +++ b/components/esp_wifi/include/esp_mesh.h @@ -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 */ diff --git a/components/esp_wifi/include/esp_private/esp_wifi_private.h b/components/esp_wifi/include/esp_private/esp_wifi_private.h index 80828aa88..087a4a166 100644 --- a/components/esp_wifi/include/esp_private/esp_wifi_private.h +++ b/components/esp_wifi/include/esp_private/esp_wifi_private.h @@ -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. diff --git a/components/esp_wifi/include/esp_private/esp_wifi_types_private.h b/components/esp_wifi/include/esp_private/esp_wifi_types_private.h index 3a1eebac6..55c70c77c 100644 --- a/components/esp_wifi/include/esp_private/esp_wifi_types_private.h +++ b/components/esp_wifi/include/esp_private/esp_wifi_types_private.h @@ -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. diff --git a/components/esp_wifi/include/esp_wifi.h b/components/esp_wifi/include/esp_wifi.h index 57014b8d9..ad13bd6c7 100644 --- a/components/esp_wifi/include/esp_wifi.h +++ b/components/esp_wifi/include/esp_wifi.h @@ -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,\ diff --git a/components/esp_wifi/include/esp_wifi_types.h b/components/esp_wifi/include/esp_wifi_types.h index fea3f1467..4dae5dc6c 100644 --- a/components/esp_wifi/include/esp_wifi_types.h +++ b/components/esp_wifi/include/esp_wifi_types.h @@ -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 **/ diff --git a/components/esp_wifi/lib_esp32 b/components/esp_wifi/lib_esp32 index 09ed80c2b..00ed323d8 160000 --- a/components/esp_wifi/lib_esp32 +++ b/components/esp_wifi/lib_esp32 @@ -1 +1 @@ -Subproject commit 09ed80c2b047ae5bb41ddbfb9be44ec2bc71fedd +Subproject commit 00ed323d855e71eab0e7cbf114733de92bf0d6bb diff --git a/components/esp_wifi/test/test_wifi.c b/components/esp_wifi/test/test_wifi.c index 08996d9de..b3d950e08 100644 --- a/components/esp_wifi/test/test_wifi.c +++ b/components/esp_wifi/test/test_wifi.c @@ -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(); diff --git a/components/mdns/include/mdns.h b/components/mdns/include/mdns.h index a30534640..1ffa312c0 100644 --- a/components/mdns/include/mdns.h +++ b/components/mdns/include/mdns.h @@ -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 } diff --git a/components/mqtt/esp-mqtt b/components/mqtt/esp-mqtt index 117eef2da..fb3d2107c 160000 --- a/components/mqtt/esp-mqtt +++ b/components/mqtt/esp-mqtt @@ -1 +1 @@ -Subproject commit 117eef2dad54e0f9e25b3005fcfc18e7695ff29e +Subproject commit fb3d2107cdac440d84f2fab81ea9b5217aa4ba1f diff --git a/components/tcpip_adapter/event_handlers.c b/components/tcpip_adapter/event_handlers.c index 5e3717c56..6d2128e52 100644 --- a/components/tcpip_adapter/event_handlers.c +++ b/components/tcpip_adapter/event_handlers.c @@ -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, ð_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, ð_ip, sizeof(tcpip_adapter_ip_info_t)); - - esp_event_send(&evt); + evt.if_index = TCPIP_ADAPTER_IF_ETH; + memcpy(&evt.ip_info, ð_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"); } diff --git a/components/tcpip_adapter/tcpip_adapter_lwip.c b/components/tcpip_adapter/tcpip_adapter_lwip.c index 237b082a3..307babe3a 100644 --- a/components/tcpip_adapter/tcpip_adapter_lwip.c +++ b/components/tcpip_adapter/tcpip_adapter_lwip.c @@ -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; } - memcpy(&evt.event_info.got_ip.ip_info, ip_info, sizeof(tcpip_adapter_ip_info_t)); + if (tcpip_if == TCPIP_ADAPTER_IF_ETH) { + evt_id = IP_EVENT_ETH_GOT_IP; + } + + 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); } diff --git a/components/wifi_provisioning/include/wifi_provisioning/manager.h b/components/wifi_provisioning/include/wifi_provisioning/manager.h index 8f31aedba..2edd43fee 100644 --- a/components/wifi_provisioning/include/wifi_provisioning/manager.h +++ b/components/wifi_provisioning/include/wifi_provisioning/manager.h @@ -14,9 +14,9 @@ #pragma once -#include #include +#include "esp_event.h" #include "wifi_provisioning/wifi_config.h" #ifdef __cplusplus diff --git a/components/wifi_provisioning/src/wifi_provisioning_priv.h b/components/wifi_provisioning/src/wifi_provisioning_priv.h index 756e82f45..a607b49dc 100644 --- a/components/wifi_provisioning/src/wifi_provisioning_priv.h +++ b/components/wifi_provisioning/src/wifi_provisioning_priv.h @@ -14,8 +14,6 @@ #pragma once -#include - #include #include diff --git a/components/wpa_supplicant/src/esp_supplicant/esp_wifi_driver.h b/components/wpa_supplicant/src/esp_supplicant/esp_wifi_driver.h index 62d2d6246..820b71392 100644 --- a/components/wpa_supplicant/src/esp_supplicant/esp_wifi_driver.h +++ b/components/wpa_supplicant/src/esp_supplicant/esp_wifi_driver.h @@ -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); diff --git a/components/wpa_supplicant/src/esp_supplicant/esp_wps.c b/components/wpa_supplicant/src/esp_supplicant/esp_wps.c index cbcd35197..16f6f9965 100644 --- a/components/wpa_supplicant/src/esp_supplicant/esp_wps.c +++ b/components/wpa_supplicant/src/esp_supplicant/esp_wps.c @@ -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); diff --git a/examples/bluetooth/bluedroid/ble/ble_hid_device_demo/main/ble_hidd_demo_main.c b/examples/bluetooth/bluedroid/ble/ble_hid_device_demo/main/ble_hidd_demo_main.c index b7584735a..f7900d59b 100644 --- a/examples/bluetooth/bluedroid/ble/ble_hid_device_demo/main/ble_hidd_demo_main.c +++ b/examples/bluetooth/bluedroid/ble/ble_hid_device_demo/main/ble_hidd_demo_main.c @@ -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" diff --git a/examples/bluetooth/bluedroid/ble/blufi/main/blufi_example_main.c b/examples/bluetooth/bluedroid/ble/blufi/main/blufi_example_main.c index bd3b86e21..cf3e15330 100644 --- a/examples/bluetooth/bluedroid/ble/blufi/main/blufi_example_main.c +++ b/examples/bluetooth/bluedroid/ble/blufi/main/blufi_example_main.c @@ -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) ); diff --git a/examples/bluetooth/bluedroid/ble/blufi/main/blufi_security.c b/examples/bluetooth/bluedroid/ble/blufi/main/blufi_security.c index f790e58e5..635d5f00a 100644 --- a/examples/bluetooth/bluedroid/ble/blufi/main/blufi_security.c +++ b/examples/bluetooth/bluedroid/ble/blufi/main/blufi_security.c @@ -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" diff --git a/examples/bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist/components/iperf/cmd_wifi.c b/examples/bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist/components/iperf/cmd_wifi.c index 15ebcb21c..8fd95ce47 100644 --- a/examples/bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist/components/iperf/cmd_wifi.c +++ b/examples/bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist/components/iperf/cmd_wifi.c @@ -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 diff --git a/examples/ethernet/eth2ap/main/ethernet_example_main.c b/examples/ethernet/eth2ap/main/ethernet_example_main.c index 3b540fad0..b9b2193a2 100644 --- a/examples/ethernet/eth2ap/main/ethernet_example_main.c +++ b/examples/ethernet/eth2ap/main/ethernet_example_main.c @@ -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" diff --git a/examples/peripherals/spi_slave/receiver/main/app_main.c b/examples/peripherals/spi_slave/receiver/main/app_main.c index 0defcb4ec..cd01465d8 100644 --- a/examples/peripherals/spi_slave/receiver/main/app_main.c +++ b/examples/peripherals/spi_slave/receiver/main/app_main.c @@ -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" diff --git a/examples/peripherals/spi_slave/sender/main/app_main.c b/examples/peripherals/spi_slave/sender/main/app_main.c index a8bcc6e0b..c3a8007c7 100644 --- a/examples/peripherals/spi_slave/sender/main/app_main.c +++ b/examples/peripherals/spi_slave/sender/main/app_main.c @@ -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" diff --git a/examples/protocols/http_server/advanced_tests/main/main.c b/examples/protocols/http_server/advanced_tests/main/main.c index af9ae1a87..118a380a8 100644 --- a/examples/protocols/http_server/advanced_tests/main/main.c +++ b/examples/protocols/http_server/advanced_tests/main/main.c @@ -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" diff --git a/examples/protocols/http_server/file_serving/main/main.c b/examples/protocols/http_server/file_serving/main/main.c index 421355da3..4a6faf5a2 100644 --- a/examples/protocols/http_server/file_serving/main/main.c +++ b/examples/protocols/http_server/file_serving/main/main.c @@ -10,7 +10,7 @@ #include #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" diff --git a/examples/protocols/http_server/persistent_sockets/main/main.c b/examples/protocols/http_server/persistent_sockets/main/main.c index 725de62e1..8e6132b1e 100644 --- a/examples/protocols/http_server/persistent_sockets/main/main.c +++ b/examples/protocols/http_server/persistent_sockets/main/main.c @@ -8,7 +8,7 @@ */ #include -#include +#include #include #include #include diff --git a/examples/protocols/http_server/restful_server/main/esp_rest_main.c b/examples/protocols/http_server/restful_server/main/esp_rest_main.c index ee13bfa35..c82711ca4 100644 --- a/examples/protocols/http_server/restful_server/main/esp_rest_main.c +++ b/examples/protocols/http_server/restful_server/main/esp_rest_main.c @@ -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" diff --git a/examples/protocols/https_server/main/main.c b/examples/protocols/https_server/main/main.c index a71f44e59..6d6a36931 100644 --- a/examples/protocols/https_server/main/main.c +++ b/examples/protocols/https_server/main/main.c @@ -8,7 +8,7 @@ */ #include -#include +#include #include #include #include diff --git a/examples/protocols/websocket/main/websocket_example.c b/examples/protocols/websocket/main/websocket_example.c index 6b64ef25d..901d2ad92 100644 --- a/examples/protocols/websocket/main/websocket_example.c +++ b/examples/protocols/websocket/main/websocket_example.c @@ -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; diff --git a/examples/provisioning/ble_prov/main/app_prov.h b/examples/provisioning/ble_prov/main/app_prov.h index 97d5abaf9..64e4dbe3a 100644 --- a/examples/provisioning/ble_prov/main/app_prov.h +++ b/examples/provisioning/ble_prov/main/app_prov.h @@ -9,8 +9,6 @@ #pragma once -#include - #include #include diff --git a/examples/provisioning/console_prov/main/app_prov.h b/examples/provisioning/console_prov/main/app_prov.h index c6e026bc0..5e6d88474 100644 --- a/examples/provisioning/console_prov/main/app_prov.h +++ b/examples/provisioning/console_prov/main/app_prov.h @@ -9,8 +9,6 @@ #pragma once -#include - #include #include diff --git a/examples/provisioning/custom_config/main/app_prov.h b/examples/provisioning/custom_config/main/app_prov.h index b575100bf..be46b2945 100644 --- a/examples/provisioning/custom_config/main/app_prov.h +++ b/examples/provisioning/custom_config/main/app_prov.h @@ -9,7 +9,7 @@ #pragma once -#include +#include #include #include diff --git a/examples/provisioning/softap_prov/main/app_prov.h b/examples/provisioning/softap_prov/main/app_prov.h index 312d00e40..c87ff4f0b 100644 --- a/examples/provisioning/softap_prov/main/app_prov.h +++ b/examples/provisioning/softap_prov/main/app_prov.h @@ -9,7 +9,7 @@ #pragma once -#include +#include #include #include diff --git a/examples/system/esp_event/default_event_loop/main/event_source.h b/examples/system/esp_event/default_event_loop/main/event_source.h index 91ca4f10c..e9733a3df 100644 --- a/examples/system/esp_event/default_event_loop/main/event_source.h +++ b/examples/system/esp_event/default_event_loop/main/event_source.h @@ -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_ diff --git a/examples/system/esp_event/user_event_loops/main/event_source.h b/examples/system/esp_event/user_event_loops/main/event_source.h index 73a3b69c1..2e1787d8e 100644 --- a/examples/system/esp_event/user_event_loops/main/event_source.h +++ b/examples/system/esp_event/user_event_loops/main/event_source.h @@ -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_ diff --git a/examples/system/network_tests/main/net_suite.c b/examples/system/network_tests/main/net_suite.c index 9b9dfe2d0..dc8817357 100644 --- a/examples/system/network_tests/main/net_suite.c +++ b/examples/system/network_tests/main/net_suite.c @@ -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" diff --git a/examples/system/ota/advanced_https_ota/main/advanced_https_ota_example.c b/examples/system/ota/advanced_https_ota/main/advanced_https_ota_example.c index aafa48888..a207a9130 100644 --- a/examples/system/ota/advanced_https_ota/main/advanced_https_ota_example.c +++ b/examples/system/ota/advanced_https_ota/main/advanced_https_ota_example.c @@ -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" diff --git a/examples/system/ota/native_ota_example/main/native_ota_example.c b/examples/system/ota/native_ota_example/main/native_ota_example.c index 9d84cc07c..1c8ea033f 100644 --- a/examples/system/ota/native_ota_example/main/native_ota_example.c +++ b/examples/system/ota/native_ota_example/main/native_ota_example.c @@ -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" diff --git a/examples/system/ota/simple_ota_example/main/simple_ota_example.c b/examples/system/ota/simple_ota_example/main/simple_ota_example.c index 9d0187f3b..f85186e2b 100644 --- a/examples/system/ota/simple_ota_example/main/simple_ota_example.c +++ b/examples/system/ota/simple_ota_example/main/simple_ota_example.c @@ -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"