cbrand / micropython-mdns

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

Service Discoverty was working fine, but no longer. #16

Closed shaneapowell closed 7 months ago

shaneapowell commented 8 months ago

1st of all. thanks for this library. It's really made my little IOT project act a lot more professional.

Let me see if I can explain what strangeness I'm seeing.

Specifically, I'm setting them up with ServiceDiscovery enabled, so I can easily find them in my mobile app. I have 3 prototypes of my project on my network, and they have been working perfectly for nearly a year. But, just about a month ago I noticed they slowly started .. not being discoverable in my app. One day I could see all 3. A few days later only 2.. then 1. Now none.

I went through a multitude of various debugging steps.
rebooting, re-flashing, re-compiling micropython, updating my esp-idf to 5.0 and micropython from 1.20 to 1.22 I tried increasing the MAX_PACKET_SIZE value in the constants.py. Not knowing what to set it to, I just tried 2700. Initially, I thought that fixed it, as the 1st device immediately started advertising. But, the other 2 did not.
And, after a restart, the 1st device no long advertises either.

I am running a custom built micropython 1.22.1 firmware with it's mdns disabled, on a Seeed Studio Xaio ESP32S3 with SPIRAM (8M).

One thing that is especially peculiar, is that if I leave the devices running for some time (, one of them will randomly respond to ptr requests, and announce itself. But, it will only do it once and then go silent again.

I have been using both my app that looks for a specific protocol name. As well as avahi-browse (I run Linux on my workstation)

The devices in question are getting DHCP addresses , and are available on my network if I manually navigate to them.

Nothing has changed on my network or wifi, other than just peoples phones coming and going. I am running a Ubiquity wifi , with a pair of access points.

I'm hoping you can help me diagnose what has happened that seems to be blocking my devices from responding. At least direct me down some more troubleshooting ideas.

Cheers Shane

shaneapowell commented 8 months ago

Update with added info. I tried adding a ndms_service_add line witin the micropython code. Built and flahsed that firmware. The service showed up immediately in my avahi-browser termina. But, then .. eventually fell off and never returned. Not sure if that is relevant or not.

cbrand commented 7 months ago

Hey,

I sadly have not really a lot of input to give there. The only thing which might explain this is the memory issue described in the caveats in https://github.com/cbrand/micropython-mdns?tab=readme-ov-file#caveats . But this is just a hunch and not anything I can vouch for.

What I would require to even start taking a look is when you try to get the mdns record to have a pcap record from the network on port 5353 to be able to see how / if the micropython controllers react to any traffic.

You could do this with tcpdump:

tcpdump -s 0 port 5353 -w mycap.pcap
shaneapowell commented 7 months ago

I'm still fiddling through this issue, (time permitting of course). here is an interesting finding.

I setup a fresh wifi access point on my network all by itself. I set it up as if my network was the internet (double NATd). So this APs WAN port, is just on my network, but it has it's own DNS and DHCP and wifi creds, etc. When I connect my micropython device to this wifi, the mdns just works. And keeps working.
So far at least. It's been up now for a few hours, while on my main wifi, it drops the MDNS in a few moments. It seems to me that something on my network is causing the mdsn to stop broadcasting/responding. I have a good number of IOT devices on my wifi, if I run a service-discovery utility on my phone on my main wifi, it finds a bunch of them. If I run a Bonjour discovery, I get even more. so, I don't think it's something on my wifi that is blocking all MDNS packets. Just something unique to this little project.

I'm beginning to think that your theory about it being a memory issue might be onto something. My network is pretty chatty. I am using an 8M module, so I have access to plenty of RAM, I think. I have been watching the output to stdout to see if I can spot any memory related errors, but nothing yet.

Cheers Shane.

shaneapowell commented 7 months ago

Another very interesting finding. I tried going back with a stock micropython firmware. Where the mdns is enabled at the firmware level. Same thing happens to it. The device shows up on service discovery initially. But, within about 30-60 seconds, it will disappear. Again, this is only on my main wifi. Not the separate AP I tried setting up above. Something very strange is goign on.

shaneapowell commented 7 months ago

Solved! As I should have guessed. It was my wifi/lan that was the issue. Somehow, my ubiquiti access points are just not being nice when various mdns enabled devices connect to different APs. I turned off one of my APs, forcing all clients to connect to the other, and magically, all mdns issues were resolved. Flipped which AP was enabled, and the same. All mdns resolved. Turn them both on, and as long as all devices happen to connect to the same AP, all mdns stuff works. As soon as one connects to the other AP, things start to go sideways. Thanks for your help cbrand.