Public Access
The Arduino network client treats a half-closed connection as closed, so the device's reply after the sender's EOF was lost. The header already carries the image size: UpdateParser::complete() lets the device finish and answer while the connection is open. ota_push.py half-closes only if no answer comes within 3 s, for older firmware. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
54 lines
1.6 KiB
Python
Executable File
54 lines
1.6 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Pushes a signed Update File to a Cardputer over Wi-Fi (TCP 3232) and reports the result.
|
|
|
|
Usage: scripts/ota_push.py <file.ota> <host>
|
|
<host> is the device's IP (shown in Settings > About), or its name when mDNS works on your network.
|
|
"""
|
|
import socket
|
|
import sys
|
|
|
|
PORT = 3232
|
|
|
|
|
|
def main():
|
|
if len(sys.argv) < 3:
|
|
sys.exit(__doc__)
|
|
path, host = sys.argv[1:3]
|
|
data = open(path, "rb").read()
|
|
with socket.create_connection((host, PORT), timeout=15) as s:
|
|
s.settimeout(60)
|
|
sent, last = 0, -1
|
|
while sent < len(data):
|
|
chunk = data[sent:sent + 4096]
|
|
s.sendall(chunk)
|
|
sent += len(chunk)
|
|
pct = sent * 100 // len(data)
|
|
if pct != last:
|
|
print(f"\rsending {pct:3d}%", end="", flush=True)
|
|
last = pct
|
|
# The header announces the image size, so current firmware answers once it has it all.
|
|
# Firmware from before that change only knows the file ended when we half-close.
|
|
reply = b""
|
|
s.settimeout(3)
|
|
try:
|
|
reply = s.recv(256)
|
|
except socket.timeout:
|
|
s.shutdown(socket.SHUT_WR)
|
|
s.settimeout(60)
|
|
while reply == b"" or not reply.endswith(b"\n"):
|
|
try:
|
|
part = s.recv(256)
|
|
except socket.timeout:
|
|
break
|
|
if not part:
|
|
break
|
|
reply += part
|
|
print()
|
|
reply = reply.decode(errors="replace").strip()
|
|
print(f"device: {reply or '(no answer)'}")
|
|
sys.exit(0 if reply.startswith("OK") else 1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|