Last mod: 2024.11.11
Raspberry Pi - UPS
Hardware
- Raspberry Pi 4 with Raspberry Pi OS Lite (64-bit)
- WaveShare UPS HAT for Raspberry Pi
Update software an install packages
Install requires packages:
sudo apt update
sudo apt upgrade -y
sudo apt-get install -y p7zip python3-smbus
Turn on I2C interface. Select Interfacing Options -> I2C ->yes to start the i2C kernel driver:
sudo raspi-config
sudo reboot
And after reboot:
wget https://files.waveshare.com/upload/d/d9/UPS_HAT.7z
7zr x UPS_HAT.7z
cd UPS_HAT/
python3 INA219.py
We should see informations:
Create web page with status UPS
We will create a site based on the framweork flask and bootstrap:
sudo apt install -y python3-flask python3-flask-bootstrap
Let's create directory for flask project on Raspberry:
mkdir UpsStatus
Add files:
And finally run:
cd UpsStatus
python3 app.py
Open browser with IP and port (default value 5000) application, in my example http://192.168.3.42:5000
The page refreshes at the frequency defined in the template UpsStatus/templates/UpsStatus.html, line:
setInterval(fetchBatteryStatus, 1000);
We can see how the script works in the video:
Sources
https://gitlab.com/dziak.tech/examples/-/tree/main/IoT/UpsForRaspberry
Links
https://www.waveshare.com/ups-hat.htm?sku=18306 https://www.waveshare.com/wiki/UPS_HAT https://files.waveshare.com/upload/d/d9/UPS_HAT.7z