aiot-production-kit / constrained-ota
GO 1.21+ · CONSTRAINED OTA REFERENCE
Constrained MCU HTTP Range OTA & Short-Signed URL Server
Eliminates the #1 EV charger and AIoT field bricking failure: S3/OSS presigned URLs exceeding 96–128 byte embedded MCU buffers.
TL;DR ENGINEERING FACTS
- Fixed <= 48-Byte Short-Signed Paths: Issues `/f/<id>?e=<unix>&s=<12hex>` tokens that fit cleanly inside AT-command and OCPP UpdateFirmware buffers.
- Resumable HTTP 206 Range Chunks: Serves 4 KB chunks with per-chunk `X-Chunk-CRC32` and full-image `X-Firmware-SHA256` verification.
- Canary Bucketing & Instant Kill Fuse: Deterministic hash rollouts (`1% -> 10% -> 50% -> 100%`) halt immediately if field rollback spikes.
Run & Test Locally (Zero External Dependencies)
go test ./... go run ./cmd/constrained-ota-server -dir ./firmware -secret "replace-me" -canary 100 curl -s "http://127.0.0.1:8090/manifest?id=ev204&device=charger-001" curl -i -H "Range: bytes=0-4095" "http://127.0.0.1:8090/f/ev204?e=...&s=..."
Field Failure Mode vs. Spacebit Reference Fix
| Field Failure Mode | Why Naïve Implementations Break | Production Guardrail |
|---|---|---|
| OTA fails despite HTTP 200 | 300B+ presigned cloud URL truncated by MCU buffer | Fixed <= 48B HMAC short-signed endpoint |
| Cellular connection drops at 72% | RAM too small to cache full .bin image | HTTP Range (206) 4 KB chunked fetch + CRC32 |
| Bad firmware rollout hits fleet | All units pulled unverified image at once | Canary bucket gate (1%->100%) + instant halt |