Page 1 of 1

IP_EVENT for timeout on dhcp request ?

Posted: Fri Apr 14, 2023 6:51 pm
by limpens
Hi all,

If got the following use case:

wifi credentials are properly configured and the code is connecting to the selected wifi SSID, but due to a strict dhcp setup, there will not be an answer to a dhcp-request (a combination of authoritative and ignore unknown-clients in ISC-DHCP). For an answer to the dhcp-request, the mac address will have to be added to the correct pool.

So, I like to give a notice to the user, that the dhcp-request was not answered in a timely fashion, but I'm kinda stuck here.

I've setup an event handler with card blanche:

Code: Select all

esp_event_handler_instance_register(ESP_EVENT_ANY_BASE, ESP_EVENT_ANY_ID, event_handler, ....
And the events are printed in the event_handler in the expected order, when the dhcp-request is answered by the dhcp-server
WIFI_EVENT / WIFI_EVENT_STA_START
WIFI_EVENT / WIFI_EVENT_SCAN_DONE
WIFI_EVENT / WIFI_EVENT_STA_CONNECTED

IP_EVENT / IP_EVENT_STA_GOT_IP
But, in this use case, when the mac address hasn't been added to the reservation list of the dhcp server, it will never get an answer and the events end with WIFI_EVENT_STA_CONNECTED.


My question: is there any better solution but starting a timer after calling esp_wifi_connect() to wait for a predefined time for an ip address / IP_EVENT_STA_GOT_IP event?

Regards.

Re: IP_EVENT for timeout on dhcp request ?

Posted: Tue Apr 18, 2023 8:00 pm
by limpens
Resolved the issue by using a few bits in an event-group and waiting for the correct bit(s) after WIFI_EVENT_STA_CONNECTED has been received.

Of course it would be really convenient when the wifi stack was able to keep track of dhcp requests and emit an event when no reply has been received in a configurable time. ;)

Regards.