Open karlp opened 3 months ago
My Workaround is to simply poll esp_netif_dhcpc_get_status
and reapply IP settings (either static or DHCP) as long as the dhcpc status is INIT. For static IP configuration, the state needs to be in STOPPED, and for DHCP it needs to be in STARTED.
I should also note that when using static IPs, the DHCP client still remains stuck in INIT, but this causes no harm in that case.
Answers checklist.
IDF version.
5.1.2 (but same code in master and 5.2)
Espressif SoC revision.
ESP32
Operating System used.
Linux
How did you build your project?
Command line with idf.py
If you are using Windows, please specify command line type.
None
Development Kit.
Custom
Power Supply used.
External 5V
What is the expected behavior?
After creating a (ethernet) netif, I optionally apply DHCP client settings. Depending on how quickly the link comes up, the DHCP settings are not always applied. The
esp_netif_dhcpc_start
call returns ESP_OK, but it prints a debug log to "re-init" Here: https://github.com/espressif/esp-idf/blob/master/components/esp_netif/lwip/esp_netif_lwip.c#L1531-L1533Unless I explicitly re-invoke dhcp start, my netif says permanently in the ESP_NETIF_DHCP_INIT state. I can externally plug/unplug the ethernet, and see that the stack recognises link up/down events, but DHCP will never request an address.
To summarize, expected behaviour is that
Should either start DHCP client, or return an error. Currently, it returns a misleading "ESP_OK", with only a debug print.
What is the actual behavior?
Actual behaviour is that no error code is returned, but the DHCP client is not started.
Steps to reproduce.
The netif is created using code like this, which disables the automatic dhcp, because we may (depending on config) wish to use static IPs instead:
Afterwards, we use this code for turning on DHCP:
We see this state of the netif not being up happen when we are removing and re-creating the netif around power down states. (We remove and destroy the netif to clear PM locks, as we are also powering off the PHY entirely)
Debug Logs.
(I edited my local esp-idf to make the two places that both log "dhcp client re init" distinguishable...)
log 1
Debug log of creating and "applying" DHCP
``` I (10:54:12.733) task_network: <Log section 2
This snippet shows that link up/down has no impact on this after the fact, the dhcp client is simply not started.
Log of link up/down
``` I (11:01:27.438) K: dhcpc: netif: 0x3ffd3d40 (UP) flags: 18 init <<< my code checking state of dhcp D (11:01:27.955) esp_netif_lwip: esp_netif_get_ip_info esp_netif:0x3ffd3d40 I (11:01:28.437) K: dhcpc: netif: 0x3ffd3d40 (UP) flags: 18 init D (11:01:28.769) esp_netif_lwip: esp_netif_get_ip_info esp_netif:0x3ffd3d40 D (11:01:28.770) esp_netif_lwip: esp_netif_get_ip_info esp_netif:0x3ffd3d40 D (11:01:28.821) esp_netif_lwip: esp_netif_get_ip_info esp_netif:0x3ffd3d40 D (11:01:28.821) esp_netif_lwip: esp_netif_get_ip_info esp_netif:0x3ffd3d40 I (11:01:29.436) K: dhcpc: netif: 0x3ffd3d40 (UP) flags: 18 init D (11:01:29.953) esp_netif_lwip: esp_netif_get_ip_info esp_netif:0x3ffd3d40 I (11:01:30.435) K: dhcpc: netif: 0x3ffd3d40 (UP) flags: 18 init D (11:01:30.779) event: running post ETH_EVENT:3 with handler 0x400d90c0 and context 0x3ffdb378 on loop 0x3ffcae3c D (11:01:30.896) event: running post ETH_EVENT:3 with handler 0x400dc8c0 and context 0x3ffd37d0 on loop 0x3ffcae3c D (11:01:30.896) event: running post ETH_EVENT:3 with handler 0x401027cc and context 0x3ffdf844 on loop 0x3ffcae3c D (11:01:30.898) esp_eth.netif.netif_glue: eth_action_disconnected: 0x3ffd3534, 0x3f41c9f8, 3, 0x3ffdfff4, 0x3ffd5074 D (11:01:30.901) esp_netif_handlers: esp_netif action disconnected with netif0x3ffd3d40 from event_id=3 D (11:01:30.904) esp_netif_lwip: check: remote, if=0x3ffd3d40 fn=0x400ffad8 I (11:01:30.908) esp_netif_lwip: esp_netif_down_api esp_netif:0x3ffd3d40 D (11:01:30.910) esp_netif_lwip: check: local, if=0x3ffd3d40 fn=0x401000f8 D (11:01:30.913) esp_netif_lwip: esp_netif_update_default_netif_lwip 0x3ffd3d40 D (11:01:30.914) esp_netif_lwip: call api in lwip: ret=0x0, give sem D (11:01:30.917) event: running post ETH_EVENT:3 with handler 0x400e025c and context 0x3ffd4c1c on loop 0x3ffcae3c I (11:01:30.919) net_connect: Ethernet event 3 I (11:01:30.921) net_connect: Link down <<< my code link handler print D (11:01:30.923) event: no handlers have been registered for event ESP_HTTP_SERVER_EVENT:8 posted to loop 0x3ffcae3c D (11:01:30.924) event: no handlers have been registered for event ESP_HTTP_SERVER_EVENT:1 posted to loop 0x3ffcae3c I (11:01:31.435) K: dhcpc: netif: 0x3ffd3d40 (DOWN) flags: 18 init I (11:01:32.434) K: dhcpc: netif: 0x3ffd3d40 (DOWN) flags: 18 init I (11:01:33.433) K: dhcpc: netif: 0x3ffd3d40 (DOWN) flags: 18 init I (11:01:34.433) K: dhcpc: netif: 0x3ffd3d40 (DOWN) flags: 18 init I (11:01:35.432) K: dhcpc: netif: 0x3ffd3d40 (DOWN) flags: 18 init I (11:01:36.432) K: dhcpc: netif: 0x3ffd3d40 (DOWN) flags: 18 init I (11:01:37.431) K: dhcpc: netif: 0x3ffd3d40 (DOWN) flags: 18 init I (11:01:38.431) K: dhcpc: netif: 0x3ffd3d40 (DOWN) flags: 18 init D (11:01:38.780) event: running post ETH_EVENT:2 with handler 0x400dc8c0 and context 0x3ffd37d0 on loop 0x3ffcae3c D (11:01:38.781) event: running post ETH_EVENT:2 with handler 0x40102808 and context 0x3ffdf7f8 on loop 0x3ffcae3c D (11:01:38.783) esp_eth.netif.netif_glue: eth_action_connected: 0x3ffd3534, 0x3f41c9f8, 2, 0x3ffdfff4, 0x3ffd5074 D (11:01:38.786) esp_netif_handlers: esp_netif action connected with netif0x3ffd3d40 from event_id=2 D (11:01:38.788) esp_netif_lwip: check: remote, if=0x3ffd3d40 fn=0x400ff938 D (11:01:38.793) esp_netif_lwip: esp_netif_up_api esp_netif:0x3ffd3d40 D (11:01:38.794) esp_netif_lwip: check: local, if=0x3ffd3d40 fn=0x401000f8 D (11:01:38.799) esp_netif_lwip: esp_netif_update_default_netif_lwip 0x3ffd3d40 D (11:01:38.800) esp_netif_lwip: call api in lwip: ret=0x0, give sem D (11:01:38.802) event: running post ETH_EVENT:2 with handler 0x400e025c and context 0x3ffd4c1c on loop 0x3ffcae3c I (11:01:38.804) net_connect: Ethernet event 2 <<< my code link handler print I (11:01:38.807) net_connect: Ethernet Link Up D (11:01:39.006) esp_netif_lwip: esp_netif_get_ip_info esp_netif:0x3ffd3d40 D (11:01:39.306) esp_netif_lwip: esp_netif_get_ip_info esp_netif:0x3ffd3d40 I (11:01:39.430) K: dhcpc: netif: 0x3ffd3d40 (UP) flags: 18 init D (11:01:39.606) esp_netif_lwip: esp_netif_get_ip_info esp_netif:0x3ffd3d40 D (11:01:39.906) esp_netif_lwip: esp_netif_get_ip_info esp_netif:0x3ffd3d40 D (11:01:39.954) esp_netif_lwip: esp_netif_get_ip_info esp_netif:0x3ffd3d40 I (11:01:40.429) K: dhcpc: netif: 0x3ffd3d40 (UP) flags: 18 init D (11:01:40.771) esp_netif_lwip: esp_netif_get_ip_info esp_netif:0x3ffd3d40 D (11:01:40.771) esp_netif_lwip: esp_netif_get_ip_info esp_netif:0x3ffd3d40 D (11:01:40.821) esp_netif_lwip: esp_netif_get_ip_info esp_netif:0x3ffd3d40 D (11:01:40.822) esp_netif_lwip: esp_netif_get_ip_info esp_netif:0x3ffd3d40 D (11:01:41.006) esp_netif_lwip: esp_netif_get_ip_info esp_netif:0x3ffd3d40 I (11:01:41.428) K: dhcpc: netif: 0x3ffd3d40 (UP) flags: 18 init D (11:01:41.771) esp_netif_lwip: esp_netif_get_ip_info esp_netif:0x3ffd3d40 D (11:01:41.772) esp_netif_lwip: esp_netif_get_ip_info esp_netif:0x3ffd3d40 D (11:01:41.821) esp_netif_lwip: esp_netif_get_ip_info esp_netif:0x3ffd3d40 D (11:01:41.822) esp_netif_lwip: esp_netif_get_ip_info esp_netif:0x3ffd3d40 D (11:01:41.955) esp_netif_lwip: esp_netif_get_ip_info esp_netif:0x3ffd3d40 D (11:01:42.106) esp_netif_lwip: esp_netif_get_ip_info esp_netif:0x3ffd3d40 I (11:01:42.427) K: dhcpc: netif: 0x3ffd3d40 (UP) flags: 18 init I (11:01:43.427) K: dhcpc: netif: 0x3ffd3d40 (UP) flags: 18 init ```More Information.
No response