NPN/PNP Input API
The board serves a JSON API over HTTP on port 80 under /api/v1, and a
server-sent event stream of input transitions. Examples use INPUT_IP for the board's
address.
Quick Start
The board takes its address from DHCP. Its default hostname is input- followed by the last six hex digits of its MAC address, and discovery finds boards on the local network. Opening http://INPUT_IP/ in a browser shows
a live dashboard.
Confirm the board's identity, read all twelve channels, set the debounce to 5 ms, then stream transitions:
curl http://INPUT_IP/api/v1/info
curl http://INPUT_IP/api/v1/inputs
curl -X PATCH -H 'Content-Type: application/json' -d '{"debounce_us":5000}' http://INPUT_IP/api/v1/inputs/configuration
curl -N http://INPUT_IP/api/v1/eventsChanging the debounce briefly pauses acquisition. Every channel reports asserted: null until its level is stable again for the new interval.
Wiring and Signals
- Each channel has a three-terminal block marked
24V,SIG, andGND. Power the sensor from24VandGND, and wire its output toSIG. - A sinking (NPN) sensor pulls
SIGto ground when active; a sourcing (PNP) sensor drives it to 24 V. Either reportsasserted: true. The board cannot tell which kind is wired, sosensor_typesin the capabilities lists compatible wiring, not detected polarity. assertedisnullafter boot or a settings change until the channel's level has been stable for the debounce interval.- Debounce is one board-wide value from 0 to 1,000,000 µs, 2,000 µs by default, and is kept across restarts. A transition's timestamp marks the first sampled edge of the new stable level, not the later moment the debounce confirmed it.
Endpoint Index
Inputs
| Method | Path | Use |
|---|---|---|
GET | /api/v1/inputs/capabilities | Read immutable channel, debounce and sensor-wiring capabilities. |
GET | /api/v1/inputs/configuration | Read the effective board-wide debounce setting. |
GET | /api/v1/inputs | Read all twelve channels, accepted transition history and delivery continuity. |
PATCH | /api/v1/inputs/configuration | Persist board-wide debounce; changed settings intentionally pause capture and requalify channels. |
Event Stream
| Method | Path | Use |
|---|---|---|
GET | /api/v1/events | Subscribe to checkpoints, retained control records and compact batches of input transitions. |
Power
| Method | Path | Use |
|---|---|---|
GET | /api/v1/power | Read the latest eFuse IMON sample and estimated current, when available. |
Service
| Method | Path | Use |
|---|---|---|
GET | /api/v1 | Discover the version, contract revision and resource links. |
GET | /api/v1/info | Read product, boot and exact firmware identity. |
GET | /api/v1/health | Read current faults and warnings; earlier faults do not change current health. |
GET | /api/v1/system | Read uptime, resources, capture and delivery diagnostics, and the retained earlier-boot fault. |
POST | /api/v1/system/reboot | Reboot after the completed response and fixed delay; join the new boot before further work. |
Time
| Method | Path | Use |
|---|---|---|
GET | /api/v1/time | Read a coherent monotonic/PTP observation with quality and scheduling eligibility. |
GET | /api/v1/time/diagnostics | Inspect PTP lifecycle, discipline and correlation diagnostics. |
Network
| Method | Path | Use |
|---|---|---|
GET | /api/v1/network | Read confirmed, active and pending network settings and service observations. |
PATCH | /api/v1/network | Validate a candidate, or stage a reversible network transaction. Confirm only after the candidate is ready. |
POST | /api/v1/network/confirm | Persist the pending configuration; a completed confirmation can be retried idempotently. |
POST | /api/v1/network/rollback | Roll back pending settings, then poll until the confirmed settings are active. |
Discovery
| Method | Path | Use |
|---|---|---|
DISCOVER | udp://device:39590 | Discover the numeric HTTP origin and join it to the expected model and MAC over HTTP. |
Web Interface
| Method | Path | Use |
|---|---|---|
GET | / | Serve the dashboard; each open dashboard uses one SSE connection. |
GET | /input_model.mjs | Serve the dashboard input-state model module. |
Endpoints
Inputs
GET /api/v1/inputs/capabilities
Read immutable channel, debounce and sensor-wiring capabilities.
Query String
No query string is accepted.
Request Body
No request body is accepted.
Example
curl http://INPUT_IP/api/v1/inputs/capabilitiesHTTP 200 application/json
{
"channel_numbers": {
"count": 12,
"first": 1
},
"debounce_us": {
"max": 1000000,
...GET /api/v1/inputs/configuration
Read the effective board-wide debounce setting.
Query String
No query string is accepted.
Request Body
No request body is accepted.
Example
curl http://INPUT_IP/api/v1/inputs/configurationHTTP 200 application/json
{
"debounce_us": 2000
}GET /api/v1/inputs
Read all twelve channels, accepted transition history and delivery continuity.
Query String
No query string is accepted.
Request Body
No request body is accepted.
Example
curl http://INPUT_IP/api/v1/inputsHTTP 200 application/json
{
"acquisition_gaps": "4",
"boot_id": "00000000-0000-4000-8000-000000000001",
"capture_epoch": "5",
"captured": {
"mono_ns": "240988737000",
"ptp": {
...PATCH /api/v1/inputs/configuration
Persist board-wide debounce; changed settings intentionally pause capture and requalify channels.
Query String
No query string is accepted.
Request Body
JSON matching inputs.configuration.
Examples
Success (200)
curl -X PATCH -H 'Content-Type: application/json' -d '{"debounce_us":0}' http://INPUT_IP/api/v1/inputs/configurationHTTP 200 application/json
{
"debounce_us": 0
}Invalid debounce (400)
curl -X PATCH -H 'Content-Type: application/json' -d '{"debounce_us":-1}' http://INPUT_IP/api/v1/inputs/configurationHTTP 400 application/json
{
"error": {
"code": "bad_request",
"details": {
"field": "debounce_us"
},
"message": "debounce_us is outside the supported range",
...Event Stream
GET /api/v1/events
Subscribe to checkpoints, retained control records and compact batches of input transitions.
Query String
Optional boot_id; positive Last-Event-ID requires the matching boot_id.
Request Body
No request body is accepted.
Responses
| Status | Result | Schema |
|---|---|---|
200 | success | text/event-stream |
410 | stale_event_cursor_410 | common.product_error |
409 | future_event_cursor_409 | common.product_error |
409 | boot_id_mismatch_409 | common.product_error |
503 | sse_capacity_exceeded_503 | common.product_error |
503 | event_publisher_unavailable_503 | common.product_error |
The common errors can also apply.
Examples
System (200)
curl -N -H 'Last-Event-ID: 0' http://INPUT_IP/api/v1/eventsHTTP 200 text/event-stream
id: 1
event: system
data: {"boot_id":"00000000-0000-4000-8000-000000000001","state":"ok"}Checkpoint (200)
curl -N http://INPUT_IP/api/v1/eventsHTTP 200 text/event-stream
id: 91
event: stream_checkpoint
data: {"boot_id":"00000000-0000-4000-8000-000000000001","state":"ok","latest_event_id":91}Gap (200)
curl -N http://INPUT_IP/api/v1/eventsHTTP 200 text/event-stream
id: 92
event: input_acquisition_gap
data: {"reason":"flash_persistence","previous_capture_epoch":"7","capture_epoch":"8","gaps":"7","abandoned_slots":"1","delivery":{"drops":"0","epoch":"0","continuous":true}}Initialized (200)
curl -N http://INPUT_IP/api/v1/eventsHTTP 200 text/event-stream
id: 93
event: input_initialized
data: {"channel":1,"asserted":false,"stable_since":{"mono_ns":"258503957350","ptp":{"ns":"1793740605080054485","state":"acquiring","epoch":null,"generation":2}},"delivery":{"drops":"0","epoch":"0","continuous":true}}Input batch (200)
curl -N http://INPUT_IP/api/v1/eventsHTTP 200 text/event-stream
id: 107
event: input_batch
data: "AQMCAQAAAAAAAABUkf3QPAAAAMPg8UGUpeQYAAAAAAAAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAUAAAAAAAAAAAcEexYBAXsWAQT4DskC8Q7JAg=="Decoded rows
[
{
"event": "input",
"id": "105",
"data": {
"transition": 1,
"channel": 3,
"asserted": true,
"mono_ns": "261204316500",
...Future cursor (409)
curl -N -H 'Last-Event-ID: 9007199254740991' 'http://INPUT_IP/api/v1/events?boot_id=00000000-0000-4000-8000-000000000001'HTTP 409 application/json
{
"error": {
"code": "future_event_cursor",
"details": {
"boot_id": "00000000-0000-4000-8000-000000000001",
"latest_event_id": 65,
"requested_event_id": 9007199254740991
...Power
GET /api/v1/power
Read the latest eFuse IMON sample and estimated current, when available.
Query String
No query string is accepted.
Request Body
No request body is accepted.
Example
curl http://INPUT_IP/api/v1/powerHTTP 200 application/json
{
"sample": {
"adc_raw": 56,
"calibrated": true,
"estimated_ma": 37,
"imon_mv": 58,
"mono_ns": "240789592000"
...Service
GET /api/v1
Discover the version, contract revision and resource links.
Query String
No query string is accepted.
Request Body
No request body is accepted.
Example
curl http://INPUT_IP/api/v1HTTP 200 application/json
{
"api_version": "1.0",
"capabilities": [
"system",
"network",
"time",
"events",
...GET /api/v1/info
Read product, boot and exact firmware identity.
Query String
No query string is accepted.
Request Body
No request body is accepted.
Examples
Success (200)
curl http://INPUT_IP/api/v1/infoHTTP 200 application/json
{
"api_version": "1.0",
"boot_id": "00000000-0000-4000-8000-000000000001",
"chip": {
"flash_bytes": 16777216,
"psram_bytes": 33554432,
"revision": "v1.3",
...Query rejected (400)
curl 'http://INPUT_IP/api/v1/info?unsupported=1'HTTP 400 application/json
{
"error": {
"code": "bad_request",
"details": {},
"message": "query parameters are not supported",
"retryable": false
}
}GET /api/v1/health
Read current faults and warnings; earlier faults do not change current health.
Query String
No query string is accepted.
Request Body
No request body is accepted.
Example
curl http://INPUT_IP/api/v1/healthHTTP 200 application/json
{
"faults": [],
"heap": {
"internal_free_bytes": 293615,
"internal_min_free_bytes": 285387,
"psram_free_bytes": 12431056,
"psram_min_free_bytes": 12430888
...GET /api/v1/system
Read uptime, resources, capture and delivery diagnostics, and the retained earlier-boot fault.
Query String
No query string is accepted.
Request Body
No request body is accepted.
Example
curl http://INPUT_IP/api/v1/systemHTTP 200 application/json
{
"boot_id": "00000000-0000-4000-8000-000000000001",
"boot_stage": "running",
"events": {
"history": {
"append_failures": "0",
"available": true,
...POST /api/v1/system/reboot
Reboot after the completed response and fixed delay; join the new boot before further work.
Query String
No query string is accepted.
Request Body
JSON matching system.reboot.request.
Responses
| Status | Result | Schema |
|---|---|---|
202 | success | system.reboot.response |
409 | conflict_409 | common.product_error |
The common errors can also apply.
Examples
Success (202)
curl -X POST -H 'Content-Type: application/json' -d '{}' http://INPUT_IP/api/v1/system/rebootHTTP 202 application/json
{
"boot_id": "00000000-0000-4000-8000-000000000001",
"delay_ms": 250
}Invalid reboot (400)
curl -X POST -H 'Content-Type: application/json' -d '{"delay_ms":1}' http://INPUT_IP/api/v1/system/rebootHTTP 400 application/json
{
"error": {
"code": "bad_request",
"details": {},
"message": "reboot body must be exactly {}",
"retryable": false
}
}Time
GET /api/v1/time
Read a coherent monotonic/PTP observation with quality and scheduling eligibility.
Query String
No query string is accepted.
Request Body
No request body is accepted.
Example
curl http://INPUT_IP/api/v1/timeHTTP 200 application/json
{
"boot_id": "00000000-0000-4000-8000-000000000001",
"mono_ns": "240959674000",
"ptp": {
"epoch": "2",
"generation": 2,
"grandmaster_id": "a0:ad:9f:ff:fe:a0:e9:2e",
...GET /api/v1/time/diagnostics
Inspect PTP lifecycle, discipline and correlation diagnostics.
Query String
No query string is accepted.
Request Body
No request body is accepted.
Example
curl http://INPUT_IP/api/v1/time/diagnosticsHTTP 200 application/json
{
"boot_id": "00000000-0000-4000-8000-000000000001",
"device_time_ns": "1793740587541864255",
"monotonic_time_ns": "240965856000",
"ptp": {
"actuator_fault_active": false,
"algorithm": "robust_linear_regression",
...Network
GET /api/v1/network
Read confirmed, active and pending network settings and service observations.
Query String
No query string is accepted.
Request Body
No request body is accepted.
Example
curl http://INPUT_IP/api/v1/networkHTTP 200 application/json
{
"active": {
"dns": [],
"gateway": "192.0.2.2",
"hostname": "input-example-1",
"ipv4": "192.0.2.1",
"mode": "dhcp",
...PATCH /api/v1/network
Validate a candidate, or stage a reversible network transaction. Confirm only after the candidate is ready.
Query String
No query string is accepted.
Request Body
JSON matching network.patch.request.
Responses
| Status | Result | Schema |
|---|---|---|
200 | success | network.patch.validate_response |
202 | accepted | network.patch.apply_response |
422 | invalid_config_422 | common.product_error |
409 | address_conflict_409 | common.product_error |
409 | network_change_pending_409 | common.product_error |
409 | confirm_not_ready_409 | common.product_error |
409 | confirm_not_reachable_409 | common.product_error |
409 | no_pending_config_409 | common.product_error |
409 | network_busy_409 | common.product_error |
409 | network_mutation_blocked_409 | common.product_error |
503 | network_busy_503 | common.product_error |
503 | network_unavailable_503 | common.product_error |
503 | outcome_unknown_503 | common.product_error |
500 | internal_error_500 | common.product_error |
200 | unchanged | network.response |
The common errors can also apply.
Examples
Success (200)
curl -X PATCH -H 'Content-Type: application/json' -d '{"apply":false,"hostname":"input-example-1","mode":"dhcp"}' http://INPUT_IP/api/v1/networkHTTP 200 application/json
{
"candidate": {
"hostname": "input-example-1",
"mode": "dhcp",
"static_ipv4": null
},
"valid": true
}Apply unchanged (200)
curl -X PATCH -H 'Content-Type: application/json' -d '{"apply":true,"hostname":"input-example-1","mode":"dhcp"}' http://INPUT_IP/api/v1/networkHTTP 200 application/json
{
"active": {
"dns": [],
"gateway": "192.0.2.2",
"hostname": "input-example-1",
"ipv4": "192.0.2.1",
"mode": "dhcp",
...Apply (202)
curl -X PATCH -H 'Content-Type: application/json' -d '{"apply":true,"confirm_timeout_ms":30000,"hostname":"input-example-2","mode":"dhcp"}' http://INPUT_IP/api/v1/networkHTTP 202 application/json
{
"active": {
"dns": [],
"gateway": "192.0.2.2",
"hostname": "input-example-1",
"ipv4": "192.0.2.1",
"mode": "dhcp",
...Invalid network mode (422)
curl -X PATCH -H 'Content-Type: application/json' -d '{"mode":"invalid"}' http://INPUT_IP/api/v1/networkHTTP 422 application/json
{
"error": {
"code": "invalid_config",
"details": {
"field": "mode"
},
"message": "mode must be dhcp or static",
...POST /api/v1/network/confirm
Persist the pending configuration; a completed confirmation can be retried idempotently.
Query String
No query string is accepted.
Request Body
JSON matching network.confirm.request.
Responses
| Status | Result | Schema |
|---|---|---|
200 | success | network.response |
422 | invalid_config_422 | common.product_error |
409 | address_conflict_409 | common.product_error |
409 | network_change_pending_409 | common.product_error |
409 | confirm_not_ready_409 | common.product_error |
409 | confirm_not_reachable_409 | common.product_error |
409 | no_pending_config_409 | common.product_error |
409 | network_busy_409 | common.product_error |
409 | network_mutation_blocked_409 | common.product_error |
503 | network_busy_503 | common.product_error |
503 | network_unavailable_503 | common.product_error |
503 | outcome_unknown_503 | common.product_error |
500 | internal_error_500 | common.product_error |
The common errors can also apply.
Example
curl -X POST -H 'Content-Type: application/json' -d '{"config_id":"00000000-0000-4000-8000-000000000003"}' http://INPUT_IP/api/v1/network/confirmHTTP 200 application/json
{
"active": {
"dns": [],
"gateway": "192.0.2.2",
"hostname": "input-example-1",
"ipv4": "192.0.2.1",
"mode": "dhcp",
...POST /api/v1/network/rollback
Roll back pending settings, then poll until the confirmed settings are active.
Query String
No query string is accepted.
Request Body
JSON matching network.confirm.request.
Responses
| Status | Result | Schema |
|---|---|---|
202 | success | network.rollback.response |
200 | already_rolled_back | network.response |
422 | invalid_config_422 | common.product_error |
409 | address_conflict_409 | common.product_error |
409 | network_change_pending_409 | common.product_error |
409 | confirm_not_ready_409 | common.product_error |
409 | confirm_not_reachable_409 | common.product_error |
409 | no_pending_config_409 | common.product_error |
409 | network_busy_409 | common.product_error |
409 | network_mutation_blocked_409 | common.product_error |
503 | network_busy_503 | common.product_error |
503 | network_unavailable_503 | common.product_error |
503 | outcome_unknown_503 | common.product_error |
500 | internal_error_500 | common.product_error |
The common errors can also apply.
Examples
Success (202)
curl -X POST -H 'Content-Type: application/json' -d '{"config_id":"00000000-0000-4000-8000-000000000004"}' http://INPUT_IP/api/v1/network/rollbackHTTP 202 application/json
{
"config_id": "00000000-0000-4000-8000-000000000004",
"rollback_started": true
}Rollback idempotent (200)
curl -X POST -H 'Content-Type: application/json' -d '{"config_id":"00000000-0000-4000-8000-000000000004"}' http://INPUT_IP/api/v1/network/rollbackHTTP 200 application/json
{
"active": {
"dns": [],
"gateway": "192.0.2.2",
"hostname": "input-example-1",
"ipv4": "192.0.2.1",
"mode": "dhcp",
...Discovery
DISCOVER udp://device:39590
Discover the numeric HTTP origin and join it to the expected model and MAC over HTTP.
Query String
Not applicable.
Request Body
JSON matching discovery.udp.request.
Responses
| Status | Result | Schema |
|---|---|---|
Reply | success | discovery.udp.response |
Example
UDP datagram to port 39590
{
"protocol": "esp32-p4-discovery",
"type": "esp32_p4.discover",
"version": 1
}UDP reply
{
"base_url": "http://192.0.2.1",
"mac": "02:00:00:00:00:01",
"model": "esp32-p4-npn-pnp-input",
"product_class": "input",
"protocol": "esp32-p4-discovery",
"type": "esp32_p4.discovery",
...Web Interface
GET /
Serve the dashboard; each open dashboard uses one SSE connection.
Query String
No query string is accepted.
Request Body
No request body is accepted.
Example
curl http://INPUT_IP/HTTP 200 text/html; charset=utf-8
(67,792 bytes)GET /input_model.mjs
Serve the dashboard input-state model module.
Query String
No query string is accepted.
Request Body
No request body is accepted.
Example
curl http://INPUT_IP/input_model.mjsHTTP 200 text/javascript; charset=utf-8
(21,202 bytes)Event Stream
GET /api/v1/events opens a server-sent event stream. A new stream starts with stream_checkpoint, whose id is the latest retained cursor, then delivers retained records as they are published.
| Event | Retained | SSE id | Schema |
|---|---|---|---|
stream_checkpoint | No | latest retained cursor | events.stream_checkpoint |
system | Yes | 1 | events.system_event |
input_initialized | Yes | individual cursor | inputs.initialized |
input_acquisition_gap | Yes | individual cursor | inputs.gap |
input_batch | Yes | last cursor in batch | inputs.batch |
error | No | no id field | events.terminal_error |
Input Batches
Transitions arrive as input_batch frames of 1 to
32 rows. Each frame is sent as soon as transitions are available;
there is no batching delay. Its data is a JSON string holding standard base64 of a
55-byte little-endian header followed by
9-byte rows.
| Offset | Field | Type |
|---|---|---|
| 0 | version | u8 |
| 1 | count | u8 |
| 2 | ptp_state | u8 |
| 3 | first_transition | u64 |
| 11 | base_mono_ns | u64 |
| 19 | base_ptp_ns | u64 |
| 27 | ptp_epoch | u64 |
| 35 | ptp_generation | u32 |
| 39 | delivery_drops | u64 |
| 47 | delivery_epoch | u64 |
| Offset | Field | Type |
|---|---|---|
| 0 | channel_state | u8 |
| 1 | mono_offset_ns | u32 |
| 5 | ptp_offset_ns | u32 |
channel_stateis2 × (channel − 1) + asserted.- Each row's timestamps are the header bases plus the row's offsets, in nanoseconds. The first row's offsets are zero.
ptp_stateis an index intounavailable,unsynchronized,acquiring,holdover,synchronized. Withunavailable, the PTP base, offsets, epoch, and generation are zero.- The frame's SSE id is the cursor of its last row; earlier rows count back from it.
Transition IDs are a separate sequence:
first_transitionplus the row index. - Read 64-bit fields as
BigIntin JavaScript, or as integers in Python. Never convert them through floating-point numbers.
This decoder returns the same individual events as the firmware's reference decoder:
const k_header_bytes = 55;
const k_row_bytes = 9;
const k_maximum_rows = 32;
const k_ptp_states = ['unavailable', 'unsynchronized', 'acquiring', 'holdover', 'synchronized'];
/**
* Decodes one `input_batch` server-sent event into individual input events.
* 64-bit values stay exact: they are read as BigInt and returned as decimal strings.
*
* @param {string} payload The frame's base64 payload: `JSON.parse(frame.data)`.
* @param {string} last_event_id The frame's SSE `id`, which belongs to its last row.
*/
export function decode_input_batch(payload, last_event_id) {
const bytes = Uint8Array.from(atob(payload), (character) => character.charCodeAt(0));
const view = new DataView(bytes.buffer);
const count = view.getUint8(1);
if (
view.getUint8(0) !== 1 ||
count < 1 ||
count > k_maximum_rows ||
bytes.length !== k_header_bytes + k_row_bytes * count
) {
throw new Error('Unsupported input_batch frame');
}
const state = k_ptp_states[view.getUint8(2)];
if (state === undefined) {
throw new Error('Unknown PTP state');
}
const first_transition = view.getBigUint64(3, true);
const base_mono_ns = view.getBigUint64(11, true);
const base_ptp_ns = view.getBigUint64(19, true);
const ptp_epoch = view.getBigUint64(27, true);
const ptp_generation = view.getUint32(35, true);
const drops = view.getBigUint64(39, true);
const delivery_epoch = view.getBigUint64(47, true);
const first_event_id = BigInt(last_event_id) - BigInt(count) + 1n;
return Array.from({ length: count }, (_, index) => {
const row = k_header_bytes + k_row_bytes * index;
const channel_state = view.getUint8(row);
return {
event: 'input',
id: String(first_event_id + BigInt(index)),
data: {
transition: Number(first_transition + BigInt(index)),
channel: Math.floor(channel_state / 2) + 1,
asserted: channel_state % 2 === 1,
mono_ns: String(base_mono_ns + BigInt(view.getUint32(row + 1, true))),
ptp: {
ns:
state === 'unavailable'
? null
: String(base_ptp_ns + BigInt(view.getUint32(row + 5, true))),
state,
epoch: ptp_epoch === 0n ? null : String(ptp_epoch),
generation: state === 'unavailable' ? null : ptp_generation
},
delivery: {
drops: String(drops),
epoch: String(delivery_epoch),
continuous: drops === 0n
}
}
};
});
}
// frame.data is the SSE data line and frame.id is its id.
if (frame.event === 'input_batch') {
for (const input of decode_input_batch(JSON.parse(frame.data), frame.id)) {
console.log(input.data.channel, input.data.asserted, input.data.mono_ns);
}
}The event stream examples include a three-row batch with its decoded rows. No input changed while the examples were captured, so this batch was constructed to continue that stream and checked against the firmware's reference decoder.
Reconnecting and Replay
- Reconnect with the
Last-Event-IDheader set to the last cursor you processed, and theboot_idquery set to the boot from the checkpoint. The board replays retained records after that cursor. - A cursor older than retained history returns
410 stale_event_cursor. A cursor from another boot returns409 boot_id_mismatch. In either case, readGET /api/v1/inputsfor the current state and open a new stream without a cursor. - Replay can repeat events you already handled, so deduplicate on the pair
(boot_id, SSE id). BrowserEventSourceadvances its cursor before your handler finishes, so it cannot prove an event was processed. - Every record carries a
deliverysnapshot. Ifdelivery.continuousbecomesfalse, or transition IDs skip, records were dropped before publication; reconcile withGET /api/v1/inputs. - Up to 3 streams can be open at once. Full-rate delivery is specified for 1 stream; more streams share the board's processing and Ethernet capacity.
Conventions
- Security: None; trusted control networks only. No TLS or permissive CORS. Deploy the board only on a trusted control network.
- Responses: UTF-8, application/json, Cache-Control:no-store, one trailing newline.
- Requests: Reject unknown/duplicate keys, non-object bodies, invalid numeric lexemes and unsupported queries before mutation. JSON Schema validates values; lexical and semantic constraints are documented separately. Request bodies are limited to 2,048 bytes.
- Timestamps:
mono_nsis nanoseconds since boot. Itsptpcompanion hasns,state,epoch, andgeneration;nsisnullwhen PTP is unavailable. - Identity:
boot_idchanges on every boot. Transition IDs and stream cursors restart after a reboot and only have meaning with theirboot_id.
| Format | Encoding |
|---|---|
int64-decimal | Canonical decimal string, -9223372036854775808..9223372036854775807 |
uint64-decimal | Canonical decimal string, 0..18446744073709551615 |
Errors
Errors return a JSON error object matching common.product_error. Branch on the HTTP status and error.code, not the message; retryable says whether repeating the request can succeed. Any endpoint can return
these:
| Status | Code |
|---|---|
400 | bad_request |
404 | not_found |
405 | method_not_allowed |
408 | timeout |
413 | content_too_large |
415 | unsupported_media_type |
417 | expectation_failed |
503 | busy |
503 | unavailable |
Performance
- The design target is all twelve channels switching at 1 kHz with no debounce: 24,000 transitions per second.
- In a one-hour endurance run at that rate, the board captured and delivered all 86,400,084 transitions to one stream. All 7,200 reads made during the run returned within 312 ms, and each reconnect after a two-second disconnect caught up within seven seconds.
- A reconnecting stream drains retained history at more than 30,000 transitions per second while inputs keep arriving.
- Retained history holds 240,000 records, about ten seconds at the full design rate.
Schemas
JSON Schema 2020-12 definitions for every request, response, and event.
common.boot_id
{
"pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$",
"type": "string"
}common.git_sha
{
"pattern": "^[0-9a-f]{40}(?:-dirty)?$",
"type": "string"
}common.mac
{
"pattern": "^(?!00:00:00:00:00:00$)[0-9a-f][02468ace](?::[0-9a-f]{2}){5}$",
"type": "string"
}common.product_error
{
"additionalProperties": false,
"properties": {
"error": {
"additionalProperties": false,
"properties": {
"code": {
"type": "string"
},
...common.public_id
{
"maximum": 9007199254740991,
"minimum": 1,
"type": "integer"
}common.public_id_or_zero_sentinel
{
"maximum": 9007199254740991,
"minimum": 0,
"type": "integer"
}debug.time
{
"additionalProperties": false,
"properties": {
"boot_id": {
"minLength": 1,
"type": "string"
},
"device_time_ns": {
"description": "Canonical unsigned decimal in 0..18446744073709551615. Never convert to a JavaScript Number.",
...discovery.api_root
{
"additionalProperties": false,
"properties": {
"api_version": {
"const": "1.0"
},
"capabilities": {
"const": [
"system",
...discovery.health
{
"additionalProperties": false,
"allOf": [
{
"else": {
"properties": {
"faults": {
"maxItems": 0
}
...discovery.info
{
"additionalProperties": false,
"properties": {
"api_version": {
"const": "1.0"
},
"boot_id": {
"$ref": "#/$defs/common.boot_id"
},
...discovery.time
{
"additionalProperties": false,
"properties": {
"boot_id": {
"$ref": "#/$defs/common.boot_id"
},
"mono_ns": {
"description": "Canonical unsigned decimal in 0..18446744073709551615. Never convert to a JavaScript Number.",
"format": "uint64-decimal",
...discovery.udp.request
{
"additionalProperties": false,
"properties": {
"protocol": {
"const": "esp32-p4-discovery"
},
"type": {
"const": "esp32_p4.discover"
},
...discovery.udp.response
{
"additionalProperties": false,
"properties": {
"base_url": {
"pattern": "^http://(?:(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])$",
"type": "string"
},
"mac": {
"$ref": "#/$defs/common.mac"
...events.boot_id
{
"$ref": "#/$defs/common.boot_id"
}events.query
{
"additionalProperties": false,
"properties": {
"boot_id": {
"$ref": "#/$defs/events.boot_id"
}
},
"type": "object"
}events.request_headers
{
"additionalProperties": true,
"properties": {
"last-event-id": {
"$ref": "#/$defs/events.safe_u53_decimal_or_zero"
}
},
"type": "object"
}events.safe_u53_decimal_or_zero
{
"pattern": "^(0|[1-9][0-9]{0,14}|[1-8][0-9]{15}|900[0-6][0-9]{12}|90070[0-9]{11}|90071[0-8][0-9]{10}|900719[0-8][0-9]{9}|9007199[0-1][0-9]{8}|90071992[0-4][0-9]{7}|900719925[0-3][0-9]{6}|9007199254[0-6][0-9]{5}|90071992547[0-3][0-9]{4}|9007199254740[0-8][0-9]{2}|90071992547409[0-8][0-9]|900719925474099[0-1])$",
"type": "string"
}events.stale_event_cursor
{
"additionalProperties": false,
"properties": {
"boot_id": {
"$ref": "#/$defs/events.boot_id"
},
"code": {
"const": "stale_event_cursor"
},
...events.stream_checkpoint
{
"additionalProperties": false,
"properties": {
"boot_id": {
"$ref": "#/$defs/events.boot_id"
},
"latest_event_id": {
"$ref": "#/$defs/common.public_id"
},
...events.system_event
{
"additionalProperties": false,
"properties": {
"boot_id": {
"$ref": "#/$defs/events.boot_id"
},
"state": {
"enum": [
"ok",
...events.terminal_error
{
"oneOf": [
{
"$ref": "#/$defs/events.stale_event_cursor"
},
{
"$ref": "#/$defs/events.event_publisher_unavailable"
}
]
}inputs.batch
{
"contentEncoding": "base64",
"description": "Canonical base64 of a little-endian 55-byte v1 header and 1..32 nine-byte rows. SSE id is the final cursor, not the transition ID. See embedded protocol description. Validate with input_api.decode_input_batch.",
"maxLength": 460,
"minLength": 88,
"type": "string"
}inputs.capabilities
{
"additionalProperties": false,
"properties": {
"channel_numbers": {
"const": {
"count": 12,
"first": 1
}
},
...inputs.channel
{
"additionalProperties": false,
"properties": {
"asserted": {
"anyOf": [
{
"type": "boolean"
},
{
...inputs.configuration
{
"additionalProperties": false,
"properties": {
"debounce_us": {
"maximum": 1000000,
"minimum": 0,
"type": "integer"
}
},
...inputs.decoded_batch
{
"items": {
"additionalProperties": false,
"properties": {
"data": {
"$ref": "#/$defs/inputs.event"
},
"event": {
"const": "input"
...inputs.delivery
{
"additionalProperties": false,
"properties": {
"continuous": {
"type": "boolean"
},
"drops": {
"description": "Canonical unsigned decimal in 0..18446744073709551615. Never convert to a JavaScript Number.",
"format": "uint64-decimal",
...inputs.event
{
"additionalProperties": false,
"properties": {
"asserted": {
"type": "boolean"
},
"channel": {
"maximum": 12,
"minimum": 1,
...inputs.gap
{
"additionalProperties": false,
"properties": {
"abandoned_slots": {
"description": "Canonical unsigned decimal in 0..18446744073709551615. Never convert to a JavaScript Number.",
"format": "uint64-decimal",
"maxLength": 20,
"pattern": "^(0|[1-9][0-9]*)$",
"type": "string"
...inputs.initialized
{
"additionalProperties": false,
"properties": {
"asserted": {
"type": "boolean"
},
"channel": {
"maximum": 12,
"minimum": 1,
...inputs.point
{
"additionalProperties": false,
"properties": {
"mono_ns": {
"description": "Canonical unsigned decimal in 0..18446744073709551615. Never convert to a JavaScript Number.",
"format": "uint64-decimal",
"maxLength": 20,
"pattern": "^(0|[1-9][0-9]*)$",
"type": "string"
...inputs.ptp
{
"additionalProperties": false,
"oneOf": [
{
"properties": {
"epoch": {
"type": "null"
},
"generation": {
...inputs.snapshot
{
"additionalProperties": false,
"properties": {
"acquisition_gaps": {
"description": "Canonical unsigned decimal in 0..18446744073709551615. Never convert to a JavaScript Number.",
"format": "uint64-decimal",
"maxLength": 20,
"pattern": "^(0|[1-9][0-9]*)$",
"type": "string"
...inputs.transition
{
"additionalProperties": false,
"properties": {
"asserted": {
"type": "boolean"
},
"mono_ns": {
"description": "Canonical unsigned decimal in 0..18446744073709551615. Never convert to a JavaScript Number.",
"format": "uint64-decimal",
...network.confirm.request
{
"additionalProperties": false,
"properties": {
"config_id": {
"$ref": "#/$defs/common.boot_id"
}
},
"required": [
"config_id"
...network.patch.apply_response
{
"$ref": "#/$defs/network.response"
}network.patch.request
{
"additionalProperties": false,
"allOf": [
{
"if": {
"properties": {
"mode": {
"const": "dhcp"
}
...network.patch.validate_response
{
"additionalProperties": false,
"properties": {
"candidate": {
"additionalProperties": false,
"properties": {
"hostname": {
"type": "string"
},
...network.response
{
"additionalProperties": false,
"properties": {
"active": {
"additionalProperties": false,
"properties": {
"dns": {
"items": {
"type": "string"
...network.rollback.response
{
"additionalProperties": false,
"properties": {
"config_id": {
"$ref": "#/$defs/common.boot_id"
},
"rollback_started": {
"const": true
}
...power.response
{
"additionalProperties": false,
"properties": {
"sample": {
"anyOf": [
{
"additionalProperties": false,
"allOf": [
{
...system.reboot.request
{
"additionalProperties": false,
"properties": {},
"type": "object"
}system.reboot.response
{
"additionalProperties": false,
"properties": {
"boot_id": {
"$ref": "#/$defs/common.boot_id"
},
"delay_ms": {
"const": 250
}
...system.response
{
"additionalProperties": false,
"properties": {
"boot_id": {
"$ref": "#/$defs/common.boot_id"
},
"boot_stage": {
"enum": [
"not_started",
...system.terminal_fault
{
"additionalProperties": false,
"properties": {
"boot_id": {
"$ref": "#/$defs/common.boot_id"
},
"classification": {
"enum": [
"none",
...