Program to monitor the PiUPS+ (PiUSV+) module for the raspberry pi.
This program is a replacement for the original piupsmon which lacks the availability of source code.
I tried to use the original init.d script, but that does not work, due to the fact, that the Raspian Os now uses systemd. The PiUSV+ won't power off because the variable RUNLEVEL ist not set during shutdown causing the poweroff timer not to be set.
So I created two systemd-services, one to start the daemon in multi-user.target and another to programm the poweroff
timer on shutdown. By replacing the /usr/sbin/piupsmonitor
with /usr/bin/piupsmon
the service might even work with the original piupsmon.
- Raspberry Pi
- PiUSV+
libi2c-dev
# Library for C
Use the following command to install the library:
sudo apt install libi2c-dev
Enable I2C
sudo raspi-config
Go to "3 Interface Options" -> "I5 I2C" -> select Yes and reboot.
mkdir -p usr/sbin
gcc -O -o usr/sbin/piupsmonitor src/piupsmonitor.c -li2c
sudo cp -a etc/piupsmonitor /etc
The configuration can be changed in /etc/piupsmonitor/piupsmonitor.conf
Copy the binary
sudo cp -a usr/sbin/piupsmonitor /usr/sbin
Copy the systemd service files if you want to start piupsmonitor
during boot
sudo cp -a etc/systemd/system/piupsmonitor*.service /etc/systemd/system/
and enable the services
sudo systemctl daemon-reload
sudo systemctl enable piupsmonitor.service
sudo systemctl start piupsmonitor.service
sudo systemctl enable piupsmonitor-poweroff.service
Don't start the piupsmonitor-poweroff.service
or your Raspberry will poweroff whithout shutting down. The service
will be started during shutdown to switch off the power after a delay (default 15 seconds).
On my Raspberry Pis I get Remote I/O error (121)
if I use the default i2c
baudrate. So I reduced it to 40000 and got no errors anymor.
Add the following to /boot/config.txt
dtparam=i2c_baudrate=40000
and reboot.
This problem is probably caused by the Raspberry Pi I2C clock-stretching bug. For more details s. e.g. here or ask Google.
By the way the problem exists with the original piupsmon
, too. There I get
occasionaly power failures in the logfile. With lowering the i2c baudrate they
are gone.