Skip to content

Improve TFT/GUI upload reliability#364

Open
jamesmulcahy wants to merge 1 commit intoNSPManager:mainfrom
jamesmulcahy:gui-upgrade-reliability
Open

Improve TFT/GUI upload reliability#364
jamesmulcahy wants to merge 1 commit intoNSPManager:mainfrom
jamesmulcahy:gui-upgrade-reliability

Conversation

@jamesmulcahy
Copy link
Copy Markdown
Contributor

  • Replace the per-chunk upload loop with a single currentOffset variable that only advances after a valid ACK, fixing silent corruption when the display rejects a chunk (previously the offset advanced before reading the ACK)

  • Handle 0x08 skip response correctly: non-zero offset jumps ahead in the file; zero offset means "continue sequentially" and now correctly advances currentOffset rather than re-sending the previous chunk (which was corrupting the flash)

  • Parse all 4 offset bytes for 0x08 with a generous 10s timeout, matching the first-byte timeout — the display sends 0x08 immediately but may take several seconds to compute and transmit the offset

  • Send connect twice during init; some displays silently discard the first command after DRAKJHSUYDGBNCJHGJKSHBDN, and the 10s read window catches whichever connect gets a response. A 500ms discard read drains any second comok from panels that respond to both.

  • Always initiate TFT handshake at 9600 baud (Nextion power-on default); switch to tft_upload_baud for data transfer via whmi-wri(s). Retry at 9600 on comok failure.

  • Fix HttpLib::DownloadChunk: remove available()-capped readBytes call that returned short reads whenever TCP segments were still in flight

  • Add streaming MD5 over all sent bytes, compared against server checksum after upload completes; comparison skipped if display requested offset jumps

  • Add consecutive_errors counter with reboot threshold across all ACK failure paths; reset to zero on any successful ACK

  • Guard tft_update MQTT command: reject with error log if manager_address is not yet known (avoids URL-with-empty-host failure)

  • Wake display with sleep=0 after comok exchange before sending whmi-wri

  • Increase NSPanel::init() display power-on wait from 1s to 3s to give the display time to boot before the NSPM flag detection window opens

- Replace the per-chunk upload loop with a single currentOffset variable that
  only advances after a valid ACK, fixing silent corruption when the display
  rejects a chunk (previously the offset advanced before reading the ACK)

- Handle 0x08 skip response correctly: non-zero offset jumps ahead in the file;
  zero offset means "continue sequentially" and now correctly advances currentOffset
  rather than re-sending the previous chunk (which was corrupting the flash)

- Parse all 4 offset bytes for 0x08 with a generous 10s timeout, matching the
  first-byte timeout — the display sends 0x08 immediately but may take several
  seconds to compute and transmit the offset

- Send connect twice during init; some displays silently discard the first command
  after DRAKJHSUYDGBNCJHGJKSHBDN, and the 10s read window catches whichever
  connect gets a response. A 500ms discard read drains any second comok from
  panels that respond to both.

- Always initiate TFT handshake at 9600 baud (Nextion power-on default); switch
  to tft_upload_baud for data transfer via whmi-wri(s). Retry at 9600 on comok
  failure.

- Fix HttpLib::DownloadChunk: remove available()-capped readBytes call that
  returned short reads whenever TCP segments were still in flight

- Add streaming MD5 over all sent bytes, compared against server checksum after
  upload completes; comparison skipped if display requested offset jumps

- Add consecutive_errors counter with reboot threshold across all ACK failure
  paths; reset to zero on any successful ACK

- Guard tft_update MQTT command: reject with error log if manager_address is
  not yet known (avoids URL-with-empty-host failure)

- Wake display with sleep=0 after comok exchange before sending whmi-wri

- Increase NSPanel::init() display power-on wait from 1s to 3s to give the
  display time to boot before the NSPM flag detection window opens

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jamesmulcahy jamesmulcahy changed the title Fix multiple bugs in TFT/GUI upload reliability Improve TFT/GUI upload reliability Apr 24, 2026
@tpanajott
Copy link
Copy Markdown
Collaborator

Hey, this is all awesome work and I really appreciate it! Where did you find all the details in how the panel handles things internally?

The firmware has moved from here to it's own repo available here. I can manually move the changes over if you'd like or you can open a PR towards that repo if you care to have your profile considered a contributor to the project.

@jamesmulcahy
Copy link
Copy Markdown
Contributor Author

I asked Claude Code to compare my implementation to the new firmware repo, and work out which changes needed moving. Seems like many of the fixes are already in the newer releases -- which indeed explains why I had so much success updating my panels overnight. It did find one buffer overflow bug, and there are some small tweaks we can port forward -- but the core protocol changes seem to already be incorporated.

Attaching Claude's analysis here for visibility -- but I'll submit PRs to the new repo.
nspm firmware fix analysis.md

@tpanajott
Copy link
Copy Markdown
Collaborator

Had a read through your attached document and agree. There are a few things that for sure can be handled better. Hopefully this can resolve #340

@tpanajott
Copy link
Copy Markdown
Collaborator

I believe this PR can be closed as all the issues raised has been handled in the following PRs:

Do you have any objections? Once again, thanks for your help.

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.

2 participants