M2: On-device WiFi + REST API #2
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feature/fw-rest-api"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
M2: On-device WiFi + REST API
Feature
The device now joins WiFi and serves the open REST API on the LAN, so the app (and any
client) can list recordings, download audio (with resumable Range requests), delete
recordings, read device status, control recording, and read/update config. If no WiFi
credentials are stored, the device opens a provisioning SoftAP so the same API is reachable
to set them.
What was achieved
The WiFi-to-app sync path and the "completely open API" on the device side. Implements the
device paths of
api/openapi.yaml. Persistent config (device id, WiFi creds, API token,upload settings) now lives in NVS. Advertised over mDNS as
openscribe.local.How to verify
pio run -e esp32s3_devand-e xiao_esp32s3(now also fetching ArduinoJson).docs/testing.md): set WiFi viaPUT /api/v1/device/config, then:GET http://openscribe.local/api/v1/device-> status JSON.GET .../api/v1/recordings-> list;GET .../recordings/{id}/audiowith aRange: bytes=0-1023header ->206+Content-Range.POST .../record/startthen.../record/stop-> recording toggles.Not yet compiled locally or hardware-verified - relies on CI to build.
Tools used
C++ (Arduino-ESP32 3.x), PlatformIO. New dependency:
bblanchon/ArduinoJson@^7. WiFi,WebServer,ESPmDNS,Preferences,SDare all core-bundled.How it works
config(src/config.{h,cpp}) - NVS (Preferences) store: stable device id (from MAC),WiFi SSID/PSK, API bearer token, upload settings. Secrets stay off the SD card.
net_wifi(src/net_wifi.{h,cpp}) - station join with stored creds; on no-creds/failureopens a SoftAP
OpenScribe-<macsuffix>for provisioning; starts mDNSopenscribe.local;reconnect logic in
loop().api_http(src/api_http.{h,cpp}) - synchronousWebServeron :80 with routes for/device,/device/config(GET/PUT),/recordings,/recordings/{},/recordings/{}/audio(HTTP Range -> 206), delete, and/record/start|stop. Bearer-tokenauth on mutating calls (open when no token is set). JSON via ArduinoJson.
storagegained list/read/delete/count helpers and path builders used by the API.main.cppwires config + WiFi + API into setup/loop alongside the M1 recorder.State updated
state/TODO.md(M2 in PR; new security + NTP follow-ups)state/ARCHITECTURE.md(config/net_wifi/api_http marked landed)state/NOTES.md(M2 firmware specifics + security follow-ups)Follow ups
started_at.during provisioning (M4/BLE).
Adds the WiFi-to-app sync path and the on-device open REST API implementing the device paths of api/openapi.yaml, plus persistent config in NVS. What changed: - firmware/src/config.{h,cpp}: NVS (Preferences) store - stable device id from MAC, WiFi SSID/PSK, API bearer token, upload settings. Secrets stay off the SD card. - firmware/src/net_wifi.{h,cpp}: station join with stored creds; SoftAP provisioning fallback when no creds / join fails; mDNS openscribe.local; reconnect in loop(). - firmware/src/api_http.{h,cpp}: synchronous WebServer on :80. Routes: GET /device, GET/PUT /device/config, GET /recordings, GET /recordings/{id}, GET /recordings/{id}/audio (HTTP Range -> 206 + Content-Range), DELETE /recordings/{id}, POST /record/start|stop. Bearer-token auth on mutating calls (open when no token). - firmware/src/storage.{h,cpp}: list/read/delete/count helpers + path builders. - firmware/src/main.cpp: wire config + WiFi + API into setup/loop; bump fw to 0.2.0. - firmware/platformio.ini: add bblanchon/ArduinoJson@^7 (only new dep). - state/: ARCHITECTURE, NOTES, TODO updated; security + NTP follow-ups recorded. Why: - This is the WiFi transfer channel and the device half of the "completely open API": clients can list, download (resumable), delete and control without any cloud. Notes: - Not compiled locally (no PlatformIO on the dev host) or hardware-verified; CI builds both board profiles. Security follow-ups logged: API is open when no token is set, and the SoftAP uses a fixed default passphrase (make user-set at M4/BLE). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>