Skip to content
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

mDNS on RPi Pico #9

Closed
ondrej1024 opened this issue Mar 6, 2023 · 14 comments
Closed

mDNS on RPi Pico #9

ondrej1024 opened this issue Mar 6, 2023 · 14 comments

Comments

@ondrej1024
Copy link

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
Copy link
Owner

cbrand commented Mar 6, 2023

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: #8 (comment)

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: micropython/micropython@2ccf030 (This is for esp32 but I think the rpi pico also has something similar when this error message comes up).

@ondrej1024
Copy link
Author

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
Copy link
Owner

cbrand commented Mar 6, 2023

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
Copy link
Author

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 🙄

@cbrand
Copy link
Owner

cbrand commented Mar 6, 2023

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 :)

@cbrand cbrand closed this as completed Mar 6, 2023
@captncraig
Copy link

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
Copy link
Author

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:
micropython/micropython#8946

@RoelantM
Copy link

@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
Copy link

arag0re commented Feb 4, 2024

@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?

  • Clone the repo from https://github.com/micropython/micropython.
  • go to repo-folder cd micropython
  • edit the include for LWIP_MDNS_RESPONDER to 0. via nano nano ./ports/rp2/lwip_inc/lwipopts.h and replace the 1 in line 35 after #define LWIP_MDNS_RESPONDER to a 0, then press ctrl + x to save and hit enter to confirm saving.
  • go to mpy-cross folder and build it cd mpy-cross && make
  • go to rp2 port folder, install external deps and built pico-uf2 file with cd ../ports/rp2 && make BOARD=RPI_PICO_W submodules && make BOARD=RPI_PICO_W

@arag0re
Copy link

arag0re commented Feb 4, 2024

@arag0re
Copy link

arag0re commented Feb 4, 2024

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

@arag0re
Copy link

arag0re commented Feb 5, 2024

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
Copy link
Owner

cbrand commented Feb 6, 2024

@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
Copy link

vinux84 commented Feb 28, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants