Skip to content

Add Web Workflow #6174

Closed
Closed
@tannewt

Description

@tannewt

Let's add a way to work with CircuitPython over the (local) web!

How it should work

  1. First, load http://circuitpython.local:7676 in a web browser. This uses mDNS to do a local domain lookup.
  2. All CircuitPython devices on the network will reply with their IP. The first will win.
  3. The browser will then request / from that IP.
  4. The running webserver will see the circuitpython.local host and will return with a 302 redirect to the device's specific domain which will be cpy-000000.local where 000000 is the last three bytes of the mac address. (mDNS is also used for the cpy-000000.local lookup but only on device will reply.)
  5. 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.
  6. 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".
  7. 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.
  • Add supervisor.disable_web_workflow() to prevent WiFi from running outside of user code. Depends on CIRCUITPY_WIFI_SSID.
  • 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.
  • Connect the serial input/output to a socket. Likely 23 to match telnet. Should be usable through an insecure websocket as well.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions