project
Live dashboard for a 16S battery pack
The firmware writes a JSON file every two seconds; the server watches it and pushes to browsers over WebSockets. No network stack on the MCU at all.
The MCU writes a JSON status file every two seconds and reads a command file for instructions. A Node server on a Pi watches for changes with chokidar and pushes updates to every connected browser via Socket.io; new tabs get the last known snapshot on connect, so the screen is never blank.
Commands run the same path in reverse — the browser posts to a REST endpoint, the server writes the command file, the firmware sets an acknowledged flag after acting. The UI polls that flag and confirms the FET actually switched, not just that the request was sent. That distinction matters when you’re toggling a charge MOSFET on a 16S pack.
History goes to SQLite in WAL mode, chosen because chart reads and telemetry writes happen concurrently. Charts downsample to ~300 points at query time with bucketed SQL averaging, so they stay responsive from a one-hour range to seven days.
What I took away
Bridging the gap between a resource-constrained MCU and a real-time web UI without requiring the firmware to implement any network stack was a challenge faced. Adopted a file-based bridge pattern: firmware writes bms_status.json atomically every 2s and reads bms_command.json for commands, completely decoupling it from the web layer. The Node.js server uses chokidar to detect file changes and fan out updates to all connected clients via Socket.io.
SQLite with WAL mode handles concurrent reads without locking issues on the Pi; history queries use time-bucketed averaging (GROUP BY bucket) to downsample to ~300 points regardless of the selected time range, keeping chart rendering fast. This helped solve the issue of storing continuous BMS telemetry on a Raspberry Pi without degrading SD card lifespan or overwhelming chart rendering with thousands of raw data points.