[arm-allstar] UPS Suggestions...

Sean McCarthy smccarthy61 at gmail.com
Mon Jul 2 09:44:04 EST 2018


The script in case anyone else would like to take a look...

On Mon, Jul 2, 2018 at 10:33 AM Sean McCarthy <smccarthy61 at gmail.com> wrote:

> Jesse,
>
> What did you need to do to get the script to run? I followed the
> instructions from Alchemy with no luck, but it was written for Rasberrian,
> so theres that...
>
> Here is my failure:
>
> [root at K8FBI UPS]# sudo python GPIO-shutdown-sample.py
> Traceback (most recent call last):
>   File "GPIO-shutdown-sample.py", line 32, in <module>
>     import RPi.GPIO as GPIO
> ImportError: No module named 'RPi'
> [root at K8FBI UPS]#
>
> Thanks!
>
> On Thu, Jun 28, 2018 at 10:21 PM "Jesse Royall via arm-allstar" <
> arm-allstar at hamvoip.org> wrote:
>
>> Sean,
>> Yes it will restart when power is applied and will start charging again.
>> If you do a shutdown then no. You have to remove power and apply it to
>> start back up. But it will start up if the batteries go dead and power
>> comes back on. It has a smart charge built on. You setup a python script to
>> monitor the voltage and it will initiate a safe power down before they go
>> dead. Then when they go dead it will restart the pi when power is applied
>> back to charge the batteries. What sold me is that one power supply to
>> power the ups then since it’s a hat, it supplies the pi with power on the
>> header. If the cells go bad you just replace them like AA batteries. You
>> can replace them one at a time without loosing power. You can also stack
>> them to increase the battery time and they have connections to daisy  them
>> and charge the next ups. Has a reset button on board to force a restart
>> when pressed. The only problem I’ve had is I had one bad cell once and it
>> would take the other cell down with it. But the voltage monitor would catch
>> it and shut down the pi when unplugged it. The other is when picking up the
>> pi, I had a habit of hitting the reset accidentally.
>>
>> I’m was working on a script to watch the voltage and when it sees a
>> voltage drop it tells you via courtesy tone your on battery and possibly
>> speak voltage at intervals. Since the cron job looks for low voltage to
>> safe power down I figure I could use that check to report back to allstar
>> and either tattle via tone or voice.
>>
>>
>> Sent from my iPhone
>>
>> > On Jun 28, 2018, at 10:11 AM, Sean McCarthy via arm-allstar <
>> arm-allstar at hamvoip.org> wrote:
>> >
>> > I was looking at the pi uptime ups, but it was unclear if it would
>> restart
>> > the PI unattended. If it does, thats probably the way I'll go...
>> >
>> > On Thu, Jun 28, 2018 at 10:26 AM "Jesse Royall via arm-allstar" <
>> > arm-allstar at hamvoip.org> wrote:
>> >
>> >> http://alchemy-power.com/pi-uptime-ups/
>> >>
>> >> This is the one I use. Uses 2 18650 batteries. I get about 10 hrs of
>> >> backup. It’s stackable. Has a reset button on it. Monitors the voltage
>> for
>> >> a safe power off. And boots back up when power is applied.
>> >>
>> >> Sent from my iPhone
>> >>
>> >> _______________________________________________
>> >>
>> >> arm-allstar mailing list
>> >> arm-allstar at hamvoip.org
>> >> http://lists.hamvoip.org/cgi-bin/mailman/listinfo/arm-allstar
>> >>
>> >> Visit the BBB and RPi2/3 web page - http://hamvoip.org
>> > _______________________________________________
>> >
>> > arm-allstar mailing list
>> > arm-allstar at hamvoip.org
>> > http://lists.hamvoip.org/cgi-bin/mailman/listinfo/arm-allstar
>> >
>> > Visit the BBB and RPi2/3 web page - http://hamvoip.org
>>
>> _______________________________________________
>>
>> arm-allstar mailing list
>> arm-allstar at hamvoip.org
>> http://lists.hamvoip.org/cgi-bin/mailman/listinfo/arm-allstar
>>
>> Visit the BBB and RPi2/3 web page - http://hamvoip.org
>
>
-------------- next part --------------
#! /usr/bin/python
#
# HOW TO USE:
#
# HAVE TO RUN THIS SCRIPT WITH SUDO PRIVILIDGES. Shutdown commands needs SUDO.
# As always, we recommend using the latest version of the software. To do that use commands
#  sudo apt-get update
#  sudo apt-get upgrade
#  sudo apt-get dist-upgrade    (Note - this will update the kernel and the OS. Use it with caution.)
#
#
#
# Recommend to save this file in /usr/local/bin. Please make sure the run bit is set. Here are the commands:
# sudo cp GPIO-crontab.py /usr/local/bin
# sudo chmod 755 /usr/local/bin/GPIO-crontab.py
#
# Now modify the crontab to execute the command every 2 minutes (or longer).
# Use "sudo crontab -e" command to add the line below:
#    */2 * * * * python /usr/local/bin/GPIO-crontab.py
#
#  The */2 can be replaced with */1 for every 1 minute, */3 for every 3 minnutes etc.
#
# Best to reboot the Pi to make sure all changes etc have been adopted.
#
#
# RIGHT TO USE STATEMENT
# (C) 2017 Alchemy Power Inc.
# Right to use, copy, distribute etc. of this code with Pi-UpTimeUPS or
# PiZ-UpTime or any other Alchemy Power Inc. product or any product. Right is granted to you
# by Alchemy Power Inc. as long as you maintain the lines from line 1 to "END OF HEADERS" line
# with every copy.
#
####################  END OF HEADERS  ##########################
#
#
# This file shows alternate ways to use the Python code. You can use whichever one you
# are familair with.
#
# Instead of firt line /usr/bin/python, you can use line below to setup the environment for Python.
#
#!/usr/bin/env python
#
#
#
import RPi.GPIO as GPIO
import time
#
# import os if using the os method to initiate the shutdown.
#
import os
#
# sys is needed for flushing std out on an interrupt.
#
import sys
#
# import subprocess to start the shut down process as a seperate thread
# and exit the script cleaning out the GPIO.
#
import subprocess
# Use the number carefully - GPIO.BOARD for pin number on the board.
# Use the BCM method if
# Use the GPIO.BCM if you are using the BCM method to assign the GPIO number.
# Make sure the GPIO jumper is in.
# If the GPIO jumper is out, the GPIO connection is broken.
#
buttonPin = 37 # GPIO 26, Pin 37
# Use pin number 37 on the board by using the setmode below.
#
GPIO.setmode(GPIO.BOARD)
#
# Use GPIO number if you are using BCM technique below.
# GPIO.setmode(GPIO.BCM)
#
# Use the pull up i.e. expect output to be zero. When it goes to 1, GPIO is set.
GPIO.setup(buttonPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
#
# Opposite of what we did above - normally 1, GPIO set when it goes to zero.
# GPIO.setup(buttonPin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
#
# Use schlaf variable below to indicate how long the program sleeps for before checking again.
#
if (not(GPIO.input(buttonPin))):
	# GPIO is 1. We are here because the sensors triggered the battery being low.
	time.sleep(2)
	# Sleep for 2 seconds, just to make sure the battery level is indeed low and not a jitter...
	# Check again.
	if (not(GPIO.input(buttonPin))):
		print("Shutdown initiated at %s " % (time.ctime()))
		#
		# The command shuts down the pi in 2 minutes. Replace
		# 2 with word "now" (without the quotes) for immediate
		# shutdown. If you use the Pi-Zero-Uptime (the one which uses 14500 battery)
		# recommend using shutdown -h now instead of shutdown -h 2.
		# The subprocess method forks a process which can run in the background while this
		# program exits properly. os.system method continues to run in the program thread.
		#
		#
		subprocess.call("shutdown -h 2 &", shell=True)
		#
		# Sleep for a second or so for the shutdown process to fork and then exit
		# script cleaning out GPIO.
		time.sleep(2)
		# Flush any stdout messages before exiting..
		sys.stdout.flush()
		#  Force exit.
		exit()


More information about the arm-allstar mailing list