DocsReferenceAPI reference
Apps and macros
Lua apps on the device, one running at a time: list, start, stop, start on boot, delete, message, read events and run code in the app. The macro player is the app macro, controlled through POST /v1/apps/msg
GET /v1/apps#
Apps, the running app, start on boot, memory
Lists the apps under /apps in storage (ones with a broken manifest too, with error), plus the runtime state. Changes nothing
Reply#
Apps and runtime state
| Field | Type | Required | Values | Range | Description |
|---|---|---|---|---|---|
ok | boolean | Yes | true | Always true | |
apps | object[] | Yes | Apps in storage | ||
id | string | Yes | App ID (folder name) | ||
name | string | ≤ 64 bytes | Name (manifest name; defaults to the id) | ||
version | string | ≤ 32 bytes | Version (manifest version; may be empty) | ||
perms | string[] | hid | Permissions: only hid so far (keys through the app source) | ||
auto | boolean | Yes | Starts on boot | ||
size | integer | Yes | ≥ 0 | Total bytes of the folder's files | |
error | string | bad_manifest | Broken manifest: missing, not JSON or breaking the rules | ||
running | string | null | Yes | ID of the running app (also in the error state); null if none | ||
state | string | Yes | stopped running error | stopped: none running; running; error: halted on an error (timers stopped, UI kept) | |
error | string | null | Yes | Text of the latest error (Lua error and location); null if none | ||
mem | integer | Yes | ≥ 0 | Lua memory used by the app (bytes) | |
mem_max | integer | Yes | Lua memory limit per app (bytes) | ||
started_ms | integer | Yes | ≥ 0 | Uptime in ms when the app started; 0 if none running | |
auto | string | null | Yes | App started on boot; null if none |
Error codes#
| Status | Code | Description |
|---|---|---|
503 | no_storage | Storage is not mounted. See GET /v1/logs |
For errors any endpoint can return, see Common errors.
POST /v1/apps/start#
Start an app (the macro player is macro)
Stops the running app, reads the manifest and runs the entry file's top level (limit 1000 ms), replying when it finishes. A top-level error still returns HTTP 200, with ok false and error app_error; the app stays in the error state. A manifest with the hid permission opens the app source
Request body#
application/json
Names one app
| Field | Type | Required | Values | Range | Description |
|---|---|---|---|---|---|
id | string | Yes | pattern ^[a-z0-9_-]{1,24}$ | App ID: 1–24 of a-z 0-9 _ -, the folder name under /apps. IDs starting with _ are for temporary host apps (such as _try) |
Examples#
Start the clock#
{"id": "clock"}Start the macro player#
Once started, a click of BOOT runs the current macro
{"id": "macro"}Reply#
Started; ok is false on a top-level error
ok false means a top-level error (HTTP 200); the app stays in the error state
| Field | Type | Required | Values | Range | Description |
|---|---|---|---|---|---|
ok | boolean | Yes | Whether the app started | ||
running | string | ID of the started app (on success) | |||
error | string | app_error | Top-level error (on failure) | ||
message | string | Lua error text (on failure) |
Error codes#
| Status | Code | Description |
|---|---|---|
503 | no_storage | Storage is not mounted. See GET /v1/logs |
400 | bad_json | The body is not a JSON object |
400 | bad_id | id is not 1–24 of a-z 0-9 _ -. See the example “Start the clock” for the correct form |
404 | no_app | No such app in storage (message is the id). Run stick push first |
400 | bad_manifest | manifest.json is missing, not JSON, or breaks the manifest rules (docs/lua.md section 2) |
500 | start_failed | Internal error such as the runtime not ready (message is the ESP-IDF error name) |
For errors any endpoint can return, see Common errors.
POST /v1/apps/stop#
Stop the current app and return home
Stops the running app (calls app.on_stop first, limit 200 ms), closes the app source and shows the home screen. Succeeds when no app is running too. No body needed
Reply#
Stopped
Successful reply; endpoints add their own fields
| Field | Type | Required | Values | Range | Description |
|---|---|---|---|---|---|
ok | boolean | Yes | true | Always true |
Error codes#
| Status | Code | Description |
|---|---|---|
400 | bad_json | A body was sent but is not a JSON object. Send no body |
For errors any endpoint can return, see Common errors.
POST /v1/apps/auto#
Set or clear start on boot (id null clears)
Starts this app 3 s after boot; id null clears it. Cleared automatically after 3 errors in a row within 10 s of starting
Request body#
application/json
Sets or clears start on boot
| Field | Type | Required | Values | Range | Description |
|---|---|---|---|---|---|
id | string | null | Yes | pattern ^[a-z0-9-][a-z0-9_-]{0,23}$ | App ID to start on boot, not starting with _; null clears |
Examples#
Start the clock on boot#
{"id": "clock"}Clear start on boot#
{"id": null}Reply#
Saved
Saved start-on-boot setting
| Field | Type | Required | Values | Range | Description |
|---|---|---|---|---|---|
ok | boolean | Yes | true | Always true | |
auto | string | null | Yes | App now started on boot; null if none |
Error codes#
| Status | Code | Description |
|---|---|---|
503 | no_storage | Storage is not mounted. See GET /v1/logs |
400 | bad_json | The body is not a JSON object |
400 | bad_id | id is not a string or null, not 1–24 of a-z 0-9 _ -, or starts with _ (temporary apps cannot start on boot). See the example “Start the clock on boot” for the correct form |
404 | no_app | No such app in storage (message is the id). Run stick push first |
400 | bad_manifest | manifest.json is missing, not JSON, or breaks the manifest rules (docs/lua.md section 2) |
500 | nvs | Saving to NVS failed. Try again |
For errors any endpoint can return, see Common errors.
POST /v1/apps/delete#
Delete an app folder (keeps its data folder)
Deletes the whole /apps/<id> folder: stops the app first if it is running and clears start on boot if set. The data folder /data/<id> is kept
Request body#
application/json
Names one app
| Field | Type | Required | Values | Range | Description |
|---|---|---|---|---|---|
id | string | Yes | pattern ^[a-z0-9_-]{1,24}$ | App ID: 1–24 of a-z 0-9 _ -, the folder name under /apps. IDs starting with _ are for temporary host apps (such as _try) |
Examples#
Delete the app hello#
{"id": "hello"}Reply#
Deleted
Successful reply; endpoints add their own fields
| Field | Type | Required | Values | Range | Description |
|---|---|---|---|---|---|
ok | boolean | Yes | true | Always true |
Error codes#
| Status | Code | Description |
|---|---|---|
503 | no_storage | Storage is not mounted. See GET /v1/logs |
400 | bad_json | The body is not a JSON object |
400 | bad_id | id is not 1–24 of a-z 0-9 _ - |
404 | no_app | No such app in storage (message is the id). Run stick push first |
500 | io_error | Deleting the folder failed (storage error). See GET /v1/logs |
For errors any endpoint can return, see Common errors.
POST /v1/apps/msg#
Message the running app; macro player: select / run / stop / reload / plan
Converts data to a Lua value for the running app's app.on_message and replies once it is queued, without waiting; read the app's response in GET /v1/apps/events. The macro player (app macro) takes AppsMacroCommand; for a bad command it emits an error event and the endpoint still succeeds. Apps in the error state receive nothing
Request body#
application/json
Message for the running app
| Field | Type | Required | Values | Range | Description |
|---|---|---|---|---|---|
data | object | Yes | Value for app.on_message. The macro player takes AppsMacroCommand | ||
| Macro player command | object | data for the macro player (app macro). Results arrive as selected, started, stopped, plan, error and other events in GET /v1/apps/events (docs/web.md section 7); the macro file format is web/spec/macro.schema.json | |||
cmd | string | Yes | select run stop reload plan | select: set the current macro (stops a running one; needs name); run: run the current macro, or with name a trial run of that macro (once, current macro unchanged); stop: stop and reset; reload: re-read the current macro (after the file changed); plan: dry run — load and check, then walk the first steps with a fake hid and emit a plan event (step counts, estimated time, the hid.* calls each step would make); sends no HID, keeps the current macro and anything running | |
doc | object | string | plan only: the macro itself (a macro object or its JSON string) instead of reading a file by name / where | |||
trace | integer | default 20 | 0–200 | plan only: how many steps to walk and list | |
json | boolean | default false | plan only: include the normalized macro JSON in the event (dropped first when the event would exceed 4 KB) | ||
name | string | null | length 1–48; ≤ 48 bytes | Macro name: the file name without .json | ||
where | string | null | fs sd null | Where the macro is: fs = device storage /data/macro/ (default), sd = microSD card /stick/data/macro/ | ||
| #2 | Other apps: any JSON |
Examples#
Macro player: set the current macro#
Makes the macro 每日签到 (daily check-in) on the device current (stops a running one first); emits selected
{"data": {"cmd": "select", "name": "每日签到", "where": "fs"}}Macro player: run the current macro#
Presses keys on the computer. If already running, emits started with already
{"data": {"cmd": "run"}}Macro player: trial run#
Runs it once without changing the current macro; events carry trial
{"data": {"cmd": "run", "name": "每日签到"}}Message another app#
Any JSON, interpreted by the app's app.on_message
{"data": {"cmd": "reset"}}Reply#
Handed to the app
Successful reply; endpoints add their own fields
| Field | Type | Required | Values | Range | Description |
|---|---|---|---|---|---|
ok | boolean | Yes | true | Always true |
Error codes#
| Status | Code | Description |
|---|---|---|
400 | bad_json | The body is not a JSON object, or data is missing |
409 | no_app_running | No app is running. POST /v1/apps/start first (the macro player is macro). See the example “Macro player: run the current macro” for the correct form |
500 | msg_failed | The app's message queue is full (not queued within 100 ms). Try again later |
For errors any endpoint can return, see Common errors.
GET /v1/apps/events#
Events emitted by apps (app.emit)
Ring of app.emit events keeping the latest 64, cleared on reboot. To read incrementally, pass the last reply's next as since. since defaults to 0, i.e. the oldest event in the ring
Parameters#
| Parameter | Type | Required | Values | Range | Description |
|---|---|---|---|---|---|
since | integer | ≥ 0 | Start at this sequence number (inclusive); use the last reply's next. Defaults to 0 | ||
max | integer | 0–64 | Max events, 1–64; 0 or omitted means 64 |
Reply#
Events
Events from app.emit
| Field | Type | Required | Values | Range | Description |
|---|---|---|---|---|---|
ok | boolean | Yes | true | Always true | |
next | integer | Yes | ≥ 0 | since for the next call | |
events | object[] | Yes | In sequence order | ||
seq | integer | Yes | ≥ 0 | Sequence number from 0, reset on reboot | |
ms | integer | Yes | ≥ 0 | Uptime in ms when emitted | |
app | string | Yes | ID of the emitting app | ||
data | Yes | Value given to app.emit (any JSON, ≤ 4096 bytes). Macro player events are told apart by ev (docs/web.md section 7) |
Error codes#
For errors any endpoint can return, see Common errors.
POST /v1/eval#
Run code in the app’s Lua state (can call hid; take care)
Tries code as an expression first (prefixed with return), then as statements. Runs in the running app's Lua state, so it can read and change the app's variables and call hid; with no app running, in a temporary state (only sys, log, json and the standard library). Errors and timeouts still return HTTP 200 with ok false. The body is at most 64 KB
Request body#
application/json
A piece of Lua code
| Field | Type | Required | Values | Range | Description |
|---|---|---|---|---|---|
code | string | Yes | Lua code | ||
timeout_ms | integer | default 2000 | 0–10000 | Time limit in ms; 0 or omitted means 2000, at most 10000 |
Examples#
Check memory (expression)#
{"code": "sys.heap()"}Change an app variable (statement)#
No return value, so result is null
{"code": "count = 0", "timeout_ms": 500}Reply#
Result; ok is false on error
ok false means the code failed (still HTTP 200)
| Field | Type | Required | Values | Range | Description |
|---|---|---|---|---|---|
ok | boolean | Yes | Whether the code ran | ||
result | Return value as JSON (on success): several values become an array, none is null; functions and the like become description strings | ||||
error | string | lua_error timeout no_mem | Failure: lua_error = syntax or runtime error, timeout, no_mem = out of memory | ||
message | string | Error text (on failure) | |||
prints | string[] | Yes | ≤ 64 items | Output of print and log.* during the run, up to 64 lines |
Error codes#
| Status | Code | Description |
|---|---|---|
400 | bad_json | The body is not a JSON object, or code (a string) is missing. See the example “Check memory (expression)” for the correct form |
500 | eval_failed | The Lua runtime is not ready, or memory ran out before a result |
For errors any endpoint can return, see Common errors.