-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Web Workflow: network mDNS hostname often differs from local-device mDNS hostname (links & redirects don't work) #6869
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
Comments
Ok, this sounds like it's not yet properly handling mDNS Hostname conflict naming. While in theory, every device should have a unique name because of using the MAC address, this isn't always the case such as with an improperly setup network where multiple mDNS resolvers keep trying to resolve the same host. This is good info because there may need to be some updates to code.circuitpython.org to deal with this there too. |
@anecdata How many devices do you have on the network? Are you relying on web workflow to start wifi or are you starting it everytime yourself in code.py? |
Typically less than half a dozen CircuitPython devices with web workflow enabled. I don't have any collisions in the lower three octets of the MAC. Currently on devices where web workflow is enabled, web workflow starts up wifi (but I can do it either way, that's not strictly necessary - wifi has to be prepared to detect disconnection and re-connect anyway). |
This seems like we'll need to add the mac address to the instance name to make it unique. That may be causing the collision. The IDF public API doesn't provide a way to read back the "mangled" hostname or instance name unfortunately. That causes the mismatch. I'll explore more tomorrow. Thanks for the details! |
@anecdata Could you please give me more details of your network setup and what code is running on each device and what device it is? I was able to get the IDF to mangle the instance name but not the hostname. |
Not sure what all is useful to you... Multiple industrial-strength APs, all with the same SSID(s). Relatively complex home network wired / wifi, but robust. A lot of devices on the network, a bunch of Apple devices, some Raspberry Pi, myriad other things. There are a lot of CircuitPython devices, though only a handful running web workflow (and none anymore doing non-web-workflow mDNS). Typically I'm using Safari to interact with the web workflow pages, could be something to do with Mac cacheing. But accessing from Chromium on a Raspberry Pi also requires the numeric extension to the mDNS hostname (note that no devices ever show up in the My assumption has been that mDNS is really just between the device advertising its hostname and instance name on an IPv4:port, and the device trying to access it (no central name server). The web workflow devices are all ESP32-S2 (QT Py), now running 8.0.0-beta.3 or -beta.4. Four of them are running rudimentary adafruit_httpserver just for testing. Another is running a typical web client. Another is just chilling in the REPL. All are in Station mode, no APs. Typical web workflow display as follows: Here are other CircuitPython devices on your network: Adafruit QT Py ESP32S2-4 (cpy-d96468-22) The A cpy-aaeb36 hostname on one device's web workflow page shows up to other devices' web workflow pages as Adafruit QT Py ESP32S2 (cpy-aaeb36-666). Neradoc has also seen this behavior, various discussions on Discord. The behavior has been consistent throughout the 8.0.0-beta period. |
I've been doing tests with the following python code, adapted from the zeroconf library examples: from zeroconf import ServiceBrowser, ServiceListener, Zeroconf
from zeroconf import ZeroconfServiceTypes
class MyListener(ServiceListener):
def update_service(self, zc: Zeroconf, type_: str, name: str) -> None:
info = zc.get_service_info(type_, name)
print(f">>> Service {name} updated")
print(" ", info.server)
def add_service(self, zc: Zeroconf, type_: str, name: str) -> None:
info = zc.get_service_info(type_, name)
print(f"+++ Service {name} added")
print(" ", info.server)
zeroconf = Zeroconf()
listener = MyListener()
browser2 = ServiceBrowser(zeroconf, "_circuitpython._tcp.local.", listener)
try:
input("Press enter to exit...\n\n")
except KeyboardInterrupt:
pass
finally:
zeroconf.close() It detects and prints new MDNS services and updates.
If I add a second device, it's detected and so far so good.
But if then I do requests to circuitpython.local, using for example:
This only seems to happen if there is more than one device.
A few queries later:
|
Thank you both! I'll try again to replicate it today. The collision should only happen if two devices share a hostname (which they shouldn't.) Instance names can have this happen too but it isn't critical for the API to work. |
I think this change in the IDF will fix it: adafruit/esp-idf#9 Thanks to @anecdata for finding that it is caused by a collision of |
cpy-MAC hostnames were being mangled on circuitpython.local conflicts. Fixes #6869
This issue of spontaneously-incrementing mDNS hostnames (e.g., "blahblah-4") appears to be back in CP 9. CP 8.2.10 seems fine. @DonutCat spotted it, and there's been discussion on Discord last evening and prior in #help-with-circuitpython.
No
CIRCUITPY_WIFI_SSID="Redacted"
CIRCUITPY_WIFI_PASSWORD="Redacted"
CIRCUITPY_WEB_API_PASSWORD="passw0rd" (and a similar file on another S3) Device 34, after reset:
Device 84, after reset:
Try
First time is fine, but after redirecting from
It's incremented occasionally even without visiting Success to the incremented hostname:
Things get stranger if the hostname is changed in |
|
Uh oh!
There was an error while loading. Please reload this page.
CircuitPython version
Code/REPL
Behavior
From the network perspective, CircuitPython mDNS hostnames often have a hyphen and integer appended to the hostname. CircuitPython mDNS
server.find
code will expose these augmented hostnames (and instance names), and browsers and curl will find the devices using these augmented names.Anyone who has encountered things like
iPhone (3)
has encountered a related issue, I suspect.However, the device itself [currently] does not recognize itself with these augmented names. The Web API will report something like:
Hostname:
cpy-f66961
IP:
192.168.6.180
and clicking the hostname link on the Web API will fail.
Redirects also fail since the device doesn't answer to its nominal hostname:
or simply:
Description
When a device mDNS hostname has been augmented:
Additional information
Since the device knows its own IPv4 address, perhaps one solution could be to redirect to the IPv4 address instead of to the network-invalid mDNS local-device hostname, and not redirect at all if the entry URL is the IP address.
The text was updated successfully, but these errors were encountered: