Rev Author Line No. Line
4686 kaklik 1 #!/usr/bin/python
2 import wiringpi2 as gpio
3 import time
4 import subprocess
5  
4745 kaklik 6 power_sense_pin = 83
7  
4686 kaklik 8 gpio.wiringPiSetupGpio()
4745 kaklik 9 gpio.pinMode(power_sense_pin, 0)
10 gpio.pullUpDnControl(power_sense_pin, 0)
4686 kaklik 11  
4786 kaklik 12 time.sleep(30) # wait for complete startup.
4686 kaklik 13  
4745 kaklik 14 oldstav = gpio.digitalRead(power_sense_pin)
4686 kaklik 15  
16 while True:
4745 kaklik 17 stav = gpio.digitalRead(power_sense_pin)
4686 kaklik 18  
4687 kaklik 19 if oldstav == 0 and stav == 0:
4690 kaklik 20 subprocess.call("shutdown -P 0", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
4784 kaklik 21 exit(0)
4688 kaklik 22 else:
23 print "power is OK."
4745 kaklik 24  
4688 kaklik 25 oldstav = stav
4686 kaklik 26  
4687 kaklik 27 time.sleep(2)
4686 kaklik 28  
29