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());
}