Skip to content

Web Workflow: network mDNS hostname often differs from local-device mDNS hostname (links & redirects don't work) #6869

@anecdata

Description

@anecdata

CircuitPython version

Adafruit CircuitPython 8.0.0-beta.0 on 2022-08-18; Adafruit QT Py ESP32S2 with ESP32S2

Code/REPL

# From another device on the network, "augmented" names are found:
m = mdns.Server(wifi.radio)
for service in m.find(service_type="_circuitpython", protocol="_tcp", timeout=5):
        print(service.instance_name)
        print(service.hostname)
        print(f"{service.ipv4_address}:{service.port}")
"""
Adafruit QT Py ESP32S2-5
cpy-f66961-281
192.168.6.180:80
"""

# So these work:
# curl -v -L http://192.168.6.180/cp/devices.json
# curl -v -L http://cpy-f66961-281/cp/devices.json

# But the device itself does not seem to know about the augmented name:
print(m.hostname)
# cpy-f66961
print(m.instance_name)
# cpy-f66961
# NOTE: this is completely different from the Instance Name reported from other devices using .find

# So this does not work:
# curl -v -L http://cpy-f66961.local/cp/devices.json

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:

% curl -v -L http://circuitpython.local/cp/devices.json
*   Trying 192.168.6.180:80...
* Connected to circuitpython.local (192.168.6.180) port 80 (#0)
> GET /cp/devices.json HTTP/1.1
> Host: circuitpython.local
> User-Agent: curl/7.79.1
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 307 Temporary Redirect
< Connection: close
< Content-Length: 0
< Location: http://cpy-f66961.local/cp/devices.json
< Access-Control-Allow-Credentials: true
< Vary: Origin, Accept, Upgrade
< Access-Control-Allow-Origin: 
< 
* Closing connection 0
* Issue another request to this URL: 'http://cpy-f66961.local/cp/devices.json'
* Could not resolve host: cpy-f66961.local
* Closing connection 1
curl: (6) Could not resolve host: cpy-f66961.local

or simply:

% curl -v -L http://cpy-f66961.local/cp/devices.json 
* Could not resolve host: cpy-f66961.local
* Closing connection 0
curl: (6) Could not resolve host: cpy-f66961.local

Description

When a device mDNS hostname has been augmented:

  1. the "Hostname:" link on the Web API web page will fail
  2. the File REST API breaks

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions