Why am I stuck in esp_event_loop_delete_default() function?
Posted: Mon Nov 15, 2021 10:27 am
I am working on my ESP32-S2 and I want to implement a Restserver. As a template I use the https "simple" example provided by the esp-idf. My ESP32 should try to connect to a local router with a hardcoded SSID and password. The ESP tries to connect to a router every 1-2 seconds. After 4 attempts I want the ESP to stop connecting to the Router and start and Accesspoint instead.
Now I'm facing some problems implementing this logic. After an unsuccessful connection try I'm calling my deinit_wifi function which looks like this:
I noticed, that my ESP gets stuck within the following line:
ESP_ERROR_CHECK(esp_event_loop_delete_default());
I started searching for the problem and looked in the definition and added some printf's to locate the line in which the function get stuck.
My last printed line was "I try to delete". So that means, my program stucks in this function:
err = esp_event_loop_delete(s_default_loop);
Anyone got and idea?
for completion here is my init function:
Now I'm facing some problems implementing this logic. After an unsuccessful connection try I'm calling my deinit_wifi function which looks like this:
Code: Select all
void deinit_wifi(void)
{
stop_webserver(mainserver);
#ifdef CONFIG_EXAMPLE_CONNECT_WIFI
ESP_ERROR_CHECK(esp_event_handler_unregister(IP_EVENT, IP_EVENT_STA_GOT_IP, &connect_handler));
ESP_ERROR_CHECK(esp_event_handler_unregister(WIFI_EVENT, WIFI_EVENT_STA_DISCONNECTED, &disconnect_handler));
#endif // CONFIG_EXAMPLE_CONNECT_WIFI
#ifdef CONFIG_EXAMPLE_CONNECT_ETHERNET
ESP_ERROR_CHECK(esp_event_handler_unregister(IP_EVENT, IP_EVENT_ETH_GOT_IP, &connect_handler));
ESP_ERROR_CHECK(esp_event_handler_unregister(ETH_EVENT, ETHERNET_EVENT_DISCONNECTED, &disconnect_handler));
#endif // CONFIG_EXAMPLE_CONNECT_ETHERNET
ESP_ERROR_CHECK(example_disconnect());
ESP_ERROR_CHECK(esp_event_loop_delete_default());
init_access_point();
}
ESP_ERROR_CHECK(esp_event_loop_delete_default());
I started searching for the problem and looked in the definition and added some printf's to locate the line in which the function get stuck.
Code: Select all
esp_err_t esp_event_loop_delete_default(void)
{
printf("\n I'm in function \n");
if (!s_default_loop) {
printf("\n Invalide state?! \n");
return ESP_ERR_INVALID_STATE;
}
esp_err_t err;
printf("\n I try to delete \n");
err = esp_event_loop_delete(s_default_loop);
printf("\n i just deleted \n");
if (err != ESP_OK) {
printf("\n s_default_loop is not null \n");
return err;
}
s_default_loop = NULL;
printf("\n s_default_loop is null now \n");
return ESP_OK;
}
My last printed line was "I try to delete". So that means, my program stucks in this function:
err = esp_event_loop_delete(s_default_loop);
Anyone got and idea?
for completion here is my init function:
Code: Select all
void init_Wifi(void)
{
ESP_ERROR_CHECK(nvs_flash_init());
ESP_ERROR_CHECK(esp_netif_init());
ESP_ERROR_CHECK(esp_event_loop_create_default());
/* Register event handlers to start server when Wi-Fi or Ethernet is connected,
* and stop server when disconnection happens.
*/
#ifdef CONFIG_EXAMPLE_CONNECT_WIFI
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &connect_handler, &mainserver));
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_STA_DISCONNECTED, &disconnect_handler, &mainserver));
#endif // CONFIG_EXAMPLE_CONNECT_WIFI
#ifdef CONFIG_EXAMPLE_CONNECT_ETHERNET
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, &connect_handler, &mainserver));
ESP_ERROR_CHECK(esp_event_handler_register(ETH_EVENT, ETHERNET_EVENT_DISCONNECTED, &disconnect_handler, &mainserver));
#endif // CONFIG_EXAMPLE_CONNECT_ETHERNET
/* This helper function configures Wi-Fi or Ethernet, as selected in menuconfig.
* Read "Establishing Wi-Fi or Ethernet Connection" section in
* examples/protocols/README.md for more information about this function.
*/
ESP_ERROR_CHECK(example_connect());
}