Skip to content

Web Workflow: no circuitpython.local (Pico W, 9.0.1) #9124

Closed
@studiostephe

Description

@studiostephe

CircuitPython version

Adafruit CircuitPython 9.0.1 on 2024-03-27; Raspberry Pi Pico W with rp2040

Code/REPL

#code.py (provided by anecdata in the discord)
import time
import os
import wifi
import ipaddress
import socketpool
import mdns

MDNSFINDTIMEOUT = 5

ssid = os.getenv('WIFI_SSID')
password = os.getenv('WIFI_PASSWORD')

pool = socketpool.SocketPool(wifi.radio)

def connect():
    # to connect in case CP8 web workflow hasn't already, or to reconnect if disconnexted
    if not wifi.radio.connected:
        print (f"Connecting to wifi AP... ", end="")
        wifi.radio.connect(ssid, password)
        print (f"{wifi.radio.ipv4_address}")

print(f"Starting mDNS server...\n")
m = mdns.Server(wifi.radio)

while True:
    connect()
    print(f"Finding mDNS hosts from {wifi.radio.ipv4_address}...\n")

    try:
        host = "circuitpython.local"
        print(f"{host}")
        # ESP mDNS TTL seems to be 2 minutes
        # no difference in result with wrong port
        print(f"{ipaddress.ip_address(pool.getaddrinfo(host, 80)[0][4][0])}")
        print()
    except OSError as e:
        print(f"OSError: {e}")

    for service in m.find(service_type="_circuitpython", protocol="_tcp", timeout=MDNSFINDTIMEOUT):
        print(f"{service.service_type} {service.protocol}")
        print(f"{service.instance_name}")
        localname = ".".join((service.hostname, "local"))
        print(f"{localname}:{service.port}")
        print(f"{service.ipv4_address}:{service.port}")
        print()
    time.sleep(10)


#and my settings.toml file contains:
CIRCUITPY_WIFI_SSID = "MyNetwork"
CIRCUITPY_WIFI_PASSWORD = "mypassword"
CIRCUITPY_WEB_API_PASSWORD= "jk"

Behavior

code.py output:
Starting mDNS server...

Finding mDNS hosts from 10.0.1.55...

circuitpython.local
socket_resolve_host() returned -2
OSError: (-2, 'Name or service not known')

Description

The Pico W joins the network without issue, and can be accessed via IP or individual hostname (cpy-xxxxxx.local), but not via circuitpython.local

Access via circuitpython.local is important for when the device's REPL is not physically accessible via USB (device installed somewhere deep), and the IP is not known or knowable in advance (not my network)

Additional information

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions