#romkey he him and anecdata I think that

1 messages · Page 1 of 1 (latest)

quick rose
#

@eager bridge and @analog field: More mDNS testing has revealed that I am apparently always getting mDNS server setting correctly, even when I receive the Out of MDNS service slots warning (I am not sure which of the mdns_server commands issue this error). Good news is that mDNS setting seems to be working correctly, but sometimes reports that it has failed to connect when in fact it has.

analog field
#

it would be useful if you can find a repeatable procedure to replicate the Out of MDNS service slots ...in this case what is reporting that it can't connect?

quick rose
#

Will try to do some testing as time permits...

quick rose
# analog field it would be useful if you can find a repeatable procedure to replicate the `Out ...

@analog field and @eager bridge: Some further testing on the mDNS issue. I am not sure that I have a repeatable scenario, but I also think that the way I am trying to use mDNS might be confusing the mDNS setup. My application is a remote sensor which logs measurements to an Adalogger but will connect to wifi if available. I test for a wifi signal by first doing the following:

# If you are using a Pico W and you want to use the
# webserver, which also uses ntp to set the RTC, the
# the following will evalute to True
if wifi.radio.connected:
    print("I see a wifi signal...going to try to connect...")
    webserver = True
else:
    webserver = False

I then later attempt to setup mDNS, but fall-back to fixed address assignment if mDNS fails:

if webserver:
    try:
        print("Connecting to WiFi via MDNS...")
        mdns_server = mdns.Server(wifi.radio)
        mdns_server.hostname = "mangum-rover"
        # The following assumes that web workflow has been assigned to a port ot
her than 80 (like 8080)
        mdns_server.advertise_service(service_type="_http", protocol="_tcp", por
t=80)
    except RuntimeError as e:
        print('MDNS setting failed:',str(e))
        print("Connecting to WiFi with static address...")
        #  set static IP address
        ipv4 =  ipaddress.IPv4Address("192.168.50.212")
        netmask =  ipaddress.IPv4Address("255.255.255.0")
        gateway =  ipaddress.IPv4Address("192.168.50.1")
        wifi.radio.set_ipv4_address(ipv4=ipv4,netmask=netmask,gateway=gateway)

Since while testing I am doing this repeatably, I am finding that I am always succeeding to get an mDNS address, which is in many cases the same as the fixed address I have been assigning the device to in previous testing. I think that the fact that I am repeatedly re-assigning IP mDNS during testing is the part that is confusing the mDNS assignment, which results in an incorrect Out of MDNS service slots message.

#

In the end it is a slightly incorrect warning that is the only problem with using mDNS in my setup.

analog field
#

I only tested briefly, but mDNS slot should be available again after a reload or reset, so if this is only done once in code, there may still be an issue lurking.

#

You could actually do both: set up mDNS and fixed IP address, they are separate protocols and can co-exist.

eager bridge
#

The way the underlying implementation works, the call to advertise a service returns "Out of MDNS service slots" for any error return from the underlying mDNS implementation in LWIP.

Here's the code that indicates "out of slots"

Here's the code that actually implements mDNS

You can see in the second code there are several conditions that can cause an error:

  • no network interface
  • name too long
  • service too long
  • protocol isn't TCP or UDP
  • service list full (FINALLY! "out of slots")
  • couldn't allocate memory for the new service list entry

It's not an easy fix; LWIP can output the error message but it doesn't actually return an indication of the real error to the mDNS code in CircuitPython. So this isn't CircuitPython's fault, although it might better indicate "generic mDNS error" or something... unfortunately the mDNS implementation in LWIP just doesn't indicate which of these errors happened.

GitHub

CircuitPython - a Python implementation for teaching coding with microcontrollers - adafruit/circuitpython

#

For some reason the previews lost the line number, but the links should take you to the right place in the code

#

Maybe having the real list of conditions that indicate this error may help track it down

quick rose
quick rose
# eager bridge Maybe having the real list of conditions that indicate this error may help track...

Thanks for digging into this. Further testing my setup, which involves multiple code reloads and the occasional board reset (power cycle), does not really add any clarity. The good news is that once I used a valid hostname, I am always able to connect via mDNS. Unfortunately, about half of the time I get the "out of slots" error when I try to assign mDNS. I guess these could be instances where I am not rebooting the board, so the mDNS assignment finds that I am already assigned an mDNS address?

eager bridge
#

That seems a likely explanation, would be very easy to do an experiment to confirm that just reloading the REPL isn’t enough to clear mDNS.

quick rose