espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
13.01k stars 7.12k forks source link

ESP32 WiFi driver softAP: DHCP server problems due to loss of UDP broadcast packages (IDFGH-11444) #12580

Open ch-fb opened 8 months ago

ch-fb commented 8 months ago

Answers checklist.

General issue report

Scenario: esp32 as AP Problem: clients have (re)connection problems

For years, developers have reported problems with the esp's DHCP server. Some scenarios can be reproduced and tackled (for instance, when a client holds on to the old lease after the esp has been rebooted), but in many other cases it's difficult or impossible to reproduce a problem as they occur rather randomly.

After days or rather weeks of intensive wireshark sessions, I started seeing a pattern: replies of the DHCP server get lost! The more traffic (other clients) and/or the weaker the WiFi signal, the more likely this occurs.

Quite often the following scenario happens: client sends a DHCP discovery or a request (with old lease's IP) ESP assigns IP (event is fired) but client does not receive the OFFER or the ACK.

Client typically times out and tries again, so (re)connecting can take a long time, or it gives up. Even the NACK after a request with an old IP gets lost sometimes.

I suspect the problem simply in the implementation of the WiFi driver, where "AP only caches unicast data for the stations connect to this AP".

It would be good to give the Wifi driver a higher priority, for years an ESP hasn't been able to reliably send UDP broadcast...

Xiehanxin commented 8 months ago

hi @ch-fb could you share your IDF version or commit?

Xiehanxin commented 8 months ago

and if you can share your DHCP wireless package it would be more helpful

ch-fb commented 8 months ago

sorry for my late reply. most tests were done with idf 4.4. i went through the changelogs since 4.4 up to the latest version and did not see any DHCP-related changes nor work on caching in the WiFi driver. It is a known problem that UDP broadcast packets can easily get lost for stations that use power-saving modes (which basically all phones/tablets/laptops do) and I have observed that plenty of times.

AxelLin commented 1 month ago

After days or rather weeks of intensive wireshark sessions, I started seeing a pattern: replies of the DHCP server get lost! The more traffic (other clients) and/or the weaker the WiFi signal, the more likely this occurs.

Quite often the following scenario happens: client sends a DHCP discovery or a request (with old lease's IP) ESP assigns IP (event is fired) but client does not receive the OFFER or the ACK.

@ch-fb Could you share the wireshark log?

ch-fb commented 1 month ago

haven't saved them as I had wireshark runnig for hours in the background and I just looked at the recent entries whenever some connection problem happened again. But what it shows is that DHCP broadcast packets sometimes don't arrive (OFFER or ACK). It seems the ESP sends them (or at least it fires the according events), but they don't arrive.

Losing UDP broadcast/multicast packets when the ESP is in AP mode isn't a new issue, it has been observed many times also by others. To best reproduce the issue, you should have a busy network (plenty of traffic with other clients).

We actually gave up using the ESP for one of our products because of that issue as our application needs to send high-traffic UDP broadcast (continuous real-time data). Unfortunately, the ESP manages to deliver only a part of that data. I personally noticed the problem also for mDNS packets.

For a softAP that manages 4-10 clients, the proper caching of UDP broadcast/multicast packets isn't a very difficult task. It would be really important to implement that in the WiFi driver soon.

AxelLin commented 1 month ago

haven't saved them as I had wireshark runnig for hours in the background and I just looked at the recent entries whenever some connection problem happened again. But what it shows is that DHCP broadcast packets sometimes don't arrive (OFFER or ACK). It seems the ESP sends them (or at least it fires the according events), but they don't arrive.

Losing UDP broadcast/multicast packets when the ESP is in AP mode isn't a new issue, it has been observed many times also by others. To best reproduce the issue, you should have a busy network (plenty of traffic with other clients).

@nishanth-radja @Xiehanxin Is above symptom a known issue?

ch-fb commented 1 month ago

yes, I have seen a a few bug reports. But it is even mentioned in the official ESP documentation for the WiFi driver (regarding WiFi power-saving/sleeping modes): https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-guides/wifi.html#ap-sleep