DHCP on ethernet & stability

PeterR
Posts: 621
Joined: Mon Jun 04, 2018 2:47 pm

DHCP on ethernet & stability

Postby PeterR » Tue Mar 17, 2020 5:46 pm

I need a DHCP server on the Ethernet interface.
I have used the netif interface to add DHCP in a small worked example but I keep hitting stability issues when upgrading IDF on my application.

I am currently running with legacy GNU using toolchain 3.3.1 and IDF v4.0-dev-562-g2b301f53e. This seems quite stable. An unusual combo but the IDF was the first I found with CAN and have stuck with it.

I upgraded toolchain to xtensa-esp32-elf-gcc8_2_0-esp-2019r2-win32.zip and IDF v4.1-dev-1543-g431066f16
I then managed to create a simple DHCP server demonstration.
Unfortunately the full application was very unreliable.

I upgraded IDF to v4.2-dev-674-g640c7c510
The application is now reliable as a DHCP client but hangs during intialisation as a server.
The simple DHCP server example fails to assign an IP address when logging INFO but provides an IP address when logging DEBUG.
Probably a timing issue but weird.

So I am really looking for advice on the 'best' most stable IDF with DHCP support.
Or, maybe, a library which I could add to my original stable setup.
& I also believe that IDF CAN should be fixed.

PeterR
Posts: 621
Joined: Mon Jun 04, 2018 2:47 pm

Re: DHCP on ethernet & stability

Postby PeterR » Wed Mar 18, 2020 11:10 am

Code: Select all

.flags = (esp_netif_flags_t)(ESP_NETIF_DHCP_SERVER | ESP_NETIF_FLAG_GARP | ESP_NETIF_FLAG_EVENT_IP_MODIFIED), \
will allow the application to continue.

Adding the AUTOUP flag causes the application to hang around 50mS after esp_eth_start() call:

Code: Select all

.flags = (esp_netif_flags_t)(ESP_NETIF_DHCP_SERVER | ESP_NETIF_FLAG_GARP | ESP_NETIF_FLAG_EVENT_IP_MODIFIED | ESP_NETIF_FLAG_AUTOUP), \
As said, DHCPC client seems absolutely fine.
AUTOUP causes netif_set_up() to be called during setup rather than on interface event.

EDIT:
My application hangs because I have attached a UDP logger to ESP_LOG output. You would expect sendto() to return error rather than hang, but..
Removing my UDP logger allows the application to launch. The application launches a few services and starts periodic multicast. The multicast (sendto) fails:

Code: Select all

E (3493) emac_esp32: emac_esp32_transmit(222): insufficient TX buffer size
& I also believe that IDF CAN should be fixed.

PeterR
Posts: 621
Joined: Mon Jun 04, 2018 2:47 pm

Re: DHCP on ethernet & stability

Postby PeterR » Thu Mar 19, 2020 10:41 am

Swapped cable and now works.
EDIT: 5 minutes latter no longer works.

There do seem to be issue(s) with netif, around AUTOUP, for example sendto() can block.
I am guessing that if you have a bad cable then AUTOUP may not work well. If you wait for driver detect then maybe the hardware is in the correct state and you bypass the bug.
& I also believe that IDF CAN should be fixed.

PeterR
Posts: 621
Joined: Mon Jun 04, 2018 2:47 pm

Re: DHCP on ethernet & stability

Postby PeterR » Thu Mar 19, 2020 2:39 pm

Looking closer at the small worked example. The example was often not working. I had assumed that the example was working because the PC had a leased address. It seems that the PC will remember its last lease rather than use an auto local.

Understanding that the DHCP server was not actually working I dumped esp_netif_get_ip_info() which reveals that the ESP has address 0.0.0.0

To intitialise DHCP I use:
esp_netif_dhcps_stop(), esp_netif_set_ip_info(), esp_netif_dhcps_start()
but the assigned address does not stick when used early in the boot. Sometimes esp_netif_get_ip_info() will show the assigned IP but shortly later the address is 0.0.0.0 (when set used early in boot)
Using esp_netif_dhcps_stop(), esp_netif_set_ip_info(), esp_netif_dhcps_start() some seconds after boot seems to work.

Note that esp_netif_is_netif_up() returned true each time I perform the initialisation.
There is therefore some part of the initialisation which I do not understand.
When am I supposed to stop(), set_ip() and start()?
How can I test that its time to start?

EDIT: Additionally using sento() before the DHCPS is fully up (does not return 0.0.0.0) will hang. So it is vital that I can detect the condition.
& I also believe that IDF CAN should be fixed.

Who is online

Users browsing this forum: Bing [Bot] and 93 guests