02 · Python server · 2025
Nerva PiServer
The server that feeds Nerva: one frame of system stats, every second, to every client.
Raspberry Pi
stats_broadcaster.py
psutil · vcgencmd
ws://0.0.0.0:8765
Nerva app
Flutter, on the phone
client.html
Dashboard in a browser
Any client
Anything that speaks WebSocket
- Role
- Design and development
- Stack
- Python 3, asyncio, websockets, psutil
- Runs on
- Any Raspberry Pi
- Pairs with
- Nerva
One frame a second
A small asyncio server runs on the Pi. Every second it reads the system with psutil and the Pi's own vcgencmd, then sends one JSON frame to every connected client.
Clients come and go freely: each one is registered on connect, dropped cleanly when it closes, and kept alive with a ping every 20 seconds.
CPU
Overall and per-core usage, core counts, and current, minimum and maximum frequency.
Memory and storage
RAM and swap in detail, every mounted partition, and disk read and write counters.
Network
Bytes and packets in and out, errors and drops, and every interface with its address.
Processes and heat
The ten heaviest processes by CPU, the Pi's CPU temperature and every other sensor.
The frame
Start the server, connect to ws://YOUR_PI_IP:8765, and frames like this one arrive every second. Values from the project's README.
$ python3 stats_broadcaster.py serving on 0.0.0.0:8765 { "timestamp": "2025-07-14T10:30:00.123456", "cpu_usage_percent": 45.2, "ram_usage_percent": 62.8, "disk_usage_percent": 78.5, "temperature_celsius": 42.8, "connected_clients": 3}
Under the hood
Broadcaster
An asyncio loop gathers stats, sends to each client, and drops the ones whose connection has closed.
Sensors
Readers for an ultrasonic distance sensor and turbidity on the Pi's GPIO pins, and pH and turbidity from an Arduino over USB serial.
Service scripts
A systemd unit starts the network monitor on boot and restarts it if it stops; shell scripts manage it.