nopnop2002 / esp-idf-mdns

Example of IP address resolution using mDNS
MIT License
5 stars 1 forks source link
esp-idf esp32 mdns name-resolution

esp-idf-mdns

How to IP address resolution by mDNS.

Since ESP-IDF Ver5, mDNS has been moved from built-in library to this IDF component registry.
Accordingly, the mDNS official example has been removed from the ESP-IDF repository.
The official repository for mDNS is here.

The official repository comes with example code, but it's a bit confusing.
There are two methods for IP address resolution using mDNS.

This is a quick example of each.

Software requiment

ESP-IDF V4.4/V5.x.
ESP-IDF V5.0 is required when using ESP32-C2.
ESP-IDF V5.1 is required when using ESP32-C6.

Hardware requirements

Requires two ESP32s.

IP address resolution by host name

To find the IP address, you need to know the mDNS hostname.
mDNS hostnames must be unique within the network.
Write query-host1 to ESP32#1 and query-host2 to ESP32#2.

ESP32#1

The mDNS name for this project is esp32-mdns1.local.
Then look for the the mDNS name of esp32-mdns2.local.

git clone https://github.com/nopnop2002/esp-idf-mdns
cd esp-idf-mdns/query-host1
idf.py menuconfig
idf.py flash

ESP32#2

The mDNS name for this project is esp32-mdns2.local.
Then look for the mDNS name of esp32-mdns1.local.

cd esp-idf-mdns/query-host2
idf.py menuconfig
idf.py flash

Configuration

config-top config-app-host

Screen shot

screen-host

IP address resolution by service name

To find the IP address, you need to know the service name.
Multiple hosts with the same service name are allowed within the network.
If you give two nodes the same service name, they can find each other.
This is useful when doing P2P communication with UDP.
Write query-service to ESP32#1 and ESP32#2.
Each mDNS hostname is generated from MAC address.
Therefore, the other party's mDNS host name is completely unknown.

ESP32#1

This project looks for the service name of _service_49876._udp.

git clone https://github.com/nopnop2002/esp-idf-mdns
cd esp-idf-mdns/query-service
idf.py menuconfig
idf.py flash

ESP32#2

This project looks for the service name of _service_49876._udp.

cd esp-idf-mdns/query-service
idf.py menuconfig
idf.py flash

Configuration

config-top config-app-service

Screen shot

screen-service

Resolving mDNS using avahi-utils

$ sudo apt install avahi-utils

For more information is here.