2.6 KiB
2.6 KiB
Box HTTP API
Purpose
Defines the stable contract between the GUI/CLI and the Box. The Box is authoritative; the client only sends commands and reads status.
Prerequisites
- Box running on
http://127.0.0.1:8000
Step-by-step
Status
curl http://127.0.0.1:8000/status
Command (example)
curl -X POST http://127.0.0.1:8000/command \
-H "Content-Type: application/json" \
-d '{"command":"nfc_on","payload":{"uid":"UID_1"}}'
GET /status
Response fields:
box_id: unique device IDwifi_state:WIFI_UNCONFIGURED | WIFI_CONNECTING | WIFI_ONLINE | WIFI_OFFLINEip_address: simulated IP (192.168.4.1or127.0.0.1)connected_ssid: connected SSID ornullwifi_profiles_count: number of stored profilesspotify_status:NOT_CONFIGURED | READYplayback_state:state:IDLE | PLAYING | PAUSEDactive_uidplayback_rootcurrent_filefile_indexpositiondurationvolumelast_error
Example response:
{
"box_id": "klangkiste-a9f3k7m2q8",
"wifi_state": "WIFI_ONLINE",
"ip_address": "127.0.0.1",
"connected_ssid": "HomeWiFi",
"wifi_profiles_count": 1,
"spotify_status": "READY",
"playback_state": {
"state": "PLAYING",
"active_uid": "UID_1",
"playback_root": "media/book_1",
"current_file": "/root/klangkiste/box/data/media/book_1/01.mp3",
"file_index": 0,
"position": 42,
"duration": 180,
"volume": 40,
"last_error": null
}
}
POST /command
Request body:
{
"command": "nfc_on",
"payload": { "uid": "UID_1" }
}
Supported commands:
nfc_on{ uid }nfc_off{ uid }play_pausenextprevvolume_upvolume_downvol_up(alias)vol_down(alias)stoptrigger_error{ type }wifi_add_profile{ ssid, password, priority? }wifi_resetspotify_set_tokens{ access_token, refresh_token, expires_at, account_id? }spotify_clear
Example: add WiFi profile
curl -X POST http://127.0.0.1:8000/command \
-H "Content-Type: application/json" \
-d '{"command":"wifi_add_profile","payload":{"ssid":"HomeWiFi","password":"secret","priority":10}}'
Example: set Spotify tokens
curl -X POST http://127.0.0.1:8000/command \
-H "Content-Type: application/json" \
-d '{"command":"spotify_set_tokens","payload":{"access_token":"a","refresh_token":"b","expires_at":123}}'
Checklist
- ✅
GET /statusreturns JSON - ✅
POST /commandreturns{ "ok": true } - ✅ No secrets appear in
/status
Troubleshooting
- 400 responses:
- Check required fields in the payload.
- CORS errors:
- Ensure Box API is running on the expected host/port.