You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: defer WS hardware ops to main loop; clean up webserver init
The /snapshot WebSocket handler runs on the AsyncTCP task. Several
commands (display, low_power, sleep, power_off) were calling
u8g2.setPowerSave / u8g2.setContrast / digitalWrite(PWR_CTRL,...)
directly from that task while the main loop hammered the same
peripherals — under feature-test load at 10Hz this caused the device
to stall for ~4s and HTTP responses to time out mid-body.
* Add a portMUX-protected pending-action mask. The WS callback
queues the hardware op and updates the matching state flag
(b_u8g2Sleep / b_softSleep) synchronously so the status frame is
accurate; the main loop drains the mask early in loop() (before
the b_softSleep guard so SLEEP_OFF can wake the device).
* StopWatch.* is just bool/uint32 writes, so timer ops stay
synchronous in the callback.
* webserver.h: register handlers only once across stop/start
cycles, drop the duplicate addHandler(&websocket), and move
server.begin() to the end of startWebServer() so handlers are
in place before the server accepts requests.
* WS DATA callback: build the String with the (buf,len)
constructor instead of O(N²) char-by-char concatenation, and
only process complete unfragmented text frames.
* Use unsigned long for the WS broadcast lastUpdate to avoid
signed-subtraction wrap at the millis() 49.7-day rollover.
* Document why WiFi.setSleep(false) is the wrong call here:
tested it, caused 8% loss and HTTP all-timeout when BLE is
active because BT/WiFi share the 2.4GHz radio and the coex
layer needs WiFi sleep windows for BT slots.
Stress test (10Hz WS + HTTP every 1s + 5 cmd/s feature chaos, 120s):
pre-fix post-fix
max gap 4.18 s 0.90 s
HTTP fail 1 0
HTTP slow 2 0
Feature regression (60 WS commands) still 60/60 PASS.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
0 commit comments