-
Notifications
You must be signed in to change notification settings - Fork 345
mdns
Multicast DNS (mDNS) is the protocol that creates a device-uniqueidentifier to register as a hostname via a multicast service on local networks.
Usage:
import network
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
sta_if.connect("WiFi_SSID", "WiFi_password")
tmo = 50
while not sta_if.isconnected():
utime.sleep_ms(100)
tmo -= 1
if tmo == 0:
break
if sta_if.isconnected():
mdns = network.mDNS(sta_if)
_ = mdns.start("mPy","MicroPython with mDNS")
_ = mdns.addService('_ftp', '_tcp', 21, "MicroPython", ("board=ESP32", "service=mPy FTP File transfer", "passive=True"))
_ = mdns.addService('_telnet', '_tcp', 23, "MicroPython", ("board=ESP32", "service=mPy Telnet REPL"))
_ = mdns.addService('_http', '_tcp', 80, "MicroPython", ("board=ESP32", "service=mPy Web server"))
wifi_if is the network.WLAN object (network.STA_IF or network.AP_IF)
name string, server host name
instance string, mDNS instance description
Returns True on success, False on fail.
After the mdns is started, the MicroPython host will be visible in local network as name.local
stop the mdns server, free the resources
Returns True on success, False on fail.
Add service to mdns server.
service string, service type, use names like '_http', '_ftp', _telnet', '_mytcp'
protocol string, protocol type, '_tcp' or '_udp'
port integer, the port on which the service runs
instance string, service instance name
txdata optional, string or tuple of strings (max 8 items), describe the service characteristics
Returns True on success, False on fail.
Remove the previously added service from mdns server.
service string, service type
protocol string, protocol type
Returns True on success, False on fail.
Query the IP address of the LAN host hostname.
hostname string, host name to query
Returns list of tuples containing IPv4 and IPv6 addresses as strings.
Query the service info from hosts on LAN.
service string, service type
protocol string, protocol type
Returns list of tuples containing services information:
(hostname, instance, IPv4_string, IPv6_string, port, txdata)