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 ModeWhy Naïve Implementations BreakProduction Guardrail
OTA fails despite HTTP 200300B+ presigned cloud URL truncated by MCU bufferFixed <= 48B HMAC short-signed endpoint
Cellular connection drops at 72%RAM too small to cache full .bin imageHTTP Range (206) 4 KB chunked fetch + CRC32
Bad firmware rollout hits fleetAll units pulled unverified image at onceCanary bucket gate (1%->100%) + instant halt

Full-Stack Architecture Guides & Source Modules