Skip to content

rp2 - mDNS not working #15297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
massimosala opened this issue Jun 17, 2024 · 9 comments
Closed

rp2 - mDNS not working #15297

massimosala opened this issue Jun 17, 2024 · 9 comments

Comments

@massimosala
Copy link

massimosala commented Jun 17, 2024

Port, board and/or hardware

rp2040

MicroPython version

mp 1.22.2

Reproduction

There isn't a code sample, the feature is built-in in the firmware.

Expected behaviour

The micro working on WiFi (STA_IF or AP_IF) should respond to mDNS queries.

Observed behaviour

Not working.

Additional Information

I code in Python a mDNS and LLMNR responder.

It works like a charm on the esp8266: the micro, with its hostname xxxxxx.local is recognized by any browser (browsers use mDNS) and by ping (on microsoft pc, ping use also LLMNR).

Running my module on the rp2:

  • LLMNR works
  • MDNS doesn't work: when my code binds a UDP socket to the local port 5353, mp raises an exception

[Errno 112] EADDRINUSE

So the firmware has already taken the mDNS port ... is trying to do something... but mDNS isn't working.

Code of Conduct

Yes, I agree

@massimosala
Copy link
Author

Tested also with MP 1.23.0 : not resolved

@felixdoerre
Copy link
Contributor

On rp2 MDNS is enabled to be provided by lwip: https://github.com/micropython/micropython/blob/master/ports/rp2/lwip_inc/lwipopts.h#L35. Maybe you want to compile your own firmware with that flag disabled?

@mseminatore
Copy link

mseminatore commented Nov 19, 2024

I am looking for a fix for this as well. I would prefer not to build my own custom firmware and use something like slimdns. I will have more of a look at the code to see why LWIP is not working once I get a working local build.

@mseminatore
Copy link

mseminatore commented Nov 19, 2024

@felixdoerre

On rp2 MDNS is enabled to be provided by lwip: https://github.com/micropython/micropython/blob/master/ports/rp2/lwip_inc/lwipopts.h#L35. Maybe you want to compile your own firmware with that flag disabled?

But I think the point being made is that LWIP is not providing a working mDNS implementation on rp2 and yet is holding onto the port. Could that perhaps be a result of a build order of operations with the LWIP library and the rp2 lwipopts.h? Or some missing glue code?

It is fair if mDNS support is not yet implemented for the rp2 port. But it seems very much like a bug for rp2 lwipopts.h to define the following if mDNS support is not properly included/implemented in the fw:

#define LWIP_DNS_SUPPORT_MDNS_QUERIES   1
#define LWIP_MDNS_RESPONDER             1

I also notice that the following lines are not included in the rp2 mpconfigport.h file:

#ifndef MICROPY_HW_ENABLE_MDNS_QUERIES
#define MICROPY_HW_ENABLE_MDNS_QUERIES      (1)
#endif

#ifndef MICROPY_HW_ENABLE_MDNS_RESPONDER
#define MICROPY_HW_ENABLE_MDNS_RESPONDER    (1)
#endif

The ESP port has code in network_wlan.c that specifically calls mDNS initialization and provides some handling code. The rp2 port does not seem to have similar code.

@mseminatore
Copy link

@felixdoerre Looking over the codebase some more I think I might see the issue. In ports/rp2/main.c:125 there is this code:

    #if MICROPY_PY_LWIP
    // lwIP doesn't allow to reinitialise itself by subsequent calls to this function
    // because the system timeout list (next_timeout) is only ever reset by BSS clearing.
    // So for now we only init the lwIP stack once on power-up.
    lwip_init();
    #if LWIP_MDNS_RESPONDER
    mdns_resp_init();
    #endif
    #endif

Per the LWIP docs, the mdns_resp_init() opens the mDNS socket/port, but mDNS is not activated on a network interface until a call to mdns_resp_add_netif() which is not called anywhere that I can find. If accurate, RP2 basically has only a partial mDNS implementation and LWIP_MDNS_RESPONDER should probably be 0 by default until/unless a complete implementation is provided.

If someone can point me to where the netif is initialized in the RP2 port I am happy to build up a PR.

@mseminatore
Copy link

@dpgeorge any comment on the default behavior? Seems like mDNS should either be fully functional or disabled by default. Happy to contribute a PR if appropriate.

@projectgus

This comment was marked as outdated.

@projectgus

This comment was marked as outdated.

@jonnor jonnor added the port-rp2 label Mar 3, 2025
dpgeorge pushed a commit to mseminatore/micropython that referenced this issue Apr 3, 2025
The rp2 port has an incomplete mDNS implementation.  The code in `main.c`
calls `mdns_resp_init()` which opens the UDP socket for mDNS.  However, no
code in the cyw43 driver makes the proper calls to `mdns_resp_add_netif()`
and `mdns_resp_remove_netif()` to send the announce packets.  The wiznet5k
driver does make these calls and was used as a model for these changes.

This commit attempts to address this by very small changes to the
`ports/rp2/cyw43_configport.h` file.  The change uses new cyw43 driver
hooks to map the driver macros `CYW43_CB_TCPIP_INIT_EXTRA` and
`CYW43_CB_TCPIP_DEINIT_EXTRA` to the appropriate lwIP mDNS calls.

Fixes issue micropython#15297.

Signed-off-by: Mark Seminatore <nebula_peeps4t@icloud.com>
@dpgeorge
Copy link
Member

dpgeorge commented Apr 3, 2025

Should be fixed by f96417d (although looking up mDNS on the Pico W in AP mode might not work yet).

@dpgeorge dpgeorge closed this as completed Apr 3, 2025
VynDragon pushed a commit to VynDragon/micropython that referenced this issue Apr 6, 2025
The rp2 port has an incomplete mDNS implementation.  The code in `main.c`
calls `mdns_resp_init()` which opens the UDP socket for mDNS.  However, no
code in the cyw43 driver makes the proper calls to `mdns_resp_add_netif()`
and `mdns_resp_remove_netif()` to send the announce packets.  The wiznet5k
driver does make these calls and was used as a model for these changes.

This commit attempts to address this by very small changes to the
`ports/rp2/cyw43_configport.h` file.  The change uses new cyw43 driver
hooks to map the driver macros `CYW43_CB_TCPIP_INIT_EXTRA` and
`CYW43_CB_TCPIP_DEINIT_EXTRA` to the appropriate lwIP mDNS calls.

Fixes issue micropython#15297.

Signed-off-by: Mark Seminatore <nebula_peeps4t@icloud.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants