Commit 7a3b51c
feat: allow multiple concurrent WS clients (web UI + app)
The previous middleware returned 503 to any client past the first,
which meant opening the on-device web UI prevented a phone/desktop
app from connecting to the same scale. Drop the cap and let the
library handle multi-client.
* include/webserver.h: remove the count-checking middleware so any
handshake within the library's DEFAULT_MAX_WS_CLIENTS limit
succeeds.
* src/hds.ino: call websocket.cleanupClients() with no argument so
we inherit the library default (DEFAULT_MAX_WS_CLIENTS, which is
8 on ESP32). Plenty of RAM headroom — ~12-14 KB per client on
top of ~240 KB free heap.
* src/hds.ino WS_EVT_DISCONNECT: only reset the shared session
state (weightWebsocketNotifyInterval, b_websocketEventsEnabled,
t_lastWebsocketStatusUpdate) when the LAST client leaves
(server->count() == 0). Without this guard, one client
disconnecting would wipe rate/events state for any other client
still connected.
Verified with /tmp/ws_multi.py (5/5):
* Two simultaneous handshakes both succeed (was: 2nd got 503).
* Both clients receive the weight stream at the negotiated rate
(2Hz default, 10Hz after `rate 10`).
* Both clients see the periodic status broadcast after `events on`.
* Disconnecting client A leaves client B's stream + state intact.
Single-client feature regression still 60/60 PASS.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>1 parent 74d7f0f commit 7a3b51c
2 files changed
Lines changed: 16 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
52 | 46 | | |
53 | 47 | | |
54 | 48 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
958 | 958 | | |
959 | 959 | | |
960 | 960 | | |
961 | | - | |
962 | | - | |
963 | | - | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
964 | 970 | | |
965 | 971 | | |
966 | 972 | | |
| |||
1987 | 1993 | | |
1988 | 1994 | | |
1989 | 1995 | | |
1990 | | - | |
| 1996 | + | |
| 1997 | + | |
| 1998 | + | |
1991 | 1999 | | |
1992 | 2000 | | |
1993 | 2001 | | |
| |||
0 commit comments