You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I skipped esp_event_loop_create_default() because I didn't know why I need it at first. At a later point I found out why and added this call somewhere before esp_event_handler_instance_register() calls. This worked, I got the WIFI_EVENT_STA_CONNECTED event in my event handler (again, derived from the example), but I never got the IP_EVENT_STA_GOT_IP nor the device ever asked for IP (checked on my router). No runtime errors or warning logs were generated that would hint this being the problem.
I think this should result in an error of sorts. It's not obvious there is a tight coupling (or dependency) between these two methods and the example doesn't mention this tight coupling either. This was very difficult to troubleshoot for a beginner like me, I spent a couple of hours on this.
The reason for this call order requirement is because esp_netif_create_default_wifi_sta() calls esp_event_handler_register() which as a result relies on already existing event loop created by the user.
Also, the esp_netif_create_default_wifi_stadocumentation doesn't mention this requirement either.
/** * @brief User init default station (official API) */esp_netif_t*esp_netif_create_default_wifi_sta(void)
{
esp_netif_config_tcfg=ESP_NETIF_DEFAULT_WIFI_STA();
esp_netif_t*netif=esp_netif_new(&cfg);
assert(netif);
esp_netif_attach_wifi_station(netif);
esp_wifi_set_default_wifi_sta_handlers();
returnnetif;
}
The esp_wifi_set_default_wifi_sta_handlers() call internally returns errors but this function doesn't handle them in any way. I think even assert() as seen in assert(netif) would be better than this. Please don't ignore errors.
An alternative could be the esp_wifi_set_default_wifi_sta_handlers function would create its own event loop so it wouldn't depend on the user's event loop.
The text was updated successfully, but these errors were encountered:
github-actionsbot
changed the title
ESP32 gets no IP and returns no error if esp_netif_create_default_wifi_sta() called before esp_event_loop_create_default()
ESP32 gets no IP and returns no error if esp_netif_create_default_wifi_sta() called before esp_event_loop_create_default() (IDFGH-10321)
Jun 2, 2023
I am learning ESP32 and ESP-IDF. I was trying to make it connect to WiFi. I looked at the https://github.com/espressif/esp-idf/tree/master/examples/wifi/getting_started/station example and copied relevant method calls until things started working. In this code
I skipped
esp_event_loop_create_default()
because I didn't know why I need it at first. At a later point I found out why and added this call somewhere beforeesp_event_handler_instance_register()
calls. This worked, I got theWIFI_EVENT_STA_CONNECTED
event in my event handler (again, derived from the example), but I never got theIP_EVENT_STA_GOT_IP
nor the device ever asked for IP (checked on my router). No runtime errors or warning logs were generated that would hint this being the problem.I think this should result in an error of sorts. It's not obvious there is a tight coupling (or dependency) between these two methods and the example doesn't mention this tight coupling either. This was very difficult to troubleshoot for a beginner like me, I spent a couple of hours on this.
The reason for this call order requirement is because
esp_netif_create_default_wifi_sta()
callsesp_event_handler_register()
which as a result relies on already existing event loop created by the user.Also, the
esp_netif_create_default_wifi_sta
documentation doesn't mention this requirement either.The implementation looks like this:
The
esp_wifi_set_default_wifi_sta_handlers()
call internally returns errors but this function doesn't handle them in any way. I think evenassert()
as seen inassert(netif)
would be better than this. Please don't ignore errors.An alternative could be the
esp_wifi_set_default_wifi_sta_handlers
function would create its own event loop so it wouldn't depend on the user's event loop.The text was updated successfully, but these errors were encountered: