Setup


Easy install (recommended)

Open a terminal and copy and paste the following lines:

            sudo su  	
wget http://safe-power.appspot.com/scripts/install.sh
chmod +x install.sh
./install.sh

$ apt-get install scribbler $ gem install scribbler
An error message could appear here "no existing crontab for user" - ignore this error message Shut down the Raspberry and install the UPS. After the reboot, your python script will be running.

Manual install

All commands should be run by root. ssh into the raspberry or open a terminal window and type the following:

            sudo su  	
cd /bin
nano safe-power.py

$ apt-get install scribbler $ gem install scribbler

Paste the following text into the file safe-power.py

#!/usr/bin/env python  
#script to shutdown the raspberry by safe-power raspberry UPS
#save this script as root under /bin/safe-power.py  
#add this script AS LAST LINE of root's crontab in the following way
#  @reboot /bin/safe-power.py & 
# important!! dont forget the "&"  in the end!!
#the script will be started in the background at reboot 
#and safe power will be operational
import RPi.GPIO as GPIO  
GPIO.setmode(GPIO.BCM)  
import os   
import time
# GPIO 11 = pin23 set up as input. It is pulled up to stop false signals  
GPIO.setup(11, GPIO.IN, pull_up_down=GPIO.PUD_UP)
# now the program will do nothing until the shutdown signal on pin 23   
# gets LOW.     
#During this waiting time, your raspberry is not 
#wasting resources by polling the pin
  
try:  
    GPIO.wait_for_edge(11, GPIO.FALLING)
 
# warn all logged users of the shutdown event
    os.system("wall shutdown by UPS")
#now the system will shut down
    os.system("sudo poweroff")  
#except if this script will be cancelled by the user explicitely
except KeyboardInterrupt:  
    GPIO.cleanup()       # clean up GPIO on CTRL+C exit  
    GPIO.cleanup()           # clean up GPIO on normal exit 

Save the file by hitting CTRL+x and y.
change the permissions of your script with:

            sudo chmod +x /bin/safe-power.py 

edit the crontab by issuing the following command

            crontab -e 

paste the following line at the LAST LINE of the crontab

@reboot /bin/safe-power.py & 

save your root's crontab by hitting CTRL+x and y(or whatever your editor expects)
Your safe-power will be operational at next reboot

Troubleshooting

1. Check if the python script is running
            ps -ef | grep safe   

Output should be similar to:


root       296     1  0 Jun04 ?        00:00:00 python /bin/safe-power.py

If it is not running, start it manually with:

            sudo  /bin/safe-power.py 

and verify again

2. Check if crontab is configured correctly:
            sudo crontab -e   
$ apt-get install scribbler $ gem install scribbler

One of the last lines should contain:

@reboot /bin/safe-power.py &

If it is not there, insert it manually or use the install script

Changelog

v1.1

15/July/2019
  • corrected install.sh from automatic install (ident error)

v1

07/June/2019
  • initial new setup page