Skip to content

Port GarageDoor production improvements: startup watchdog and bounded API parsing - #38

Merged
JamesSmartCell merged 2 commits into
masterfrom
cursor/garagedoor-watchdog-port-557d
Nov 17, 2026
Merged

JamesSmartCell merged 2 commits into
masterfrom
cursor/garagedoor-watchdog-port-557d

Conversation

@JamesSmartCell

Copy link
Copy Markdown
Member

Overview

This PR ports battle-tested production improvements from Rob's GarageDoor firmware (local patches on top of Web3E v1.44) into master. These changes improve reliability and robustness on real ESP32 hardware.

Key Changes

1. Startup Watchdog (30s timeout)

  • Added TcpBridge::armStartupWatchdog() and disarmStartupWatchdog() using esp_timer
  • Fires after 30 seconds if TCP session is not confirmed
  • Catches hangs during WiFi connection, DNS resolution, or TCP handshake
  • Disarmed automatically when session is confirmed (opcode 0x02)
  • E2E test and Wallet Bridge examples updated to call armStartupWatchdog() at start of setup()

2. Connection Timeout Management

  • Added CONNECTION_TIMEOUT_MS (60s), SESSION_TIMEOUT_MS (15min), KEEP_ALIVE_INTERVAL_MS (5min)
  • New connection state tracking with unconnectedTimer and sessionStart
  • checkReset(), resetConnection(), checkConnection(), connectionCheck() methods
  • Restarts device if connection fails to establish within timeout

3. Bounded API Parsing

  • Replaced unbounded scanAPI(apiReturn, available) with bounded scanAPI(packet, apiReturn, payloadLength)
  • Replaced unbounded getArg(index) that read from WiFiClient with bounded getArg(packet, index, payloadLength) that reads from buffer
  • Prevents buffer overflows and heap fragmentation
  • Reads entire packet into fixed packetBuffer[TCP_PACKET_BUFFER_SIZE] at once

4. Web3E Logging Macros

  • Replaced all Serial.print() / Serial.println() with WEB3E_PRINT() / WEB3E_PRINTLN() macros
  • Allows compile-time stripping of debug logs with -DWEB3E_RELEASE
  • Applied across: TcpBridge, UdpBridge, KeyID, Crypto, Web3, Util, uint256

5. sendRefreshRequest Improvements

  • Added retry loop (up to 500 attempts with 10ms delay) to wait for TCP connection
  • Added clear() (arduino-esp32 3.x) / flush() (older versions) after write
  • Calls resetConnection() on timeout instead of hanging

6. maintainComms Session Timeout

  • Added session timeout: resets to handshake state after SESSION_TIMEOUT_MS (15 minutes)
  • Uses checkConnection() instead of inline connection check
  • Maintains keep-alive using KEEP_ALIVE_INTERVAL_MS instead of hardcoded 60 seconds

Compatibility

Testing

  • All changes ported from Rob's production GarageDoor firmware running on real hardware
  • E2E test firmware updated with armStartupWatchdog() call
  • Wallet Bridge examples 1, 2, 3 updated with armStartupWatchdog() call

Files Changed

Core Library

  • src/TcpBridge.{h,cpp} - Watchdog, bounded parsing, connection timeouts
  • src/UdpBridge.cpp - Web3Log macros
  • src/KeyID.cpp - Web3Log macros
  • src/Crypto.cpp - Web3Log macros
  • src/Web3.cpp - Web3Log macros
  • src/Util.cpp - Web3Log macros
  • src/uint256/uint{128,256}_t.cpp - Web3Log macros

Examples & Tests

  • test/hardware/proxy_e2e/src/main.cpp - Added armStartupWatchdog() call
  • examples/Wallet Bridge {1,2,3}/src/main.cpp - Added armStartupWatchdog() call
Open in Web Open in Cursor 

cursoragent and others added 2 commits November 17, 2026 01:27
… API parsing

- Add TcpBridge::armStartupWatchdog() / disarmStartupWatchdog() using esp_timer (30s timeout)
- Add CONNECTION_TIMEOUT_MS, SESSION_TIMEOUT_MS, KEEP_ALIVE_INTERVAL_MS constants
- Replace unbounded scanAPI with bounded packet-buffer version from GarageDoor
- Add connection management: checkReset, resetConnection, checkConnection, connectionCheck
- Add session timeout tracking and unconnected timer with restart on timeout
- Replace heap-allocated APIReturn with inline apiReturn member
- Replace Serial.print/println with WEB3E_PRINT/WEB3E_PRINTLN macros throughout
- Update sendRefreshRequest with retry logic and flush/clear for arduino-esp32 3.x
- Maintain KEEP_ALIVE_INTERVAL_MS instead of hardcoded 60s
- Update e2e test and Wallet Bridge examples to call armStartupWatchdog() in setup()

All changes ported from Rob's production GarageDoor firmware (v1.44 + local patches).
Keeps existing opcode 0x09/0x0A, setProxy, and percolate.one:8083 defaults from PR #37.

Co-authored-by: James Brown <JamesSmartCell@users.noreply.github.com>
…me declaration

- Fixed sed search-replace error: WEB3E_PRINTln -> WEB3E_PRINTLN in:
  - src/UdpBridge.cpp
  - src/Util.cpp
  - src/uint256/uint128_t.cpp
  - src/uint256/uint256_t.cpp
- Restored long getLastCommsTime() declaration in TcpBridge.h (still in use)
- ecdsa.c RFC6979 functions: already in rfc6979.c, no duplicate code in master

Verified clean build with PlatformIO:
- test/hardware/proxy_e2e (esp32dev): SUCCESS
- examples/Wallet Bridge 1 (esp32dev): SUCCESS

Co-authored-by: James Brown <JamesSmartCell@users.noreply.github.com>
@JamesSmartCell
JamesSmartCell merged commit ef0ef69 into master Nov 17, 2026
7 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.

2 participants