From 1cf23127347a34dee8d4ed7b3a521002e2bdb96e Mon Sep 17 00:00:00 2001 From: Jakob Hasse Date: Tue, 10 Mar 2020 17:23:03 +0800 Subject: [PATCH] Examples: some examples use new event register API * getting started - station * softap * iperf * fast scan * Power save --- .../esp_event/default_event_loop/README.md | 89 ++++++++++--------- .../default_event_loop/example_test.py | 4 +- .../esp_event/default_event_loop/main/main.c | 36 +++++--- .../esp_event/user_event_loops/README.md | 4 +- .../esp_event/user_event_loops/main/main.c | 6 +- examples/wifi/fast_scan/main/fast_scan.c | 6 +- .../softAP/main/softap_example_main.c | 6 +- .../station/main/station_example_main.c | 18 +++- examples/wifi/iperf/main/cmd_wifi.c | 26 ++++-- examples/wifi/power_save/main/power_save.c | 4 +- 10 files changed, 123 insertions(+), 76 deletions(-) diff --git a/examples/system/esp_event/default_event_loop/README.md b/examples/system/esp_event/default_event_loop/README.md index ad3042e37..a3e6060f8 100644 --- a/examples/system/esp_event/default_event_loop/README.md +++ b/examples/system/esp_event/default_event_loop/README.md @@ -20,7 +20,7 @@ Simply put, posting an event to a loop is the act of queueing its handlers for e ### Handler Registration/Unregistration -This example demonstrates handler registration to the default event loop using `esp_event_handler_register` for (1) specific events, (2) **any** event under a certain base, and (3) **any** event. This also shows the possbility of registering multiple handlers to the same event. +This example demonstrates handler registration to the default event loop using `esp_event_handler_register` for (1) specific events, (2) **any** event under a certain base, and (3) **any** event. This also shows the possbility of registering multiple handlers to the same event as well as registering one handler to the same event multiple times. Unregistering a handler is done using `esp_event_handler_unregister()`. Unregistering a handler means that it no longer executes even when the event it was previously registered to gets posted to the loop. @@ -55,44 +55,46 @@ See the Getting Started Guide for full steps to configure and use ESP-IDF to bui The example should have the following log output: ``` -I (276) default_event_loop: setting up -I (276) default_event_loop: starting event sources -I (276) default_event_loop: TIMER_EVENTS:TIMER_EVENT_STARTED: posting to default loop -I (276) default_event_loop: TASK_EVENTS:TASK_ITERATION_EVENT: posting to default loop, 1 out of 5 -I (296) default_event_loop: TIMER_EVENTS:TIMER_EVENT_STARTED: timer_started_handler -I (306) default_event_loop: TIMER_EVENTS:TIMER_EVENT_STARTED: timer_any_handler -I (316) default_event_loop: TIMER_EVENTS:TIMER_EVENT_STARTED: all_event_handler -I (326) default_event_loop: TASK_EVENTS:TASK_ITERATION_EVENT: task_iteration_handler, executed 1 times -I (336) default_event_loop: TASK_EVENTS:TASK_ITERATION_EVENT: all_event_handler -I (806) default_event_loop: TASK_EVENTS:TASK_ITERATION_EVENT: posting to default loop, 2 out of 5 -I (806) default_event_loop: TASK_EVENTS:TASK_ITERATION_EVENT: task_iteration_handler, executed 2 times -I (806) default_event_loop: TASK_EVENTS:TASK_ITERATION_EVENT: all_event_handler -I (1276) default_event_loop: TIMER_EVENTS:TIMER_EVENT_EXPIRY: posting to default loop -I (1276) default_event_loop: TIMER_EVENTS:TIMER_EVENT_EXPIRY: timer_expiry_handler, executed 1 out of 3 times -I (1286) default_event_loop: TIMER_EVENTS:TIMER_EVENT_EXPIRY: timer_any_handler -I (1296) default_event_loop: TIMER_EVENTS:TIMER_EVENT_EXPIRY: all_event_handler -I (1306) default_event_loop: TASK_EVENTS:TASK_ITERATION_EVENT: posting to default loop, 3 out of 5 -I (1316) default_event_loop: TASK_EVENTS:TASK_ITERATION_EVENT: unregistering task_iteration_handler -I (1316) default_event_loop: TASK_EVENTS:TASK_ITERATION_EVENT: task_iteration_handler, executed 3 times -I (1336) default_event_loop: TASK_EVENTS:TASK_ITERATION_EVENT: all_event_handler -I (1846) default_event_loop: TASK_EVENTS:TASK_ITERATION_EVENT: posting to default loop, 4 out of 5 -I (1846) default_event_loop: TASK_EVENTS:TASK_ITERATION_EVENT: all_event_handler -I (2276) default_event_loop: TIMER_EVENTS:TIMER_EVENT_EXPIRY: posting to default loop -I (2276) default_event_loop: TIMER_EVENTS:TIMER_EVENT_EXPIRY: timer_expiry_handler, executed 2 out of 3 times -I (2286) default_event_loop: TIMER_EVENTS:TIMER_EVENT_EXPIRY: timer_any_handler -I (2296) default_event_loop: TIMER_EVENTS:TIMER_EVENT_EXPIRY: all_event_handler -I (2346) default_event_loop: TASK_EVENTS:TASK_ITERATION_EVENT: posting to default loop, 5 out of 5 -I (2346) default_event_loop: TASK_EVENTS:TASK_ITERATION_EVENT: all_event_handler -I (3276) default_event_loop: TIMER_EVENTS:TIMER_EVENT_EXPIRY: posting to default loop -I (3276) default_event_loop: TIMER_EVENTS:TIMER_EVENT_STOPPED: posting to default loop -I (3286) default_event_loop: TIMER_EVENTS:TIMER_EVENT_EXPIRY: timer_expiry_handler, executed 3 out of 3 times -I (3296) default_event_loop: TIMER_EVENTS:TIMER_EVENT_EXPIRY: timer_any_handler -I (3306) default_event_loop: TIMER_EVENTS:TIMER_EVENT_EXPIRY: all_event_handler -I (3316) default_event_loop: TIMER_EVENTS:TIMER_EVENT_STOPPED: timer_stopped_handler -I (3326) default_event_loop: TIMER_EVENTS:TIMER_EVENT_STOPPED: deleted timer event source -I (3326) default_event_loop: TIMER_EVENTS:TIMER_EVENT_STOPPED: timer_any_handler -I (3336) default_event_loop: TIMER_EVENTS:TIMER_EVENT_STOPPED: all_event_handler -I (3346) default_event_loop: TASK_EVENTS:TASK_ITERATION_EVENT: deleting task event source +I (328) default_event_loop: setting up +I (338) default_event_loop: starting event sources +I (338) default_event_loop: TIMER_EVENTS:TIMER_EVENT_STARTED: posting to default loop +I (338) default_event_loop: TASK_EVENTS:TASK_ITERATION_EVENT: posting to default loop, 1 out of 5 +I (358) default_event_loop: TIMER_EVENTS:TIMER_EVENT_STARTED: timer_started_handler, instance 0 +I (368) default_event_loop: TIMER_EVENTS:TIMER_EVENT_STARTED: timer_started_handler, instance 1 +I (378) default_event_loop: TIMER_EVENTS:TIMER_EVENT_STARTED: timer_started_handler_2 +I (388) default_event_loop: TIMER_EVENTS:TIMER_EVENT_STARTED: timer_any_handler +I (388) default_event_loop: TIMER_EVENTS:TIMER_EVENT_STARTED: all_event_handler +I (398) default_event_loop: TASK_EVENTS:TASK_ITERATION_EVENT: task_iteration_handler, executed 1 times +I (408) default_event_loop: TASK_EVENTS:TASK_ITERATION_EVENT: all_event_handler +I (858) default_event_loop: TASK_EVENTS:TASK_ITERATION_EVENT: posting to default loop, 2 out of 5 +I (858) default_event_loop: TASK_EVENTS:TASK_ITERATION_EVENT: task_iteration_handler, executed 2 times +I (858) default_event_loop: TASK_EVENTS:TASK_ITERATION_EVENT: all_event_handler +I (1338) default_event_loop: TIMER_EVENTS:TIMER_EVENT_EXPIRY: posting to default loop +I (1338) default_event_loop: TIMER_EVENTS:TIMER_EVENT_EXPIRY: timer_expiry_handler, executed 1 out of 3 times +I (1348) default_event_loop: TIMER_EVENTS:TIMER_EVENT_EXPIRY: timer_any_handler +I (1358) default_event_loop: TIMER_EVENTS:TIMER_EVENT_EXPIRY: all_event_handler +I (1358) default_event_loop: TASK_EVENTS:TASK_ITERATION_EVENT: posting to default loop, 3 out of 5 +I (1368) default_event_loop: TASK_EVENTS:TASK_ITERATION_EVENT: unregistering task_iteration_handler +I (1368) default_event_loop: TASK_EVENTS:TASK_ITERATION_EVENT: task_iteration_handler, executed 3 times +I (1388) default_event_loop: TASK_EVENTS:TASK_ITERATION_EVENT: all_event_handler +I (1898) default_event_loop: TASK_EVENTS:TASK_ITERATION_EVENT: posting to default loop, 4 out of 5 +I (1898) default_event_loop: TASK_EVENTS:TASK_ITERATION_EVENT: all_event_handler +I (2338) default_event_loop: TIMER_EVENTS:TIMER_EVENT_EXPIRY: posting to default loop +I (2338) default_event_loop: TIMER_EVENTS:TIMER_EVENT_EXPIRY: timer_expiry_handler, executed 2 out of 3 times +I (2348) default_event_loop: TIMER_EVENTS:TIMER_EVENT_EXPIRY: timer_any_handler +I (2358) default_event_loop: TIMER_EVENTS:TIMER_EVENT_EXPIRY: all_event_handler +I (2398) default_event_loop: TASK_EVENTS:TASK_ITERATION_EVENT: posting to default loop, 5 out of 5 +I (2398) default_event_loop: TASK_EVENTS:TASK_ITERATION_EVENT: all_event_handler +I (3338) default_event_loop: TIMER_EVENTS:TIMER_EVENT_EXPIRY: posting to default loop +I (3338) default_event_loop: TIMER_EVENTS:TIMER_EVENT_STOPPED: posting to default loop +I (3348) default_event_loop: TIMER_EVENTS:TIMER_EVENT_EXPIRY: timer_expiry_handler, executed 3 out of 3 times +I (3358) default_event_loop: TIMER_EVENTS:TIMER_EVENT_EXPIRY: timer_any_handler +I (3358) default_event_loop: TIMER_EVENTS:TIMER_EVENT_EXPIRY: all_event_handler +I (3368) default_event_loop: TIMER_EVENTS:TIMER_EVENT_STOPPED: timer_stopped_handler +I (3378) default_event_loop: TIMER_EVENTS:TIMER_EVENT_STOPPED: deleted timer event source +I (3388) default_event_loop: TIMER_EVENTS:TIMER_EVENT_STOPPED: timer_any_handler +I (3398) default_event_loop: TIMER_EVENTS:TIMER_EVENT_STOPPED: all_event_handler +I (3398) default_event_loop: TASK_EVENTS:TASK_ITERATION_EVENT: deleting task event source ``` ## Example Breakdown @@ -135,14 +137,17 @@ The two event sources are started. The respective events are posted to the defau #### 3. Execution of handlers ``` -I (296) default_event_loop: TIMER_EVENTS:TIMER_EVENT_STARTED: timer_started_handler +I (358) default_event_loop: TIMER_EVENTS:TIMER_EVENT_STARTED: timer_started_handler, instance 0 +I (368) default_event_loop: TIMER_EVENTS:TIMER_EVENT_STARTED: timer_started_handler, instance 1 +I (378) default_event_loop: TIMER_EVENTS:TIMER_EVENT_STARTED: timer_started_handler_2 I (306) default_event_loop: TIMER_EVENTS:TIMER_EVENT_STARTED: timer_any_handler I (316) default_event_loop: TIMER_EVENTS:TIMER_EVENT_STARTED: all_event_handler ... I (326) default_event_loop: TASK_EVENTS:TASK_ITERATION_EVENT: task_iteration_handler, executed 1 times I (336) default_event_loop: TASK_EVENTS:TASK_ITERATION_EVENT: all_event_handler ``` -The handlers are executed for the events that were posted in **(2)**. In addition to the event-specific handlers `timer_started_handler()` and `task_iteration_handler()`, the `timer_any_handler()` and `all_event_handler()` are also executed. +The handlers are executed for the events that were posted in **(2)**. Note how `timer_started_handler()` is called twice on the same event post. This shows the ability to register a single event handler to a single event multiple times. Note also how `timer_started_handler_2()` is called on the same event post. This shows that multiple handlers can be registered to a single event. +In addition to the event-specific handlers `timer_started_handler()` (registered twice), `timer_started_handler_2()` and `task_iteration_handler()`, the `timer_any_handler()` and `all_event_handler()` are also executed. The `timer_any_handler()` executes for **any** timer event. It can be seen executing for the timer expiry and timer stopped events in the subsequent parts of the log. @@ -187,4 +192,4 @@ When the periodic timer expiry limit is reached, the event ``TIMER_EVENTS:TIMER_ I (3346) default_event_loop: TASK_EVENTS:TASK_ITERATION_EVENT: deleting task event source ... ``` -The task containing the loop that posts iteration events also gets deleted. The example ends at this point. \ No newline at end of file +The task containing the loop that posts iteration events also gets deleted. The example ends at this point. diff --git a/examples/system/esp_event/default_event_loop/example_test.py b/examples/system/esp_event/default_event_loop/example_test.py index 43a534451..f25741827 100644 --- a/examples/system/esp_event/default_event_loop/example_test.py +++ b/examples/system/esp_event/default_event_loop/example_test.py @@ -27,7 +27,9 @@ def _test_timer_events(dut): dut.expect("TIMER_EVENTS:TIMER_EVENT_STARTED: posting to default loop") print("Posted timer started event") - dut.expect("TIMER_EVENTS:TIMER_EVENT_STARTED: timer_started_handler") + dut.expect("TIMER_EVENTS:TIMER_EVENT_STARTED: timer_started_handler, instance 0") + dut.expect("TIMER_EVENTS:TIMER_EVENT_STARTED: timer_started_handler, instance 1") + dut.expect("TIMER_EVENTS:TIMER_EVENT_STARTED: timer_started_handler_2") dut.expect("TIMER_EVENTS:TIMER_EVENT_STARTED: timer_any_handler") dut.expect("TIMER_EVENTS:TIMER_EVENT_STARTED: all_event_handler") print("Handled timer started event") diff --git a/examples/system/esp_event/default_event_loop/main/main.c b/examples/system/esp_event/default_event_loop/main/main.c index 0564be641..456414032 100644 --- a/examples/system/esp_event/default_event_loop/main/main.c +++ b/examples/system/esp_event/default_event_loop/main/main.c @@ -16,6 +16,11 @@ static const char* TAG = "default_event_loop"; +static esp_event_handler_instance_t s_instance; + +static int TIMER_START_HANDLER_0 = 0; +static int TIMER_START_HANDLER_1 = 1; + static char* get_id_string(esp_event_base_t base, int32_t id) { char* event = ""; if (base == TIMER_EVENTS) { @@ -52,7 +57,14 @@ static void timer_callback(void* arg) // Handler which executes when the timer started event gets executed by the loop. static void timer_started_handler(void* handler_args, esp_event_base_t base, int32_t id, void* event_data) { - ESP_LOGI(TAG, "%s:%s: timer_started_handler", base, get_id_string(base, id)); + int start_handler_num = *((int*) handler_args); + ESP_LOGI(TAG, "%s:%s: timer_started_handler, instance %d", base, get_id_string(base, id), start_handler_num); +} + +// Second handler which executes when the timer started event gets executed by the loop. +static void timer_started_handler_2(void* handler_args, esp_event_base_t base, int32_t id, void* event_data) +{ + ESP_LOGI(TAG, "%s:%s: timer_started_handler_2", base, get_id_string(base, id)); } // Handler which executes when the timer expiry event gets executed by the loop. This handler keeps track of @@ -117,7 +129,7 @@ static void task_event_source(void* args) if (iteration == TASK_ITERATIONS_UNREGISTER) { ESP_LOGI(TAG, "%s:%s: unregistering task_iteration_handler", TASK_EVENTS, get_id_string(TASK_EVENTS, TASK_ITERATION_EVENT)); - ESP_ERROR_CHECK(esp_event_handler_unregister(TASK_EVENTS, TASK_ITERATION_EVENT, task_iteration_handler)); + ESP_ERROR_CHECK(esp_event_handler_instance_unregister(TASK_EVENTS, TASK_ITERATION_EVENT, s_instance)); } vTaskDelay(pdMS_TO_TICKS(TASK_PERIOD)); @@ -144,20 +156,22 @@ void app_main(void) // Create the default event loop ESP_ERROR_CHECK(esp_event_loop_create_default()); - // Register the specific timer event handlers. - ESP_ERROR_CHECK(esp_event_handler_register(TIMER_EVENTS, TIMER_EVENT_STARTED, timer_started_handler, NULL)); - ESP_ERROR_CHECK(esp_event_handler_register(TIMER_EVENTS, TIMER_EVENT_EXPIRY, timer_expiry_handler, NULL)); - ESP_ERROR_CHECK(esp_event_handler_register(TIMER_EVENTS, TIMER_EVENT_STOPPED, timer_stopped_handler, NULL)); + // Register the specific timer event handlers. Timer start handler is registered twice. + ESP_ERROR_CHECK(esp_event_handler_instance_register(TIMER_EVENTS, TIMER_EVENT_STARTED, timer_started_handler, &TIMER_START_HANDLER_0, NULL)); + ESP_ERROR_CHECK(esp_event_handler_instance_register(TIMER_EVENTS, TIMER_EVENT_STARTED, timer_started_handler, &TIMER_START_HANDLER_1, NULL)); + ESP_ERROR_CHECK(esp_event_handler_instance_register(TIMER_EVENTS, TIMER_EVENT_STARTED, timer_started_handler_2, NULL, NULL)); + ESP_ERROR_CHECK(esp_event_handler_instance_register(TIMER_EVENTS, TIMER_EVENT_EXPIRY, timer_expiry_handler, NULL, NULL)); + ESP_ERROR_CHECK(esp_event_handler_instance_register(TIMER_EVENTS, TIMER_EVENT_STOPPED, timer_stopped_handler, NULL, NULL)); // Register the handler for all timer family events. This will execute if the timer is started, expired or is stopped. - ESP_ERROR_CHECK(esp_event_handler_register(TIMER_EVENTS, ESP_EVENT_ANY_ID, timer_any_handler, NULL)); + ESP_ERROR_CHECK(esp_event_handler_instance_register(TIMER_EVENTS, ESP_EVENT_ANY_ID, timer_any_handler, NULL, NULL)); - // Register the handler for task iteration event. - ESP_ERROR_CHECK(esp_event_handler_register(TASK_EVENTS, TASK_ITERATION_EVENT, task_iteration_handler, NULL)); + // Register the handler for task iteration event; need to pass instance handle for later unregistration. + ESP_ERROR_CHECK(esp_event_handler_instance_register(TASK_EVENTS, TASK_ITERATION_EVENT, task_iteration_handler, NULL, &s_instance)); // Register the handler for all event. This will execute if either the timer events or the task iteration event // is posted to the default loop. - ESP_ERROR_CHECK(esp_event_handler_register(ESP_EVENT_ANY_BASE, ESP_EVENT_ANY_ID, all_event_handler, NULL)); + ESP_ERROR_CHECK(esp_event_handler_instance_register(ESP_EVENT_ANY_BASE, ESP_EVENT_ANY_ID, all_event_handler, NULL, NULL)); // Create and start the event sources esp_timer_create_args_t timer_args = { @@ -176,4 +190,4 @@ void app_main(void) // Post the timer started event ESP_LOGI(TAG, "%s:%s: posting to default loop", TIMER_EVENTS, get_id_string(TIMER_EVENTS, TIMER_EVENT_STARTED)); ESP_ERROR_CHECK(esp_event_post(TIMER_EVENTS, TIMER_EVENT_STARTED, NULL, 0, portMAX_DELAY)); -} \ No newline at end of file +} diff --git a/examples/system/esp_event/user_event_loops/README.md b/examples/system/esp_event/user_event_loops/README.md index 752630cad..18fb719c6 100644 --- a/examples/system/esp_event/user_event_loops/README.md +++ b/examples/system/esp_event/user_event_loops/README.md @@ -16,7 +16,7 @@ Depending on the parameters, the user can create either a loop with a dedicated ### Handler Registration/Unregistration, -Handler registration and unregistration works the same way as the default event loop, just with a different API, `esp_event_handler_register_with()` and `esp_event_handler_register_with()` respectively. There are two things this example highlights: +Handler registration and unregistration works the same way as the default event loop, just with a different API, `esp_event_handler_instance_register_with()` and `esp_event_handler_instance_unregister_with()` respectively. There are two things this example highlights: 1. The possibility of registering the same handler for different loops 2. The ability to pass static data to handlers. @@ -140,4 +140,4 @@ I (9126) user_event_loops: application_task: running application task ... ``` -The last of the iteration event is posted, and the event source is deleted. Because the loop without the task no longer receive events to execute, only the application task code executes. \ No newline at end of file +The last of the iteration event is posted, and the event source is deleted. Because the loop without the task no longer receive events to execute, only the application task code executes. diff --git a/examples/system/esp_event/user_event_loops/main/main.c b/examples/system/esp_event/user_event_loops/main/main.c index b47fed581..ec6b67062 100644 --- a/examples/system/esp_event/user_event_loops/main/main.c +++ b/examples/system/esp_event/user_event_loops/main/main.c @@ -109,8 +109,8 @@ void app_main(void) // Register the handler for task iteration event. Notice that the same handler is used for handling event on different loops. // The loop handle is provided as an argument in order for this example to display the loop the handler is being run on. - ESP_ERROR_CHECK(esp_event_handler_register_with(loop_with_task, TASK_EVENTS, TASK_ITERATION_EVENT, task_iteration_handler, loop_with_task)); - ESP_ERROR_CHECK(esp_event_handler_register_with(loop_without_task, TASK_EVENTS, TASK_ITERATION_EVENT, task_iteration_handler, loop_without_task)); + ESP_ERROR_CHECK(esp_event_handler_instance_register_with(loop_with_task, TASK_EVENTS, TASK_ITERATION_EVENT, task_iteration_handler, loop_with_task, NULL)); + ESP_ERROR_CHECK(esp_event_handler_instance_register_with(loop_without_task, TASK_EVENTS, TASK_ITERATION_EVENT, task_iteration_handler, loop_without_task, NULL)); ESP_LOGI(TAG, "starting event source"); @@ -120,4 +120,4 @@ void app_main(void) ESP_LOGI(TAG, "starting application task"); // Create the application task with the same priority as the current task xTaskCreate(application_task, "application_task", 2048, NULL, uxTaskPriorityGet(NULL), NULL); -} \ No newline at end of file +} diff --git a/examples/wifi/fast_scan/main/fast_scan.c b/examples/wifi/fast_scan/main/fast_scan.c index 4818dea5a..0fa7a5cbf 100644 --- a/examples/wifi/fast_scan/main/fast_scan.c +++ b/examples/wifi/fast_scan/main/fast_scan.c @@ -68,7 +68,7 @@ static const char *TAG = "scan"; -static void event_handler(void* arg, esp_event_base_t event_base, +static void event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) { if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) { @@ -91,8 +91,8 @@ static void fast_scan(void) wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); ESP_ERROR_CHECK(esp_wifi_init(&cfg)); - ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL)); - ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL)); + ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL, NULL)); + ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL, NULL)); // Initialize default station as network interface instance (esp-netif) esp_netif_t *sta_netif = esp_netif_create_default_wifi_sta(); diff --git a/examples/wifi/getting_started/softAP/main/softap_example_main.c b/examples/wifi/getting_started/softAP/main/softap_example_main.c index 8e7b747d0..f43249e13 100644 --- a/examples/wifi/getting_started/softAP/main/softap_example_main.c +++ b/examples/wifi/getting_started/softAP/main/softap_example_main.c @@ -52,7 +52,11 @@ void wifi_init_softap(void) wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); ESP_ERROR_CHECK(esp_wifi_init(&cfg)); - ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &wifi_event_handler, NULL)); + ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT, + ESP_EVENT_ANY_ID, + &wifi_event_handler, + NULL, + NULL)); wifi_config_t wifi_config = { .ap = { diff --git a/examples/wifi/getting_started/station/main/station_example_main.c b/examples/wifi/getting_started/station/main/station_example_main.c index ff3420804..e4e030dbc 100644 --- a/examples/wifi/getting_started/station/main/station_example_main.c +++ b/examples/wifi/getting_started/station/main/station_example_main.c @@ -75,8 +75,18 @@ void wifi_init_sta(void) wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); ESP_ERROR_CHECK(esp_wifi_init(&cfg)); - ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL)); - ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL)); + esp_event_handler_instance_t instance_any_id; + esp_event_handler_instance_t instance_got_ip; + ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT, + ESP_EVENT_ANY_ID, + &event_handler, + NULL, + &instance_any_id)); + ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT, + IP_EVENT_STA_GOT_IP, + &event_handler, + NULL, + &instance_got_ip)); wifi_config_t wifi_config = { .sta = { @@ -110,8 +120,8 @@ void wifi_init_sta(void) ESP_LOGE(TAG, "UNEXPECTED EVENT"); } - ESP_ERROR_CHECK(esp_event_handler_unregister(IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler)); - ESP_ERROR_CHECK(esp_event_handler_unregister(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler)); + ESP_ERROR_CHECK(esp_event_handler_instance_unregister(IP_EVENT, IP_EVENT_STA_GOT_IP, instance_any_id)); + ESP_ERROR_CHECK(esp_event_handler_instance_unregister(WIFI_EVENT, ESP_EVENT_ANY_ID, instance_got_ip)); vEventGroupDelete(s_wifi_event_group); } diff --git a/examples/wifi/iperf/main/cmd_wifi.c b/examples/wifi/iperf/main/cmd_wifi.c index 128fe4703..766163324 100644 --- a/examples/wifi/iperf/main/cmd_wifi.c +++ b/examples/wifi/iperf/main/cmd_wifi.c @@ -116,13 +116,25 @@ void initialise_wifi(void) netif_sta = esp_netif_create_default_wifi_sta(); assert(netif_sta); wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); - ESP_ERROR_CHECK( esp_wifi_init(&cfg) ); - ESP_ERROR_CHECK( esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_SCAN_DONE, &scan_done_handler, NULL) ); - ESP_ERROR_CHECK( esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_STA_DISCONNECTED, &disconnect_handler, NULL) ); - ESP_ERROR_CHECK( esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &got_ip_handler, NULL) ); - ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) ); - ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_NULL) ); - ESP_ERROR_CHECK( esp_wifi_start() ); + ESP_ERROR_CHECK(esp_wifi_init(&cfg)); + ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT, + WIFI_EVENT_SCAN_DONE, + &scan_done_handler, + NULL, + NULL)); + ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT, + WIFI_EVENT_STA_DISCONNECTED, + &disconnect_handler, + NULL, + NULL)); + ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT, + IP_EVENT_STA_GOT_IP, + &got_ip_handler, + NULL, + NULL)); + ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM) ); + ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_NULL) ); + ESP_ERROR_CHECK(esp_wifi_start() ); initialized = true; } diff --git a/examples/wifi/power_save/main/power_save.c b/examples/wifi/power_save/main/power_save.c index ac8f8bbfa..bf8456de4 100644 --- a/examples/wifi/power_save/main/power_save.c +++ b/examples/wifi/power_save/main/power_save.c @@ -63,8 +63,8 @@ static void wifi_power_save(void) wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); ESP_ERROR_CHECK(esp_wifi_init(&cfg)); - ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL)); - ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL)); + ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL, NULL)); + ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL, NULL)); wifi_config_t wifi_config = { .sta = {