Skip to content

dannypv05261/x728-ups-auto-shutdown

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 

Repository files navigation

x728-ups-auto-shutdown

The ups.py script allow the X728 UPS hat to auto shutdown (ASD) your raspbery pi.

This project can provide these features:

  • Listen to the change of power supply event (Power supply lost or Power supply recovered)
  • Detect power supply failure also when the PI starts
  • Enable power left checking loop ONLY when power supply lost and shutdown eventually when the batteries have 10% power left (configurable).
  • Disable power left checking loop gracefully after the power supply recovers to save processing power
  • Put the log to /var/log/syslog for UPS status change tracing

Setup

  1. Install Python3, enable RTC and ic2 according to official guidelines
# Install Python 3 and dependencies
sudo apt install python3-pip
sudo apt-get -y install python3-rpi.gpio
sudo pip3 install -r requirements.txt

#X728 RTC setting up
sudo sed -i '$ i rtc-ds1307' /etc/modules
sudo sed -i '$ i echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device' /etc/rc.local
sudo sed -i '$ i hwclock -s' /etc/rc.local
  1. Put the file to somewhere. e.g. /opt/ups.py
  2. Set file permission
sudo chmod +x /opt/ups.py
  1. Run the script on boot by crontab
# Must be run with root user, since shutdown commands will be called
sudo su
crontab - e
# Add the following line to the crontab
@reboot python3 /opt/ups.py
  1. Reboot your PI

You can check the log in /var/log/syslog file for app started, app error, power supply event change, etc.

You can test the program by keeping plugin and eject the power supply cable connected to the UPS, and you can find how robust the program is ~.

This is based on the sample script in official guidelines

About

Allow the X728 UPS hat to perform auto shutdown (ASD) in a more elegant way.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages