cbrand / micropython-mdns

MDNS implementation for MicroPython with Service Discovery
MIT License
53 stars 12 forks source link

mDNS on RPi Pico #9

Closed ondrej1024 closed 1 year ago

ondrej1024 commented 1 year ago

I am trying to run the service_responder.py example program on a RPi Pico with Ethernet port and get this error:

OSError: [Errno 98] EADDRINUSE

Does this mean the mDNS service is already active in the MP firmware? If so, should I see the Pico advertising its host name in the local network? I tried with an mDNS browser but could not find the Pico.

MP version is this:

MicroPython v1.19.1-910-g4937174b4 on 2023-03-01; W5500-EVB-Pico with RP2040

Thanks.

cbrand commented 1 year ago

Hello,

I am pretty sure this has to do with MicroPython having a default MDNS implementation on the RPi Pico already activated and you need to disable it before being able to use MDNS for service discovery.

However, the implementation has currently only been tested with ESP32 configuration and it has recently pointed out to me that it will likely not work on other implementations: https://github.com/cbrand/micropython-mdns/issues/8#issuecomment-1443703889

If you only want to see / have an address in WiFi for you device and not any kind of service discovery you might not want and/or need to use this library: https://github.com/cbrand/micropython-mdns#intended-audience

The hostname if you do a MDNS lookup should already advertise itself on the network: https://github.com/micropython/micropython/commit/2ccf030fd1ee7ddf7c015217c7fbc9996c735fd1 (This is for esp32 but I think the rpi pico also has something similar when this error message comes up).

ondrej1024 commented 1 year ago

I really cannot find any documentation or source code about this MDNS service built into the Pico Micropython build. And avahi-discover doesn't find the Pico advertising itself in the network.

So my guess is it actually isn't there and your MDNS package doesn't run on the Pico either (for the reasons you mentioned), so the EADDRINUSE it causes might just be misleading.

cbrand commented 1 year ago

avahi-discover as far as I am aware of is searching for services not for hosts itself: https://linux.die.net/man/1/avahi-browse

What I presume is going on that it registers its host name (A Record) and that is not seen by avahi-discover (which is scanning for SRV records). You can see if the host name on MDNS is available if you know it by just doing ping {host_name}.local or also skip the local. This should be resolvable. The EADDRINUSE clealry states that there is something in the code base listening on PORT 5353 which is 95% surely an MDNS service which is embedded in the deployment of Pico.

ondrej1024 commented 1 year ago

You can see if the host name on MDNS is available if you know it by just doing ping {host_name}.local or also skip the local.

Yes, I tried that, but without success. I tried the hostname which I get from network.hostname() on the Pico.

The EADDRINUSE clealry states that there is something in the code base listening on PORT 5353

I also did a port scan of the Pico but this didn't find any open ports :roll_eyes:

cbrand commented 1 year ago

Alright sorry about that then. I think without having a Pico here myself I can not help you any further.

Hope you'll find the issue and figure it out! Closing this for now. Feel free to open a new issue once you've debugged the base issues on the Pico. I would like to add support for the library for other systems, too so would be eager to hear if you get it to run and if not what error message you receive.

Good luck :)

captncraig commented 1 year ago

I was able to get around that error by compiling micropython myself, and setting the include for LWIP_MDNS_RESPONDER to 0.

I got past the EADDRINUSE issue at least. Still trying to successfully resolve a service name.

ondrej1024 commented 1 year ago

If anyone is interested, here is the explanation why the MDNS port on the Pico is used by default but it is actually not advertising anything: https://github.com/micropython/micropython/issues/8946

RoelantM commented 8 months ago

@captncraig i just started my own project (my first), on the raspberry pi pico wh, i am facing the same issue. But i lack the knowlegde how i can overwrite this, like you said. Can you help me out how to get this working?

arag0re commented 8 months ago

@captncraig i just started my own project (my first), on the raspberry pi pico wh, i am facing the same issue. But i lack the knowlegde how i can overwrite this, like you said. Can you help me out how to get this working?

arag0re commented 8 months ago

fixed Micropython for PicoW

arag0re commented 8 months ago

With the tip from @captncraig i can successfully get a txtService. Thank man :)

arag0re commented 8 months ago

also why is this issue closed ? @cbrand This is not fixed at all. Would be way easier to find, if its an open issue!

cbrand commented 8 months ago

@arag0re Hey :) Sorry but this is a bit out of scope of the library.

As this is a build issue for one specific device it makes more sense to me to track it outside of the actual library, as the library in itself is functional.

So keeping the issue open makes the management of this very hard, as I do not have any affiliation with the actual MicroPython project which seems to be the main issue facing here.

There is a caveats section in the README outlining that this is something which might be required for the individual ports for differnt boards to be done (Disabling MDNS functionality): https://github.com/cbrand/micropython-mdns?tab=readme-ov-file#caveats

I think with the information you all provided though I can also release a new version which does not only provide builds for the ESP32 but also for the RPi Pico in the next release and link this issue to make it easier findable in the future so that hopefully more people can benefit from the research done in this ticket.

vinux84 commented 7 months ago

Hi guys, after implementing @arag0re fix and installing mDNS from @cbrand I was able to use cbrands example for mDNS responder and was able to ping my pico at hostname.local

Can anyone provide any direction on how to integrate this into a web server? I'm fairly new to this and there is little documentation on how to implement this mDNS package into a webserver using micropython. I'm just wanting to be able to access my pico's web page using hostname.local

cbrand commented 3 days ago

I added into the release pipeline for 1.5.0 an RPi Pico build: https://github.com/cbrand/micropython-mdns/releases/tag/1.5.0

In the future all releases and new MicroPython versions will also be released for RPi Pico.