Skip to content

Keep the LED strip in step when the serial link or ESP32 drops out - #33

Open
Nicolas Palpacuer (NickPPC) wants to merge 1 commit into
mainfrom
led-bridge-resilience
Open

Nicolas Palpacuer (NickPPC) wants to merge 1 commit into
mainfrom
led-bridge-resilience

Conversation

@NickPPC

Copy link
Copy Markdown
Collaborator

Summary

Make led-bridge recover on its own when the LED strip stops following the voice state. On Cappuccina the strip twice stayed orange after a turn ended. Once, a reconnecting USB-serial adapter swallowed idle; the other time the ESP32 stopped running its sketch, so a delivered idle changed nothing.

❓ Open question: the auto-reset relies on the reference firmware's echo lines (ready, received line: …). Firmware that never echoes is never reset, which is safe but means custom sketches get no recovery. Is that the right default, or should it be a config flag?

Changes

  • The state is resent every 3 s while unchanged: a line lost during a re-enumeration or boot is corrected within seconds; the firmware treats a repeat as a no-op
  • A dead port is noticed at once: a reader on the port drops it on a failed read, so Status stops reporting connected: true on a dead handle and the next tick reopens it
  • A silent ESP32 is hard-reset: once the firmware has replied at all, 10 s of unanswered writes pulses RTS with DTR released (esptool's sequence) to boot it back into the sketch, at most every 30 s
  • Status reports firmware liveness: last_reply_at and firmware_resets

The underlying adapter drops look like the strip's current draw browning out the USB port; this PR only makes the bridge recover from them.

Testing

  • go test -race ./resources/led-bridge/ covers resending, reopening an unplugged port, the disconnected Status, resetting firmware that goes silent, and leaving echoing or never-echoing firmware alone
  • Not yet run against the Cappuccina hardware

🤖 Generated with Claude Code

led-bridge wrote a state only when it changed and never read the port, so a
line lost while the CP2102 re-enumerated, or an ESP32 that stopped running its
sketch, left the strip on its last colour indefinitely.

- Resend the current state every 3 s while it is unchanged.
- Read the firmware's replies; a failed read drops the port at once, so
  Status no longer reports a dead handle as connected and it reopens promptly.
- Once the firmware has answered, 10 s without a reply hard-resets the ESP32
  over RTS/DTR (esptool's sequence), at most every 30 s.
- Status gains last_reply_at and firmware_resets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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