Add support for X708 UPS HAT (#3087)

This commit is contained in:
HiLivin 2022-09-28 17:13:54 +02:00 committed by GitHub
parent 20045be2f2
commit 6aea40a58b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 4 deletions

6
FAQ.md
View File

@ -620,10 +620,12 @@ See issues #3039, #1053 & #782
A UPS (Uninterruptible Power Supply) is used to protect the RaspiBlitz against power outages. Normally you put it just between your normal power outlet and your RaspiBlitz and you are set. But some UPS offer a way to communicate with devices. This can be very useful for example if on a longer power outage the battery of the UPS runs low the RaspiBlitz could detect this and power down in a clean way - instead of a sudden stop that risks data loss or corruption. A UPS (Uninterruptible Power Supply) is used to protect the RaspiBlitz against power outages. Normally you put it just between your normal power outlet and your RaspiBlitz and you are set. But some UPS offer a way to communicate with devices. This can be very useful for example if on a longer power outage the battery of the UPS runs low the RaspiBlitz could detect this and power down in a clean way - instead of a sudden stop that risks data loss or corruption.
There is an experimental script to connect the RaspiBlitz to a UPS over USB cable build by APC - the Model tested with was [APC Back-UPS BX - BX700U-GR](https://www.amazon.de/APC-Back-UPS-Unterbrechungsfreie-Stromversorgung-BX700U-GR/dp/B00T7BYRCK) but it should work with every APC model offering a USB port. - There is an experimental script to connect the RaspiBlitz to a UPS over USB cable build by APC - the Model tested with was [APC Back-UPS BX - BX700U-GR](https://www.amazon.de/APC-Back-UPS-Unterbrechungsfreie-Stromversorgung-BX700U-GR/dp/B00T7BYRCK) but it should work with every APC model offering a USB port. \
To turn it on run from terminal: `/home/admin/config.scripts/blitz.ups.sh on apcusb` To turn it on run from terminal: `/home/admin/config.scripts/blitz.ups.sh on apcusb`
- There is also a script dealing with Geekworm/Suptronics [X708 UPS HAT](https://www.amazon.com/Geekworm-Raspberry-Management-Detection-Shutdown/dp/B08DNRYM4Y/). The tested model was x708v1.2. \
To turn it on run from terminal: `/home/admin/config.scripts/blitz.ups.sh on x708`
If you have other UPS models or ways to connect ... feel free to extend this script. If you have other UPS models or ways to connect ... feel free to extend this script.
### Can I run my RaspiBlitz on Solar Energy? ### Can I run my RaspiBlitz on Solar Energy?

View File

@ -7,6 +7,7 @@ source /mnt/hdd/raspiblitz.conf 2>/dev/null
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
echo "Configure a UPS (Uninterruptible Power Supply)" echo "Configure a UPS (Uninterruptible Power Supply)"
echo "blitz.ups.sh on apcusb" echo "blitz.ups.sh on apcusb"
echo "blitz.ups.sh on x708"
echo "blitz.ups.sh status" echo "blitz.ups.sh status"
echo "blitz.ups.sh off" echo "blitz.ups.sh off"
exit 1 exit 1
@ -21,7 +22,7 @@ if [ "$1" = "1" ] || [ "$1" = "on" ]; then
echo "Turn ON: UPS" echo "Turn ON: UPS"
if [ "$2" = "apcusb" ]; then if [ "$2" = "apcusb" ]; then
# MODEL: APC with USB connection # MODEL: APC with USB connection
# see video: https://www.youtube.com/watch?v=6UrknowJ12o # see video: https://www.youtube.com/watch?v=6UrknowJ12o
@ -48,13 +49,37 @@ if [ "$1" = "1" ] || [ "$1" = "on" ]; then
sudo sed -i "s/^WALL=.*/#WALL=wall/g" /etc/apcupsd/apccontrol sudo sed -i "s/^WALL=.*/#WALL=wall/g" /etc/apcupsd/apccontrol
sudo systemctl enable apcupsd sudo systemctl enable apcupsd
sudo systemctl start apcupsd sudo systemctl start apcupsd
# set ups config value (in case of update) # set ups config value (in case of update)
/home/admin/config.scripts/blitz.conf.sh set ups "apcusb" /home/admin/config.scripts/blitz.conf.sh set ups "apcusb"
echo "OK - UPS is now connected" echo "OK - UPS is now connected"
echo "Check status/connection with command: apcaccess" echo "Check status/connection with command: apcaccess"
elif [ "$2" = "x708" ]; then
# MODEL: Geekworm/Suptronics X708 v1.2
# enable I2C interface
sudo raspi-config nonint do_i2c 0
# install prerequisites
sudo apt-get install -y python3-smbus i2c-tools
# clone git repository with the X708 scripts
git clone https://github.com/HiLivin/x708blitz.git /home/admin/x708blitz
cd /home/admin/x708blitz
git checkout 2ed6caffedef3bd523732287234ebe9d200fd92f
# run install script
sudo bash /home/admin/x708blitz/install.sh
# set ups config value (in case of update)
/home/admin/config.scripts/blitz.conf.sh set ups "x708"
echo "OK - X708 UPS HAT is now connected"
echo "Please, perform restart to apply changes."
else else
echo "FAIL: unknown or missing second parameter 'UPSTYPE'" echo "FAIL: unknown or missing second parameter 'UPSTYPE'"
exit 1 exit 1
@ -87,6 +112,22 @@ if [ "$1" = "status" ]; then
fi fi
fi fi
exit 0 exit 0
elif [ "${ups}" = "x708" ]; then
info=$(python3 /home/admin/x708blitz/x708.info.py)
status=$(echo $info | cut -d "," -f1)
if [ ${#status} -eq 0 ]; then
echo "upsStatus='n/a'"
else
echo "upsStatus='${status}'"
# get battery level if possible
if [ "${status}" = "ONLINE" ] || [ "${status}" = "ONBATT" ]; then
battery=$(echo $info | cut -d "," -f2)
echo "upsBattery='${battery}'"
fi
fi
exit 0
else else
echo "upsStatus='CONFIG'" echo "upsStatus='CONFIG'"
exit 0 exit 0
@ -113,6 +154,13 @@ if [ "$1" = "0" ] || [ "$1" = "off" ]; then
sudo systemctl disable apcupsd sudo systemctl disable apcupsd
sudo apt-get remove -y apcupsd sudo apt-get remove -y apcupsd
/home/admin/config.scripts/blitz.conf.sh set ups "off" /home/admin/config.scripts/blitz.conf.sh set ups "off"
elif [ "${ups}" = "x708" ]; then
sudo bash /home/admin/x708blitz/uninstall.sh
sudo raspi-config nonint do_i2c 1
sudo apt-get remove -y python3-smbus i2c-tools
/home/admin/config.scripts/blitz.conf.sh set ups "off"
else else
echo "FAIL: unknown UPSTYPE: ${ups}" echo "FAIL: unknown UPSTYPE: ${ups}"
exit 1 exit 1