Files
led-controller/v2/tools/ota.py
T
jimmyandClaude Sonnet 5.5 6c16998691 feat(v2): OTA firmware update over Ethernet
POST /ota writes the image to the idle app slot and reboots; GET /ota
reports the running slot. App rollback is enabled, and a new image confirms
itself after 10 s. Adds make ota HOST=<ip>, tools/ota.py and the led-tool
--ota update.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-01 00:22:55 +13:00

27 lines
907 B
Python

#!/usr/bin/env python3
"""Upload a firmware image to the controller over Ethernet.
ota.py <host> [build/led_controller_v2.bin]
"""
import http.client
import json
import os
import sys
host = sys.argv[1] if len(sys.argv) > 1 else sys.exit(__doc__)
path = sys.argv[2] if len(sys.argv) > 2 else os.path.join(os.path.dirname(__file__), "..", "build", "led_controller_v2.bin")
size = os.path.getsize(path)
conn = http.client.HTTPConnection(host, 80, timeout=60)
conn.request("GET", "/ota")
print("running:", conn.getresponse().read().decode())
print(f"uploading {path} ({size} bytes)")
with open(path, "rb") as f:
conn.request("POST", "/ota", body=f, headers={"Content-Length": str(size),
"Content-Type": "application/octet-stream"})
r = conn.getresponse()
body = r.read().decode()
print(r.status, body)
sys.exit(0 if r.status == 200 else 1)