ESP8266 Doesn't Respond to mDNS Query "A"
Posted: Sun Apr 25, 2021 2:50 pm
Not having much luck using mDNS on an ESP8266 (or an ESP32 either). Tried it with PlatformIO, and Arduino IDE (core 2.7.4); using my code or example code (mDNS_Web_Server); always the same result: works fine for 2 minutes after booting, then fails.
Here's what I expect to happen: pinging from a host (Ubuntu) to a .local address (in this case a Raspberry Pi), it send an mDNS "A" request; the response has the IP:
When I try pinging an ESP8266 running the example program it doesn't respond to the mDNS query and the ping fails:
It will however respond to "PTR" queries, so running mdns-scan first will retrieve the _http._tcp.local service and get the IP that way:
...which is good for 2 minutes, then the mDNS record times-out, repeat...
Basically that's what the Arduino IDE does for OTA: every 100 seconds it sends a "PTR _arduino._tcp.local" request to refresh the OTA hosts. Which means that if you have OTA in your sketch and the IDE is running, mDNS will work fine. But two minutes after you shutdown the IDE the mDNS records will time-out, and mDNS will fail.
Also tried this from the "Windows" operating system. Worked fine pinging a Raspberry Pi host, but never got a successful ping to an ESP8266 host. Interestingly, even though the ping failed, the mDNS records were refreshed and pings to the ESP8266 were successful from all other OS hosts.
So, how do you get mDNS to work on the ESP8266/ESP32?
Here's what I expect to happen: pinging from a host (Ubuntu) to a .local address (in this case a Raspberry Pi), it send an mDNS "A" request; the response has the IP:
When I try pinging an ESP8266 running the example program it doesn't respond to the mDNS query and the ping fails:
It will however respond to "PTR" queries, so running mdns-scan first will retrieve the _http._tcp.local service and get the IP that way:
...which is good for 2 minutes, then the mDNS record times-out, repeat...
Basically that's what the Arduino IDE does for OTA: every 100 seconds it sends a "PTR _arduino._tcp.local" request to refresh the OTA hosts. Which means that if you have OTA in your sketch and the IDE is running, mDNS will work fine. But two minutes after you shutdown the IDE the mDNS records will time-out, and mDNS will fail.
Also tried this from the "Windows" operating system. Worked fine pinging a Raspberry Pi host, but never got a successful ping to an ESP8266 host. Interestingly, even though the ping failed, the mDNS records were refreshed and pings to the ESP8266 were successful from all other OS hosts.
So, how do you get mDNS to work on the ESP8266/ESP32?