slimDNS: a pure Python mDNS implementation

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
Posts: 9
Joined: Sun Sep 11, 2016 8:11 pm

slimDNS: a pure Python mDNS implementation

Post by nickovs » Tue Feb 13, 2018 11:06 pm

For some time I've been frustrated by the lack of multicast DNS support in the MicroPython implementations for the ESP8266, and more recently the ESP32, so I finally decided to do something about it.

To that end I'd like to present slimDNS (Simple, Lightweight Implementation of Multicast DNS).

It's a little rough around the edges still but I have tried it on both the ESP8266 and the ESP32 and it successfully advertises the addresses of the devices. It also supports resolution of names to addresses via multicast DNS (although for some reason this isn't currently reliable on the ESP8266; it seems to be fine on the ESP32). If you are running it on the ESP8266 then I'd recommend baking it in to the flash image as a "frozen" module by adding it to the ports/esp8266/modules directory and rebuilding, since importing it from the file system consumes about 6.5K. If you have it frozen then the marginal memory usage when you're already using network, socket and select modules is about 1260 bytes; on my build of 1.9.3 there's a little over 27K free on the ESP8266 when it's running.

As well as supporting mDNS address advertisement and lookup, the code is designed to be able to support mDNS service discovery. This requires the creation of PTR, SRV and TXT records and adding them to the list of available records. I will be releasing reference code for doing this; if that code doesn't add too much to the memory footprint of the frozen module then I will put it in the main module but I might make it a separate module so that it's easier for users to not include it when memory is tight.

The code on GitHub right now is very much "version 0.1.0" quality. The API for isn't as clean as I'd like, right now you can add records to be advertised but not delete them, and it has somewhat limited error handling. If people in the MicroPython community like this then I'll put some more work into it to get it polished. In the mean time if you have any comments or feedback please let me know, either here or in the GitHub issue tracker.

Post Reply