Skip to content

examples/mdnsd: Create an event-based starter for mDNS daemon#3543

Open
tmedicci wants to merge 1 commit into
apache:masterfrom
tmedicci:feature/mdnsd_event
Open

examples/mdnsd: Create an event-based starter for mDNS daemon#3543
tmedicci wants to merge 1 commit into
apache:masterfrom
tmedicci:feature/mdnsd_event

Conversation

@tmedicci

Copy link
Copy Markdown
Contributor

Summary

Start the mDNS daemon based on the event of getting a new IP address for any of the system's network interfaces. This allows DHCP client to trigger the mDNS daemon after getting a new IP address, for instance.

Impact

Impact on user: Yes. Allow starting the mDNS daemon when a valid IP is available.

Impact on build: No.

Impact on hardware: No.

Impact on documentation: No.

Impact on security: No.

Impact on compatibility: No.

Testing

Taking esp32p4-function-ev-board:ethernet as an example:

Building

make distclean && ./tools/configure.sh -S esp32p4-function-ev-board:ethernet && kconfig-tweak --enable CONFIG_LIB_MDNS && kconfig-tweak --enable CONFIG_NETUTILS_MDNS && kconfig-tweak --enable CONFIG_NETUTILS_MDNS_DAEMON && kconfig-tweak --enable CONFIG_EXAMPLES_MDNSD && kconfig-tweak --enable CONFIG_NET_NETLINK && kconfig-tweak --enable CONFIG_NETLINK_ROUTE && kconfig-tweak --enable CONFIG_NET_IGMP && kconfig-tweak --enable CONFIG_LIBC_EXECFUNCS && kconfig-tweak --enable CONFIG_SYSTEM_HOSTNAME && kconfig-tweak --set-val CONFIG_NETUTILS_MDNS_STACKSIZE 4096 && kconfig-tweak --set-str CONFIG_EXAMPLES_MDNS_SERVICE "_http._tcp.local." && kconfig-tweak --set-str CONFIG_EXAMPLES_MDNS_SERVICE_PORT "80" && make olddefconfig -s -j && make -j

Running

Flash the device with esptool:

esptool.py -p /dev/ttyACM0 write_flash 0x2000 nuttx.bin

Then, detach the ethernet cable, reset the device, and check the device's serial terminal (with picocom, for instance).

Then, on NSH, set the hostname and start the mdnsd_event:

nsh> hostname esp32p4
nsh> mdnsd_event &
mdnsd_event [8:100]
nsh> mdnsd_event: waiting for network address event

Then, attach the ethernet cable in a network that provides a DHCP server and, on NuttX, run renew eth0 to get a new IP address:

nsh> renew eth0
mdnsd_event: address set, starting mDNS
Local IPv4 address: 10.0.10.50
Opened 1 socket for mDNS service
Service mDNS: _http._tcp.local.:80
Hostname: esp32p4
Sending announce

Results

As soon as a new IP address is set to the eth0, the mDNS daemon will start. Test it on the host PC:

$ avahi-browse -r -t _http._tcp
+ enp0s13f0u1u4u4 IPv4 esp32p4                                       Web Site             local
= enp0s13f0u1u4u4 IPv4 esp32p4                                       Web Site             local
   hostname = [esp32p4.local]
   address = [10.0.10.50]
   port = [80]
   txt = ["test=1" "other=value"]

Start the mDNS daemon based on the event of getting a new IP
address for any of the system's network interfaces. This allows
DHCP client to trigger the mDNS daemon after getting a new IP
address, for instance.

Signed-off-by: Tiago Medicci <tiago.medicci@espressif.com>

@acassis acassis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tmedicci please update the Documentation about mDNS daemon to include it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants