ota

Firmware updates over the WLAN (deploy_wlan is the client).

Endpoints (raw routes for webapi.handle), all requiring the header “Authorization: Bearer <password>”:

GET    /api/files         {name: sha256 hex} of the files on the board
PUT    /api/files/<name>  store the request body as <name>
DELETE /api/files/<name>  remove <name>
POST   /api/reset         restart once the answer is sent; an optional
                          body {"version": "0.2.2"} names the new version

Uploads go to “<name>.part” first and are renamed when complete, so an interrupted transfer leaves the old file intact. Names are restricted to plain module/data file names in the root directory.

Attributes

Classes

Updater

Handlers for the update endpoints listed in the module docstring.

Functions

valid_name(name)

Check for a plain file name like "main.py".

sha256_hex(chunks)

Return the SHA-256 of the concatenated byte chunks as hex text.

Module Contents

ota.EXTENSIONS = ('py', 'mpy', 'json', 'txt')
ota.NAME_CHARS = 'abcdefghijklmnopqrstuvwxyz0123456789_'
ota.MAX_NAME = 40
ota.MAX_VERSION = 40
ota.MAX_RESET_BODY = 200
ota.valid_name(name)

Check for a plain file name like “main.py”.

Allowed are lowercase letters, digits and “_”, a dot and one of EXTENSIONS.

ota.sha256_hex(chunks)

Return the SHA-256 of the concatenated byte chunks as hex text.

class ota.Updater(password, on_reset, root='')

Handlers for the update endpoints listed in the module docstring.

Every handler takes webapi’s raw-route arguments (rest, headers, length, chunks) and returns a JSON-able dict or a webapi.reply.

updated = []
removed = []
new_version = None
raw_routes()

Return the routes to register with webapi.handle.

list_files(rest, headers, length, chunks)

GET /api/files: the board’s files with their SHA-256.

put_file(name, headers, length, chunks)

PUT /api/files/<name>: store the body, replacing name at the end.

delete_file(name, headers, length, chunks)

DELETE /api/files/<name>: remove the file.

reset(rest, headers, length, chunks)

POST /api/reset: ask for a restart after the answer.