External API
blocksd exposes two APIs for building your own integrations: a Unix domain socket for local IPC and a WebSocket for browser and network clients. Both share command validation and JSON payloads, but use different transport framing.
Connection Methods
Unix Socket
Low-latency local IPC. This is the preferred method for local integrations.
- Linux primary path:
$XDG_RUNTIME_DIR/blocksd/blocksd.sock - Linux fallback path:
/tmp/blocksd/blocksd.sock - macOS path:
/tmp/blocksd-<uid>/blocksd.sock, using the current user's numeric ID - Permissions: directory
0700, socket0660
WebSocket
Browser and network clients. Used by the web dashboard (blocksd ui).
- Default:
ws://localhost:9010/ws - Supports both binary LED frames and JSON messages
Protocol Overview
On the Unix socket, a single connection can mix two message types:
- NDJSON: newline-delimited JSON for control messages and events
- Binary LED frames: fixed-size 685-byte packets for LED streaming
The server distinguishes inbound message types by the first byte:
0xBD: binary LED frame- Anything else: read as newline-delimited JSON
WebSocket clients send JSON in text messages and the same 685-byte LED packet in binary messages. Binary acknowledgements arrive as one-byte binary messages; JSON responses and events arrive as text messages. The custom WebSocket codec has not been validated against a full conformance suite.
Recommended Client Strategy
- Open a control socket
- Send
discoverto get the device list anduidvalues - Use bitmap frames for nonzero grid dimensions; use JSON
key_frameforkey_count = 24 - Use the binary frame path for Lightpad animation; LUMI key frames use JSON
- Retry early frame rejections while the device is still coming up
- Open a second socket for
subscribeif you also need events
TIP
Splitting control and event sockets avoids the complexity of demultiplexing binary frame acks (1 byte) and NDJSON event messages on the same connection.
Binary LED Frames
Use this for streaming, animations, and anything latency-sensitive.
Frame Layout
Each binary frame is exactly 685 bytes:
| Offset | Size | Type | Meaning |
|---|---|---|---|
0 | 1 | u8 | Magic 0xBD |
1 | 1 | u8 | Message type 0x01 |
2 | 8 | u64 LE | Device uid |
10 | 675 | bytes | 15 * 15 * 3 RGB888 pixel data |
Pixel order is row-major: pixel i maps to x = i % 15, y = i // 15. Each pixel is RGB888 on the wire; the daemon converts to device RGB565 internally.
Binary Ack
Each parsed binary frame write returns one acknowledgement byte (inside a binary WebSocket message on that transport):
| Value | Meaning |
|---|---|
0x01 | Accepted |
0x00 | Rejected |
0x00 means the device was unavailable, the uid was unknown, or the payload was invalid. Early rejections during device startup are retryable.
Acceptance confirms that the daemon accepted the frame, not a hardware acknowledgement or visible display change. The first frame triggers renderer upload and can remain queued until the code transfer is acknowledged and the renderer answers a fresh execution challenge. Read program_status to distinguish upload progress from renderer readiness. See renderer startup.
Python Example
import os
import socket
import struct
MAGIC = 0xBD
TYPE_FRAME = 0x01
PIXELS = bytes([255, 0, 0] * 225) # solid red, 15x15 RGB888
uid = 42
frame = struct.pack("<BBQ", MAGIC, TYPE_FRAME, uid) + PIXELS
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as sock:
sock.connect(os.path.join(os.environ.get("XDG_RUNTIME_DIR", "/tmp"), "blocksd/blocksd.sock"))
sock.sendall(frame)
accepted = sock.recv(1) == b"\x01"
print("accepted:", accepted)JSON / NDJSON Protocol
JSON messages are newline-delimited UTF-8 JSON objects. Every request is one line, every response is one line.
ping
Health check and basic daemon info.
{ "type": "ping", "id": "req-1" }{
"type": "pong",
"version": "0.5.0",
"uptime_seconds": 12,
"device_count": 2,
"id": "req-1"
}discover
List all connected devices with capabilities and battery status.
{ "type": "discover", "id": "req-2" }{
"type": "discover_response",
"devices": [
{
"uid": 8456574102450706172,
"serial": "LPMJW6SWHSPD8H92",
"block_type": "lightpad_m",
"name": "",
"grid_width": 15,
"grid_height": 15,
"key_count": 0,
"battery_level": 100,
"battery_charging": false,
"firmware_version": null
}
],
"id": "req-2"
}battery_level is a percentage from 0 to 100, scaled from the device's 5-bit level. firmware_version is null when the device has not reported a readable version string.
The uid is a deterministic 64-bit identifier derived from the device serial. Clients can cache it across daemon restarts.
Only Lightpad Block and Lightpad Block M advertise nonzero grid dimensions and accept bitmap frames. LUMI advertises grid_width = 0, grid_height = 0, and key_count = 24; use key_frame for its key colors. Other recognized devices report key_count = 0.
WARNING
A device can appear in discover_response before API mode activation and heap setup finish. Retry rejected writes after discovery settles. An accepted frame can still be waiting for renderer initialisation; request program_status to inspect readiness separately.
frame
JSON-based LED frame write. Supported for compatibility and debugging, but not recommended for streaming.
{ "type": "frame", "uid": 42, "pixels": "...base64..." }{ "type": "frame_ack", "uid": 42, "accepted": true }The pixels field is a base64-encoded 675-byte RGB888 payload. Use the binary protocol for high-rate updates.
key_frame
Write the 24 LUMI key colors in key-index order. The pixels field contains base64-encoded RGB888 data: exactly 72 bytes (red, green, blue for each key). The daemon applies the connection server's brightness setting and converts the data to the renderer's 48-byte RGB565 heap.
The key renderer sets LUMI's hardware brightness to 100% when it starts and when it answers a readiness challenge after reconnecting. Clients control dimming through their RGB values or the API brightness setting. Gamma correction is unchanged.
{ "type": "key_frame", "uid": 42, "pixels": "...base64..." }{ "type": "key_frame_ack", "uid": 42, "accepted": true }Key frames require a LUMI device with a reported firmware version of 1.3.0 or newer. Invalid base64, incorrect length, an unsupported device, or an unavailable/older firmware version produces accepted: false. The existing 685-byte binary frame format remains dedicated to 15×15 Lightpad grids.
For example, construct a red frame in Python with base64.b64encode(bytes([255, 0, 0]) * 24).decode("ascii").
program_load, program_status, and program_reset
program commands use either a device serial or an integer uid. browser clients should use serial because device UIDs can exceed JavaScript's exact integer range. include an id to correlate responses. the device must have completed API-mode activation.
load LittleFoot source with an optional map of include names to source text:
{
"type": "program_load",
"serial": "LPM123456789ABCD",
"name": "Example.littlefoot",
"source": "#heapsize: 64\n#include \"Helpers.littlefoot\"\nvoid repaint() { draw(); }",
"includes": {
"Helpers.littlefoot": "void draw() { fillPixel(makeARGB(255, 128, 255, 234), 0, 0); }"
},
"id": "load-example"
}the program name must contain 1 to 128 printable characters. the source, include contents, and include names must total no more than 256 KiB in UTF-8. include names can use normalized relative paths; absolute paths and parent-directory traversal are rejected. the compiler reads only the supplied bundle and the bundled standard library. Dashboard metadata supports fixed defaults for int, float, bool, and midiNote, with no live metadata controls. errors refer to line numbers in the expanded source.
native clients can instead send base64-encoded LittleFoot bytecode in code. provide exactly one of source or code. the daemon validates the binary header, checksum, function table, and device memory requirements before replacing the active program.
source compilation runs away from the MIDI event loop. allow at least 20 seconds for the load request. the response reports the current upload state; it does not wait for the complete device acknowledgement:
{
"type": "program_status",
"uid": 42,
"program": {
"owner": "custom",
"name": "Example.littlefoot",
"state": "uploading",
"message": "Uploading program to the device.",
"code_size": 45,
"heap_size": 64
},
"id": "load-example"
}the example sizes are illustrative. code_size includes the program header; heap_size is the compiled program's heap allocation. query status to follow the transfer:
{
"type": "program_status",
"serial": "LPM123456789ABCD",
"id": "status-example"
}| State | Meaning |
|---|---|
idle | blocksd is not managing a temporary program on this device |
compiling | LittleFoot source is being compiled; the previous program has not been replaced |
uploading | the complete upload has not been acknowledged |
waiting | a lighting upload was acknowledged, but the renderer has not answered its execution challenge |
ready | a lighting renderer answered the current challenge |
uploaded | a custom program upload was acknowledged; execution is not verified |
unresponsive | an upload or renderer reply has exceeded the response window; the message identifies which |
the owner is device, lighting, or custom. unresponsive reports the delay without cancelling transfer retries or readiness checks. even ready does not prove visible LED output. custom programs do not need to implement blocksd's private renderer challenge.
loading is temporary and does not save a startup default. lighting frames are rejected while a custom program owns the device or compilation is in progress. compile and validation errors leave the previous program intact; a disconnect during compilation prevents the result from being sent to a replacement device session.
request the saved program explicitly:
{ "type": "program_reset", "serial": "LPM123456789ABCD", "id": "reset-example" }the daemon sends the SDK's end/begin API-mode sequence, clears its temporary program state, and returns program_status with owner: "device" and state: "idle". the response confirms dispatch, not execution of the saved program. reset does not perform a factory reset or recover a previous temporary upload. a reset during compilation is rejected.
program errors use the normal correlated error response:
{
"type": "error",
"message": "Include not supplied: Helpers.littlefoot",
"id": "load-example"
}brightness
Set the LED brightness for a device.
{ "type": "brightness", "uid": 42, "value": 128 }{ "type": "brightness_ack", "uid": 42, "ok": true }Value is clamped to 0-255. Brightness is sticky per-server state, applied to future frame writes before RGB565 conversion. Unix socket and WebSocket servers hold separate brightness settings; changing one does not change the other.
subscribe
Subscribe to real-time event streams.
{ "type": "subscribe", "events": ["device", "touch", "button"] }{ "type": "subscribed", "events": ["button", "device", "touch"] }config_get and config_set
Read cached configuration values for a device or request a setting change:
{ "type": "config_get", "uid": 42 }{
"type": "config_values",
"uid": 42,
"values": [{ "item": 10, "value": 50, "min": 0, "max": 100 }]
}{ "type": "config_set", "uid": 42, "item": 10, "value": 50 }{ "type": "config_ack", "uid": 42, "item": 10, "ok": true }The values and ranges above are illustrative; use the device's reported ranges. A successful set response confirms dispatch, not persistence. Subscribe to config for subsequent config_changed events.
Device configuration metadata
Browser clients should target configuration requests with serial instead of a numeric uid. Device UIDs can exceed JavaScript's exact integer range. Existing integer UID clients remain supported.
{ "type": "config_get", "serial": "LKB1234567890AB", "id": "settings" }The config_values response includes serial, values, and schema. Each value includes item, value, min, max, and writable. Schema entries describe item, key, label, group, kind, and verified options where available. Unknown settings retain a numeric label. Do not enable writes without a device-reported range.
Set refresh: true on config_get to request a factory-settings sync from the connected hardware. Subscribe to config first: the response contains the current cache, and subsequent config_changed events deliver fresh settings. Without refresh, the command only reads cached values. The daemon also requests factory settings when a device enters API mode.
A config_reset event (uid, serial) invalidates the device's previous settings list when a new sync starts or its program changes. Clear cached values, metadata, and pending writes for that device; subsequent config_changed events rebuild the list. A device may report an empty list.
A config_ack reports status: "pending" when dispatch succeeds and status: "error" otherwise. Subscribe to config before writing and wait for a matching config_changed event to establish readback. Config events also include serial, range, and writable state. Acknowledgement is not a guarantee of device-side persistence.
Saved presets
The daemon owns a preset store shared by Unix and WebSocket clients. Include an id to correlate requests and responses.
| Request type | Fields | Response type |
|---|---|---|
preset_list | optional serial | preset_list, with presets |
preset_save | serial, name, optional auto_restore | preset_saved, with preset and skipped_items |
preset_apply | serial, preset_id | preset_applied, with status: "pending" and requested values |
preset_update | preset_id, auto_restore | preset_saved, with preset |
preset_export | preset_id | preset_export, with preset |
preset_import | preset | preset_saved, with a new preset |
preset_delete | preset_id | preset_deleted |
A preset contains id, name, serial, block_type, values (an array of {item, value}), and auto_restore. Save captures writable device-reported values and returns excluded setting IDs in skipped_items. Apply requires the matching serial and family, validates all ranges before sending, and relies on config events for confirmation. Partial send failures return an error describing the settings already sent. Import validates the complete payload, generates a new ID, and disables auto-restore.
Browser WebSocket upgrades reject cross-origin requests. Native clients may omit Origin. Keep the default loopback binding unless access is controlled separately; origin validation does not authenticate network clients.
topology
Send { "type": "topology" } to receive topology_response with devices and connections arrays. Each connection contains device1_uid, device2_uid, port1, and port2. Subscribe to topology for topology_changed events with the same arrays.
Event Stream
Subscribed events are emitted as NDJSON on the Unix socket or JSON text messages on WebSocket. Supported categories are device, touch, button, config, and topology. A new subscription replaces the previous one on that connection.
Device Events
{
"type": "device_added",
"device": {
"uid": 42,
"serial": "LPB1234567890AB",
"block_type": "lightpad",
"grid_width": 15,
"grid_height": 15,
"battery_level": 85,
"battery_charging": false,
"firmware_version": null
}
}{ "type": "device_removed", "uid": 42 }Touch Events
{
"type": "touch",
"uid": 42,
"action": "start",
"index": 0,
"timestamp": 183204,
"x": 0.5,
"y": 0.75,
"z": 0.8,
"vx": 0.0,
"vy": 0.0,
"vz": 0.0
}Action is one of: start, move, end. index identifies one finger for the lifetime of a touch, from start through end. Positions x and y and pressure z are normalized to 0 to 1. Velocities vx, vy, and vz are signed, range from -1 to 127/128, and like positions are rounded to four decimals; devices that report touches without velocity send 0. timestamp is the device clock in milliseconds, useful for spacing events within a burst but not comparable across devices.
Button Events
{
"type": "button",
"uid": 42,
"action": "press",
"button_id": 2,
"button": "up",
"timestamp": 183910
}Action is one of: press, release. button_id is the protocol button index. button is its ROLI SDK function in snake case, such as mode, down, up, or play_or_pause, and is null when the device type does not define that index. LUMI Keys report mode, down, and up; Lightpad and Seaboard Blocks report mode. timestamp uses the same device clock as touch events.
Configuration Events
{ "type": "config_changed", "uid": 42, "item": 10, "value": 50 }Backpressure
Each subscriber has a bounded event queue of 1024 events. If a client stops consuming events and its queue fills, the daemon discards the queued events and stops queueing new ones for that connection rather than blocking the server. Once the connection's pending writes reach the client, the daemon sends {"type": "error", "message": "event queue overflowed; reconnect and subscribe again"} and closes the connection (WebSocket close status 1008). A subscribe sent on that connection before it closes is refused and may return the same error. After the close, reconnect, subscribe again, and send discover to rebuild device state; touches that started before the overflow may never report end.
Failure Semantics
Frame writes are rejected when:
- The
uiddoes not exist - The payload size is wrong
- The device has not finished entering API mode or has no heap
- The device does not support the requested bitmap or key surface
- A key frame targets unsupported or unavailable LUMI firmware
- A custom program owns the device or a program is being compiled
retry discovery for unavailable devices. inspect program_status before retrying a rejected lighting frame; an active custom program needs an explicit reset before lighting can replace it. a reconnect invalidates cached readiness state.