Closed
Description
Let's add a way to work with CircuitPython over the (local) web!
How it should work
- First, load
http://circuitpython.local:7676
in a web browser. This uses mDNS to do a local domain lookup. - All CircuitPython devices on the network will reply with their IP. The first will win.
- The browser will then request / from that IP.
- The running webserver will see the
circuitpython.local
host and will return with a 302 redirect to the device's specific domain which will becpy-000000.local
where000000
is the last three bytes of the mac address. (mDNS is also used for thecpy-000000.local
lookup but only on device will reply.) - When the device gets a / request for its unique hostname it will return a small HTML page that loads Javascript from code.circuitpython.org or somewhere else that turns the page into a full editor.
- The editor can use a REST API or form-compatible upload to read and write files. The serial connection will be available over an insecure "websocket".
- Each device will also provide a
/peers
endpoint that will cause it to do a service discovery mDNS request that finds all other CircuitPython devices on the network. The web editor can then provide links to other devices directly.
Getting on WiFi
This method doesn't address how a device gets on the network to begin with. The simplest way is by editing WiFi config settings over USB mass storage. For devices without USB, a webserial based webpage can be provided to write credentials. See how wippersnapper does it.
TODO
- Check in mDNS support.
-
AddDepends on CIRCUITPY_WIFI_SSID.supervisor.disable_web_workflow()
to prevent WiFi from running outside of user code. - Add auto connect to configured WiFi.
wifi.radio.connect()
could be modified to save credentials. - Stop resetting WiFi completely between VM reloads. We want to keep the serial connection alive.
- Create internal HTTP server to:
- Redirect
circuitpython.local
requests to its unique hostname. - Reject requests with an
Origin
that isn't in an allowlist so regular insecure pages cannot access it. - Serve web editor stub at
/
- Serve
/peers
with other device info. - Provide REST API for reading and writing files.
- Redirect
-
Connect the serial input/output to a socket. Likely 23 to match telnet.Should be usable through an insecure websocket as well.