← index #9166PR #18784
Duplicate · high · value 4.368
QUERY · ISSUE

ESP32 mDNS support on Ethernet (class LAN)

openby mohnazemiopened 2022-08-31updated 2026-03-19
enhancementport-esp32

Hi guys,

I wanted to know if there is a specific reason why the mDNS is supported on the WLAN interface (via hostname config parameter) for ESP32 but it is not supported on the LAN/Ethernet interface. There seems to be no limitation in IDF's TCP/IP Adapter library for this, but the ESP32 port does not expose a config parameter to set this.

CANDIDATE · PULL REQUEST

ports/esp32/network_lan: Add mDNS support for Ethernet interface.

openby jetpaxopened 2026-02-05updated 2026-02-10
port-esp32

esp32: Add mDNS support for Ethernet (LAN) interface

Problem

Currently, mDNS responder is only initialized when WiFi connects (in network_wlan.c). When WiFi is disabled and only Ethernet is used, mDNS never starts, so the device is not discoverable via hostname.local.

This is problematic for IoT devices that use wired Ethernet connections and need to be discoverable on the local network without knowing their IP address.

Solution

Add mDNS initialization to network_lan.c when Ethernet gets an IP address via IP_EVENT_ETH_GOT_IP.

Changes

ports/esp32/network_lan.c:

  • Add #include "mdns.h"
  • Declare extern bool mdns_initialised to share state with network_wlan.c
  • Add new eth_ip_event_handler() that initializes mDNS when Ethernet obtains an IP
  • Register the handler for IP_EVENT_ETH_GOT_IP

ports/esp32/network_wlan.c:

  • Remove static from mdns_initialised to allow sharing with network_lan.c

Testing

  • Tested on ESP32-P4 with onboard Ethernet
  • Verified device is discoverable via mDNS when only Ethernet is active (WiFi disabled)
  • Verified mDNS still works when WiFi is active
  • Verified mDNS is not re-initialized if already started by WiFi

Notes

  • The mdns_initialised flag is shared between WiFi and Ethernet to prevent double-initialization
  • This follows the same pattern already used in network_wlan.c
  • Requires MICROPY_HW_ENABLE_MDNS_QUERIES or MICROPY_HW_ENABLE_MDNS_RESPONDER to be enabled

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied