-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
esp32: Add support for mDNS queries and responder. #4951
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thanks! It would be great to have this for both queries and responder. Almost all of my ESP32s are currently running my somewhat flaky slimDNS so that I can find them on the network but using the built-in implementation in the ESPIDF would be much better. As for setting the host name, I struggle to think of a situation where one would want to have different DHCP and mDNS host names, but I suspect that if it were disallowed then someone would quickly come up with a use case. There is a lot of existing code that expects to be able to set |
Maybe. But it'd be good to er on the side of "keep things minimal" and not have separate hostname configs until there really is a use case.
Yes, to maintain backwards compatibility we should keep But in general the hostname is not specific to a given NIC, rather it's a system wide thing (like |
That seems like a sensible path to take.
8000
The ESP IDF deems the In the mean time I patched your diff to just pull the current hostname back from the adaptor using
|
Great, thanks for that, I've added this to the mDNS patch here and merged it in 2ccf030. I also added config macros for mDNS support because it may be something a user wants to disable (although eventually it could be dynamically configurable). |
I see in the new 1.12 release mDNS is enabled. Great work! I can get confirm resolving EDIT: Answering myself by reading through the code, the key was calling import network
def start(quiet=False):
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
if not wlan.isconnected():
if not quiet: print('connecting to network...')
wlan.connect('ssid', 'mypassword')
while not wlan.isconnected():
pass
wlan.config(dhcp_hostname="myhost")
if not quiet: print('network config:', wlan.ifconfig())
return(wlan) |
This example does not work for me in 1.13 (IDF4), no errors displayed. I can ping the device using the IP address, but not using the mDNS name 'myhost' (
|
You tried pinging |
I did. I'll check with the router what's going on. Ironically, if you use mDNS examples provided by espressif/arduino IDE (same device), the mDNS gets set flawlessly and you can access it - so I have some reasonable doubts about it not being my network. Should mention I'm pinging from windows, no bonjour service etc |
so some more info:
similar issue already mentioned here, possibly helpful |
This adds support to the esp32 for mDNS queries and a responder. See discussion in #4912.
For queries do:
socket.getaddrinfo('device.local', 123)
The responder is automatically enabled, with default hostname "esp32.local".
TODO: work out a way to specify the hostname. Probably need a new config option
wlan.config(mdns_hostname=...)
. Or could reusewlan.config(dhcp_hostname=...)
. Even though there are different concepts of hostnames it'd probably be a good idea to unify them into a single config, egwlan.config(hostname=...)
.