Skip to content

Instantly share code, notes, and snippets.

@tserong
Created April 27, 2022 06:16
Show Gist options
  • Save tserong/47f805be897f59d3834d669d23549a79 to your computer and use it in GitHub Desktop.
Save tserong/47f805be897f59d3834d669d23549a79 to your computer and use it in GitHub Desktop.
Log ZCell voltage, bus voltage and warning indicator status
#!/bin/bash
#
# Polls the ZCell BMS REST API once per second and prints the
# voltage, bus voltage and warning indicator status if they've
# changed since the last poll. Runs indefinitely.
# Requires `curl` and `jq`.
#
# Note: this only looks at the first battery in the system
# (".list[0]" in the `jq` invocation).
#
if [ -z "$1" ]; then
echo "Usage: $(basename $0) BMS_IP [POLL_INTERVAL]"
exit 1
fi
STATUS_URL="http://${1}:3000/rest/1.0/status"
INTERVAL="${2:-1}"
LAST=""
echo "Polling ${STATUS_URL} at ${INTERVAL} second intervals"
echo "voltage bus_voltage warning_indicator over_current_warning over_voltage_warning battery_temperature_warning other_warning"
while true ; do
WARNINGS="$(curl -s ${STATUS_URL} | jq -r '[
.list[0].voltage,
.list[0].bus_voltage,
(if .list[0].warning_indicator then "W" else "_" end),
(if .list[0].over_current_warning then "C" else "_" end),
(if .list[0].over_voltage_warning then "V" else "_" end),
(if .list[0].battery_temperature_warning then "T" else "_" end),
(if .list[0].other_warning then "O" else "_" end)
] | join (" ")')"
if [ "$WARNINGS" != "$LAST" ] ; then
echo -e "$(date --iso-8601=seconds)\t${WARNINGS}"
LAST="${WARNINGS}"
fi
sleep $INTERVAL
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment