ESP-ADF: Connecting to WiFi but not acquiring IP via DHCP

zaphodb
Posts: 2
Joined: Sun Dec 13, 2020 11:50 am

ESP-ADF: Connecting to WiFi but not acquiring IP via DHCP

Postby zaphodb » Sun Dec 13, 2020 12:23 pm

Hello,

I want to use a LyraT board and ESP-ADF to create a Wifi Internet Radio.

When i run the ADF examples like "pipeline_living_stream" my board successfully connects to my Wifi AP (I can see it has associated) but (although I understand this is the default behaviour) it does not acquire an IP address via DHCP. Instead I get a warning about an unhandled WiFi event.

When I run the IDF "components/wifi/getting_started/station" example the board associates with my Wifi AP and successfully acquires an IP address via DHCP.

The AP is accepting both WPA2-PSK and WPA3.

--> Any hints what I am doing wrong here? (and this is my first ADF project, so apologies if this is an obvious question).

zaphodb

ESP-ADF version: v2.2-27-g93d257d
ESP-IDF version: V4.2
Board: Lyra-T 4.3

Console Output "pipeline_living_stream" example (not working):
-------------- snip --------------
I (1537) wifi:mode : sta (ac:67:b2:6f:9c:5c)
I (2857) wifi:new:<11,0>, old:<1,0>, ap:<255,255>, sta:<11,0>, prof:1
I (3487) wifi:state: init -> auth (b0)
I (3497) wifi:state: auth -> assoc (0)
I (3497) wifi:state: assoc -> run (10)
I (3527) wifi:connected with Test, aid = 1, channel 11, BW20, bssid = 38:10:d5:b9:b0:d9
I (3527) wifi:security: WPA2-PSK, phy: bgn, rssi: -64
I (3527) wifi:pm start, type: 1

W (3527) PERIPH_WIFI: WiFi Event cb, Unhandle event_base:WIFI_EVENT, event_id:4
I (3657) wifi:AP's beacon interval = 102400 us, DTIM period = 1
-------------- snip --------------

Console Output ESP-IDF "station" example (working):
-------------- snip --------------
I (1646) wifi:new:<11,0>, old:<1,0>, ap:<255,255>, sta:<11,0>, prof:1
I (1646) wifi:state: init -> auth (b0)
I (4116) wifi:state: auth -> assoc (0)
I (4126) wifi:state: assoc -> run (10)
I (4166) wifi:connected with Test, aid = 1, channel 11, BW20, bssid = 38:10:d5:b9:b0:d9
I (4166) wifi:security: WPA3-SAE, phy: bgn, rssi: -56
I (4176) wifi:pm start, type: 1

I (4176) wifi:AP's beacon interval = 102400 us, DTIM period = 1
I (5076) esp_netif_handlers: sta ip: 192.168.1.122, mask: 255.255.255.0, gw: 192.168.1.1
I (5076) wifi station: got ip:192.168.1.122
I (5076) wifi station: connected to ap SSID:Test password:*********
-------------- snip --------------

cyberslug
Posts: 3
Joined: Wed Dec 16, 2020 12:03 pm

Re: ESP-ADF: Connecting to WiFi but not acquiring IP via DHCP

Postby cyberslug » Wed Dec 16, 2020 12:26 pm

Thanks for posting this query @zaphodb

I have exactly the same experience with two examples from the adf example set "play_http_select_decoder" and "play_http_mp3".

My output is identical to yours. After some investigation it seems that execution halts in function "periph_wifi_wait_for_connected" (found in periph_wifi.c) doing exactly what the function title suggests - waiting for the CONNECTED_BIT to be set. When I look at the access point status I can see that the LyraT board is connected but does not have an IP address.

I have no problems when running the examples from the idf which connect via wifi in order to return some http data. (the http_request example for instance). When looking at this example the approach seems quite different and it uses the esp_wifi code rather than the periph_wifi code for connection.

In case it is relevant my access point is a Ubiquiti AC Pro.

Does anyone have any insights they can share?

zaphodb
Posts: 2
Joined: Sun Dec 13, 2020 11:50 am

Re: ESP-ADF: Connecting to WiFi but not acquiring IP via DHCP

Postby zaphodb » Sat Dec 19, 2020 2:26 pm

Hi cyberslug,

I got it "working".

If you add a call to "tcpip_adapter_init()" as shown below in file "play_http_mp3_example.c" it will work. tcpip_adapter_init() will set the flag "s_tcpip_adapter_compat" to true, and as a result the function "tcpip_adapter_set_default_wifi_handlers()" will register the STATION_START event handler. This event handler starts the DHCP client, It is called when your client has associated with the access point.

--> Not sure if this is the proper way to do it (tcpip_adapter_init() is deprecated) but it works for me.

zaphodb

----- snip ------
esp_periph_config_t periph_cfg = DEFAULT_ESP_PERIPH_SET_CONFIG();
esp_periph_set_handle_t set = esp_periph_set_init(&periph_cfg);
periph_wifi_cfg_t wifi_cfg = {
.ssid = CONFIG_WIFI_SSID,
.password = CONFIG_WIFI_PASSWORD,
};
tcpip_adapter_init(); // <----- ADD THIS LINE
esp_periph_handle_t wifi_handle = periph_wifi_init(&wifi_cfg);
esp_periph_start(set, wifi_handle);
periph_wifi_wait_for_connected(wifi_handle, portMAX_DELAY);
----- snip ------

cyberslug
Posts: 3
Joined: Wed Dec 16, 2020 12:03 pm

Re: ESP-ADF: Connecting to WiFi but not acquiring IP via DHCP

Postby cyberslug » Mon Dec 21, 2020 3:16 am

Thanks @zaphodb,

following your solution below lead me to this bit of code in app_main

----- snip ------
#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 1, 0))
ESP_ERROR_CHECK(esp_netif_init());
#else
tcpip_adapter_init();
#endif
----- snip ------

Commenting out the conditional compilation leading to the "new" esp_netif_init() call works as well so location in the code doesn't appear to be critical. It looks like the whole implementation of the TCPIP initialization is new and perhaps something in there is not quite right. I plan to take a look and see what I can find. I will post here if I find anything useful.

Thanks again.

douardda
Posts: 2
Joined: Wed Jan 20, 2021 2:47 pm

Re: ESP-ADF: Connecting to WiFi but not acquiring IP via DHCP

Postby douardda » Wed Jan 27, 2021 9:23 am

Note that this has no now been fixed (see https://github.com/espressif/esp-adf/issues/564 )

cyberslug
Posts: 3
Joined: Wed Dec 16, 2020 12:03 pm

Re: ESP-ADF: Connecting to WiFi but not acquiring IP via DHCP

Postby cyberslug » Wed Jan 27, 2021 10:50 am

Thanks @douardda much appreciated

MP@L&T
Posts: 8
Joined: Wed Feb 17, 2021 11:34 am

Re: ESP-ADF: Connecting to WiFi but not acquiring IP via DHCP

Postby MP@L&T » Mon Mar 01, 2021 9:57 am

Can anyone help me as I am still getting this error when I try to use the "Play mp3 file from HTTP" example.
I added the tcpip_adapter_init line as suggested but my program still times out on periph_wifi_wait_for_connected. The code I changed as shown:

----- snip ------
esp_periph_config_t periph_cfg = DEFAULT_ESP_PERIPH_SET_CONFIG();
esp_periph_set_handle_t set = esp_periph_set_init(&periph_cfg);
periph_wifi_cfg_t wifi_cfg = {
.ssid = CONFIG_WIFI_SSID,
.password = CONFIG_WIFI_PASSWORD,
};
tcpip_adapter_init(); // <----- ADD THIS LINE
esp_periph_handle_t wifi_handle = periph_wifi_init(&wifi_cfg);
esp_periph_start(set, wifi_handle);
periph_wifi_wait_for_connected(wifi_handle, portMAX_DELAY);
----- snip ------

GerryBriggs
Posts: 20
Joined: Tue Oct 24, 2023 10:11 pm

Re: ESP-ADF: Connecting to WiFi but not acquiring IP via DHCP

Postby GerryBriggs » Tue Oct 24, 2023 10:39 pm

I am also getting the same error. I guess this has not been solved in over 2 years

GerryBriggs
Posts: 20
Joined: Tue Oct 24, 2023 10:11 pm

Re: ESP-ADF: Connecting to WiFi but not acquiring IP via DHCP

Postby GerryBriggs » Tue Oct 24, 2023 10:48 pm

Was there ever any solution? Is it a problem with the ADF component periph_wifi.h ?

Who is online

Users browsing this forum: No registered users and 45 guests