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
nickovs
Posts: 11
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.

ameersohail0
Posts: 1
Joined: Wed Jul 15, 2020 6:49 pm

Re: slimDNS: a pure Python mDNS implementation

Post by ameersohail0 » Wed Jul 15, 2020 7:00 pm

Thanks @nickovs for the slimDNS library. I was looking for a DNS lookup library and couldn't find any until I found this. I am using it on the ESP8266 board and it does give out the MemoryError : memory allocation failed, allocating 256 byte.

Instead of baking this on to the MicroPython core, I have compressed the library using mpy-cross. Works without any issues now.
https://gitlab.com/alelec/mpy_cross

Thank you!

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: slimDNS: a pure Python mDNS implementation

Post by pythoncoder » Thu Jul 16, 2020 7:21 am

This looks really useful.

A couple of thoughts/comments. I notice you use select.select() - this comes with some deprecation in the docs. Have you considered poll or ipoll?

There is a code comment here about threading. Have you considered using uasyncio V3 for concurrency? It is highly efficient, stable and much more lightweight than threading. I have tested substantial uasyncio applications running with good stability on ESP8266.
Peter Hinch
Index to my micropython libraries.

Post Reply