Mdns makes your embedded devices easy to find

I’m making a network controlled light. The idea is that the light hosts a web site which you can find with your phone or computer. The light will have an internet (IP) address which you can use to locate it on the network (something like 192.168.50.5) but this might change as these addresses are assigned by your network router on a first-come first-served basis. What you really want to be able to do is refer to your light as “flashlight.local”. The mdns service makes this possible.

I’m using Circuit Python to host the website in a Rasbperry Pi PICO-W. They have a lovely HTTP server library which works a treat. It also supports mdns (Multicast Domain Name Server). This lets applications (for example your browser) ask if anyone on the local network has a particular name (in this case flashlight.local). The mdns server running on the PICO-W responds to these requests with a network address which can then be used to contact the PICO-W. The code below was added to the application and starts the service running. This code is slightly different from the example code for the service, but it does work very well.

import mdns


mdns_server = mdns.Server(wifi.radio)
mdns_server.hostname = "flashlight"

Once the server has been started it seems to just run in the background responding to requests.

This is the final website for the light

You can use this to make your embedded devices much easier to locate. If they get given a different IP address next time they start up they will just keep going.