Skip to content

Switch to upload baud in place instead of reopening the port - #36

Merged
yozik04 merged 1 commit into
masterfrom
fix-upload-baud-switch
Nov 11, 2026
Merged

yozik04 merged 1 commit into
masterfrom
fix-upload-baud-switch

Conversation

@yozik04

@yozik04 yozik04 commented Nov 11, 2026

Copy link
Copy Markdown
Owner

Refs #19 (also covers the consolidated #26 report).

Problem

  • upload_firmware crashed before uploading anything: logger.info(f"... {upload_baud}" % (upload_baud)) raises TypeError: not all arguments converted during string formatting.
  • After whmi-wri, the client closed the serial port and reopened it at the upload baud. Per the official Upload Protocol v1.1 / v1.2, the device sends 0x05 within 500 ms and the host should change to baudrate, then wait_for_05. Close/reopen can miss that byte (the readiness timeout reported in Upgrade Failed for Nextion 10" Intelligent Series Display #19) and may toggle modem lines on USB adapters.

Change

  • Keep the open transport: swap to the raw BasicProtocol, drain the whmi-wri command (serial.flush()), then set serial.baudrate in place.
  • Use lazy %-style logging for the switch message.

Tests

  • New test_upload_firmware_switches_baud_in_place drives a full upload against a fake device transport: ready byte arrives right after the switch, two chunks (4096 + partial) are acked. Fails on master (TypeError), passes here.
  • pytest: 65 passed. black/flake8 clean.

Not verified

No physical Nextion hardware was available; the chunk-ACK timeout from #26 (Pi Zero /dev/ttyS0) is not proven fixed. Keeping #19 open until someone confirms on a device.

The Nextion upload protocol (v1.1/v1.2) replies 0x05 at the upload baud
within 500 ms of whmi-wri. Closing and reopening the serial port could
miss that byte, and the reopen log line raised TypeError before any
upload started. Keep the open transport, swap to the raw upload protocol,
drain the whmi-wri command and change the baud rate in place.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@yozik04
yozik04 merged commit 311d72b into master Nov 11, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant