OTA: answer once the announced image size has arrived

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
This commit is contained in:
2026-10-03 21:39:35 +02:00
co-authored by Claude Opus 5.5
parent fa62a07993
commit 08b59eb203
4 changed files with 37 additions and 5 deletions
+18 -5
View File
@@ -17,16 +17,29 @@ def main():
data = open(path, "rb").read()
with socket.create_connection((host, PORT), timeout=15) as s:
s.settimeout(60)
sent = 0
sent, last = 0, -1
while sent < len(data):
chunk = data[sent:sent + 4096]
s.sendall(chunk)
sent += len(chunk)
print(f"\rsending {sent * 100 // len(data):3d}%", end="", flush=True)
s.shutdown(socket.SHUT_WR) # end of file: the device checks it and answers
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""
while not reply.endswith(b"\n"):
part = s.recv(256)
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