Skip to content

Latest commit

 

History

43 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

  • IP address resolution by host name
  • IP address resolution by service name

This is a quick example of each.

Software requirements

ESP-IDF V5.0 or later.
ESP-IDF V4.4 release branch reached EOL in July 2024.
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 hostnames using ping in Linux

I used the Debian11.

  • Edit /etc/nsswitch.conf
hosts:          files mdns4_minimal [NOTFOUND=return] dns
  • Execute ping
$ ping {mDNS host name}.local

Image Image

Resolving mDNS hostnames using ping in Windows

I used the Windows10 command prompt.
Image Image

Resolving mDNS using avahi-utils in Linux

  • Install avahi-utils
$ sudo apt install avahi-utils
  • Translate one or more fully qualified host names into addresses.
$ avahi-resolve -n esp32-mdns1.local
esp32-mdns1.local       192.168.0.158
  • Use Avahi daemon to browse all mDNS network services.
$ avahi-browse -art
+ enp2s0 IPv4 ESP32 with mDNS                               _service_49876._udp  local
= enp2s0 IPv4 ESP32 with mDNS                               _service_49876._udp  local
   hostname = [esp32-mdns-05C634.local]
   address = [192.168.0.158]
   port = [49876]
   txt = []
  • Use the Avahi daemon to browse specific mDNS network services.
$ avahi-browse -rt _service_49876._udp
+ enp2s0 IPv4 ESP32 with mDNS                               _service_49876._udp  local
= enp2s0 IPv4 ESP32 with mDNS                               _service_49876._udp  local
   hostname = [esp32-mdns-05C634.local]
   address = [192.168.0.158]
   port = [49876]
   txt = []

For more information is here.

About

Example of IP address resolution using mDNS

Topics

Resources

Stars

7 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages