I call esp_netif_init() once, at startup.
Then I start up wifi using code similar to this simplified pseudocode:
Code: Select all
_espNetif = esp_netif_create_default_wifi_[ap|station]();
esp_wifi_init();
esp_wifi_set_mode();
esp_wifi_set_config();
esp_wifi_start();
Code: Select all
esp_wifi_stop();
esp_wifi_deinit();
esp_netif_destroy(_espNetif);
It works great the first time, but subsequent starts fail as soon as any wifi traffic occurs. In the code as shown, it's a crash:
Code: Select all
Guru Meditation Error: Core 0 panic'ed (InstructionFetchError). Exception was unhandled.
So what am I missing?
Solution: Add a call to esp_wifi_clear_default_wifi_driver_and_handlers() in the teardown sequence, e.g.,
Code: Select all
esp_wifi_stop();
esp_wifi_deinit();
esp_wifi_clear_default_wifi_driver_and_handlers(_espNetif); // <-add this!
esp_netif_destroy(_espNetif);