Description
This issue has been previously posted by others but was erroneously closed as "stale" without resolution. It is still a problem.
Hardware:
Board: LOLIN32, MH-ET-LIVE, DOIT devkit v1 and others. Happens with all ESP32 hardware I've tested.
Core Installation version: 1.0.4
IDE name: Arduino IDE
Flash Frequency: 80Mhz
PSRAM enabled: no
Description:
I'm trying to use MDNS. Using the mDNS_Web_Server example, when the device starts, I am able to access the page at 'esp32.local/'. However, after two minutes, this stops working.
Manually resolving the mDNS address shows the same behavior - it works for the first two minutes after the device is started, then simply stops working.
I did a Wireshark capture on the IP address of the ESP32. It broadcasts the mDNS messages, with a TTL of 2 minutes. It only ever broadcasts those messages at startup (I left the device for ~20m).
If I manually call MDNS.begin periodically, it works, but the correct function for this is update() which is missing from the ESP32 version.
I was able to reproduce this on multiple dev boards, and several others have reported the same issue.
Sketch:
mDNS_Web_Server example (only modified to set the ssid/password)
Debug Messages:
None
Activity
felmue commentedon Oct 11, 2020
HI @leifclaesson
I am running the mDNS_Web_Server example on a ESP32_LyraT board and I can ping 'local.ESP32' after start and also after waiting for more than 2 minutes just fine. I wonder if it has something to do with the OS from which the ping is originated from. I am using MacOSX. What is the OS you are testing with?
BTW: I only very quickly looked into how mDNS is supposed to work, so I could be wrong about it. So far it is my understanding that the server only is supposed to send out it's mDNS information when a client asks for it, so I would not expect it to broadcast its information periodically on it's own (except for when it is started), but only upon request. That is why I think it might be related to the mDNS implementation of the OS used to ping the ESP32 board.
Thanks
Felix
EricDuminil commentedon Dec 5, 2020
Hello.
For what it's worth, I can reproduce this behaviour with
espressif8266
.Same sketch (mDNS_Web_Server example, only modified to set the ssid/password).
Compiling with Arduino IDE or pio doesn't seem to make any difference.
Here are my pio libs:
I can ping
esp8266.local
at first (both from Linux Mint 19.3 and OS X El Capitan), but after 2 minutes, it returnsping: esp8266.local: Name or service not known
.I wrote a small bash loop to time it. I start the loop, wait 10 seconds, start the board and let loop and board run:
What's weird is that it might randomly start again after a while (2 or 3 minutes), without rebooting the board:
It will stop again after exactly 2 minutes, though.
I realize my board isn't an esp32, but it seems to have the same problem as yours, though, so it might help spotting where the actual problem comes from.
stale commentedon Feb 4, 2021
[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.
mjcross commentedon Feb 17, 2021
Just doing some testing on this; will report back
stale commentedon Feb 17, 2021
[STALE_CLR] This issue has been removed from the stale queue. Please ensure activity to keep it openin the future.
mjcross commentedon Feb 17, 2021
OK I've made some checks with tcpdump.
I can confirm that with the mDNS server in the Espressif native framework (ESP-IDF v4.2), the same pattern of packets is sent.
At startup, after obtaining an IP address the ESP32 first broadcasts an mDNS query for the hostname it is about to use (with a TTL of 2 minutes). It does this three times.
If no other machine responds (which would indicate this hostname is already assigned to another machine), the ESP32 then broadcasts an mDNS response to its own query, advertising its IP address (with a TTL of 2 mins). It does this three times.
After this initial announcement I did not see the ESP32 send any further mDNS packets during the 30min period of my test - although it did continue to send periodic ARP broadcasts (which are not related to mDNS).
However unlike the OP, I do not lose the ability to resolve the hostname after the 2 minute period... indeed all the machines on my LAN were still able to resolve and ping the host four hours later.
Looking into this a little more closely, I can see that it is in fact my residential gateway (FritzBox 7530) that has cached the mDNS result for the ESP32, and is serving it to other local clients via the 'normal' DNS service on port 53.
me-no-dev commentedon Feb 18, 2021
I can agree with @mjcross here. If resolution stops after 2 minutes, that means that the client did not re-query to refresh the record and so made it invalid. Generally it should have asked for the host about 1 minute in (half the TTL).
The MDNS lib in IDF is fully compliant and much tested.
mjcross commentedon Feb 18, 2021
If your application has long gaps between a client accessing the ESP32 via its mDNS hostname, then you might try getting the ESP32 to do an mDNS lookup of its own hostname using the resolve_mdns_host() API call every couple of minutes. This should keep the record 'fresh' in the cache of other machines on the LAN.
If that doesn't work then you might try periodically restarting the mDNS service on the ESP32 every couple of minutes using mdns_free() and mdns_init(), which should cause a re-broadcast of the initial mDNS registration.
leifclaesson commentedon Apr 30, 2021
This is an interesting idea! I will try this. Thank you!
That was actually the first thing I tried -- this causes the ESP to crash and reboot after ~25 hours. Took me quite a while to find why my many ESP32s had trouble staying up, because you don't immediately notice the problem after adding the periodic reinit.. so, that one is not a good solution.
MythicalForce commentedon May 8, 2021
i have the exact same problem... googling my ass off trying to find a fix for this!
khanhvu161188 commentedon Jun 28, 2021
I have tried but this approach does not work.
25 remaining items