Skip to main content

MDNS for micropython with service discovery support

Project description

Micropython MDNS

PyPi MIT licensed

Image showing service discovery

A pure Python implementation of MDNS and the Service Discovery protocol over MDNS for MicroPython.

Intended Audience

You should not use this library if you "just" require MDNS A record lookup and Host annoucement if there is already baked in support in your MicroPython distribution. This is for example the case with the default ESP32 MicroPython distribution since v1.12. This will be in all cases more resource efficient.

If you, however, require additional functionality like Service Discovery and Annoucement, you should use this library. It supports all functionality of existing basic MDNS implementations plus these features. You will not loose any functionality.

Installation

The library is available on PyPi and can be installed via upip.

import upip
upip.install("micropython-mdns")

Alternatively you can also use the new mip package manager:

import mip
mip.install("github:cbrand/micropython-mdns")

For using this library, native C type implementations of MDNS which use the MDNS service port need to be disabled. For example, this project has been developed on the ESP32 which MicroPython implementation per default has a basic MDNS implementation available. This does only support local A record lookups and A record responding of its own host address.

The releases page on this project publishes a firmware.mp.1.23.esp32.bin for MicroPython 1.23 with MDNS disabled and the mdns python module included in each release for easy usage. Other Micropython versions are also supported. Other boards are supported and you are welcome to add additional Dockerfiles in a PR which build the module compatible for other boards. All versions can also be built when having docker locally installed by running in the console the build command:

make build

Individually it is also possible to build the desired version via:

make compile-micropython-1-15
make compile-micropython-1-16
make compile-micropython-1-17
make compile-micropython-1-18
make compile-micropython-1-19
make compile-micropython-1-20
make compile-micropython-1-21
make compile-micropython-1-22
make compile-micropython-1-23

Refer to the config directory to see the configuration files when baking this into your own MicroPython ESP32 build.

For Raspberry Pi Pico support see the corresponding Dockerfile on how to compile it in linux Dockerfile.micropython.1.23.rp2.

Other MicroPython implementations might not require any changes inside of the firmware.

Usage

The library requires uasyncio to function. All handling is done asynchronously.

Examples on how to utilize the libraries can be found in the examples folder.

Reference

A basic API reference for the public API is inside of the REFERENCE.md.

Caveats

  • Depending on your MicroPython implementation, you must disable MDNS in the firmware.
    • For ESP32 use the Dockerfile for the specific Micropython version in the root directory.
    • For RPI Pico Micropython beginning with version 1.32 is supported since version 1.5.0 where you can see how to do it in the Dockerfile in the root directory.
  • Currently no support for IPv6 is implemented.
  • Depending how chatty the network is, service responders and discovery might require a lot of memory. If the memory is filled by the buffer of the underlying socket, the socket is closed and reopened which looses data. It, however, seems to work fine enough in tests on an ESP32 without external memory. Depending on the project size, a module with external RAM might be advisable.

License

The library is published under the MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

micropython-mdns-1.5.0.tar.gz (18.6 kB view details)

Uploaded Source

File details

Details for the file micropython-mdns-1.5.0.tar.gz.

File metadata

  • Download URL: micropython-mdns-1.5.0.tar.gz
  • Upload date:
  • Size: 18.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.8

File hashes

Hashes for micropython-mdns-1.5.0.tar.gz
Algorithm Hash digest
SHA256 a731aeb36ff1322cb12e13dca69fae9cee547496bbb962a641c7d6efcaa88129
MD5 2a46622448392fb1bc5c657e8baaab76
BLAKE2b-256 0780c8ed9ab1a2cb342908c0a0a886b5e2f19eac23c85323f8ec3717092ef0e4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page