Open-Source Firmware & AI Guide

Give this page or https://iot.dev/llms.txt to your AI coding assistant to implement and verify compliant device firmware.

1. Open-source boundary (MIT OR Apache-2.0)

The device contracts (contracts/), shared libraries (crates/), firmware/, connectors/ and tools/cli/ are permanently open source. The firmware/ workspace contains fw-sdk, fw-sdk-c, fw-resident and fw-sim. Its development reference board is the Waveshare ESP32-C6-Relay-1CH-U. The open-source directories build standalone with zero private dependencies using their checked-in manifests and lockfiles (enforced in CI via scripts/check-oss-build.py). Independent MCU firmware can also implement directly against the public contracts and golden byte vectors.

2. Enroll via local key & CSR

Private keys never leave your hardware or workstation. Run iot device add (or generate a P-256 key in the console browser) to submit a PKCS#10 DER CSR to POST /v1/projects/{project_id}/devices/enroll with an Idempotency-Key. Retrying with the same key returns the exact same certificate bundle. Note: browser/portable dev bundles enroll at custody_tier=none (in-range execution only; out-of-range actions are rejected even with approval).

CLI CSR enrollment
iot login
iot device add --project <project_id> --slot zone_a_heater --name "Heater 1"
# Output: device bundle (cert_der_b64, ca_chain_der_b64, authority_trust_root_ed25519_hex, broker_host, broker_port, tsl)

3. Wire protocol constraints

Connect over TLS 1.3 mTLS to configurable broker_host:broker_port (never hardcode IP addresses). Use MQTT 3.1.1 with exactly two topics (up and down), QoS 1, retain=false, max packet 64 KiB, and deterministic CBOR (RFC 8949 §4.2). Non-canonical CBOR, JSON, duplicate keys, or unknown critical fields are rejected.

/contracts/index.json · device-v1.schema.json · wire vectors · safety-invariants · tx-binding vectors

4. On-device safety kernel & persistence

All firmware must save the replay watermark and pending command identity together before actuating an ordinary command. If that write fails, leave the output untouched. If power fails before the outcome is saved, report unknown for the original command on recovery and never repeat the action. The reference firmware uses 16 bytes for seq_high and pending_seq, plus storage for the pending identity. Enforce factory hard_envelopes, dwell_and_slew limits, monotonic PolicyBundle revisions, one-shot boot_nonce CommandGrants, and hardware lease watchdogs that return outputs to safe_value on disconnect or timeout. Rust firmware can reuse the zero-heap no_std iot-safety-kernel. Other MCUs must enforce equivalent local checks against the public contracts and golden vectors. The hw_attested tier also requires hardware key attestation and signed safety-kernel evidence.

5. Verify before deployment

Run iot device verify for passive TSL and diagnostic verification; pass --active only when physical actuation is safe and explicitly confirmed.

Verify against immutable TSL
iot device verify --project <project_id> --device <device_id> --json
# Only when physical actuation is safe:
iot device verify --project <project_id> --device <device_id> --active