mDNS example

The official PYBD running MicroPython, and its accessories.
Target audience: Users with a PYBD
Post Reply
User avatar
Posts: 205
Joined: Fri Oct 31, 2014 10:29 am
Location: Zurich / Switzerland

mDNS example

Post by marfis » Sat Jul 06, 2019 7:33 pm

I was wondering how I could add mDNS support with my D-Serie Pyboard SF2..

So I was pleasantly surprised to see that mDNS support was enabled somewhere last month. But I didn't see an example how to use it.

After fiddling around I came up with this script that prints the mDNS name of the pyboard. You can then ping it on the local network via this name. Basically the mDNS name is hardcoded and starts with PYBD followed by the last 4 digits of the mac.

Code: Select all

import binascii
import network
wl = network.WLAN()
wl.connect('xxxx', 'yyy')
mac = wl.config('mac')
last = binascii.hexlify(mac)[-4:].decode("ascii")
print("ping me on PYBD{}.local".format(last))
maybe somebody find this useful. Could also help to add something like this in docs.

A bit of a pity that the name can't be changed during operation. That would have allowed to use more meaningful names...

Post Reply