Add multi-device support
server.py
- --device is now repeatable (-d ups1:/dev/ttyUSB0 -d ups2:/dev/ttyUSB1). Bare paths (/dev/ttyUSB0) auto-name from the last path component (ttyUSB0).
- Maintains {name: {ser, data, timestamp}} per UPS — each device has independent data freshness.
- GET response is now {ups_name: JBDUPS}. Accepts optional ups key in the request to return only one.
client.py
- read_data() gains ups=None parameter — pass a name to filter server-side, or omit for all.
- Always returns {ups_name: JBDUPS}.
influxdb.py
- influxdb_create_snapshot() iterates {name: JBDUPS} and tags every InfluxDB point with ups=name.
- influxdb_export() / bmspy-influxdb gain --ups to export only a specific UPS.
__init__.py
- bmspy CLI gains --ups to display only a named UPS.
- Displays each UPS under a === name === header.
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
|
||||
bmspy is a tool to get information from a [xiaoxiang-type](https://www.lithiumbatterypcb.com/product/4s-or-3s-12v-li-ion-or-lifepo4-battery-smart-bms-with-bluetooth-function-uart-and-rs485-communication-with-60a-to-120a-constant-current/?attribute_specification-selection=4S+Lifepo4+120A+with+UART+and+RS485) BMS system, using some sort of serial connection.
|
||||
|
||||
It can display the information as text, in JSON, or export the data continuously to a Prometheus exporter.
|
||||
It can display the information as text, in JSON, or export the data continuously to InfluxDB or a Prometheus exporter.
|
||||
|
||||
Multiple BMS/UPS devices can be connected at once. Each is identified by a name, and data from all of them (or just one) can be pushed to InfluxDB or Prometheus in the same connection, with each measurement tagged with the UPS name.
|
||||
|
||||
To install:
|
||||
git clone https://git.treehouse.org.za/tim/bmspy
|
||||
@@ -12,17 +14,42 @@ To install:
|
||||
Or, to install with influxdb and/or prometheus support:
|
||||
poetry install -E influxdb -E prometheus
|
||||
|
||||
To run:
|
||||
poetry run bmspyd &
|
||||
## Running the server
|
||||
|
||||
The server daemon reads from one or more serial devices and makes the data available over a Unix socket.
|
||||
|
||||
Single device (defaults to `/dev/ttyUSB0`):
|
||||
|
||||
poetry run bmspy-server
|
||||
|
||||
Multiple devices, with optional names (default name is derived from the device path, e.g. `ttyUSB0`):
|
||||
|
||||
poetry run bmspy-server -d network:/dev/ttyUSB0 -d nas:/dev/ttyUSB1
|
||||
|
||||
To run via systemd, copy `bmspy-server.service` to `/etc/systemd/system`, adjust `WorkingDirectory` and the `ExecStart` line as needed, then enable and start it:
|
||||
|
||||
Or to run via systemd, copy bmspyd.service to /etc/systemd/system, adjust WorkingDirectory to point to the installation location, and enable and start the service:
|
||||
cp bmspy-server.service /etc/systemd/system
|
||||
$EDITOR /etc/systemd/system/bmspy-server.service
|
||||
systemctl daemon-reload
|
||||
systemctl enable bmspy-server
|
||||
systemctl start bmspy-server
|
||||
|
||||
To run a client to get the data, choose one of the following options:
|
||||
poetry run bmspy
|
||||
poetry run bmspy-influxdb --url ...
|
||||
## Running a client
|
||||
|
||||
To print a summary of all connected UPSes:
|
||||
|
||||
poetry run bmspy
|
||||
|
||||
To show only a specific UPS:
|
||||
|
||||
poetry run bmspy --ups network
|
||||
|
||||
To push data for all UPSes to InfluxDB (each measurement is tagged `ups=<name>`):
|
||||
|
||||
poetry run bmspy-influxdb --url https://influx.example.com --org myorg --token mytoken
|
||||
|
||||
To push data for a single UPS only:
|
||||
|
||||
poetry run bmspy-influxdb --ups network --url ...
|
||||
|
||||
InfluxDB connection details can also be supplied via environment variables (`INFLUXDB_V2_URL`, `INFLUXDB_V2_ORG`, `INFLUXDB_V2_TOKEN`) instead of command-line flags.
|
||||
|
||||
Reference in New Issue
Block a user