CommentStreams:2b543ed81c6d2188ca20c72f9045582c
Hello all,
I edited a script for shutting down on powerloss after x seconds. For automatic shutdown, I call it with crontab. The mod of the file has to be changed to 755 before. (chmod)
I hope this helps.
Greetings
Below the Script:
- !/usr/bin/env python3
- This python script is only suitable for UPS Shield X1200, X1201 and X1202
import gpiod import time from subprocess import call
PLD_PIN = 6 chip = gpiod.Chip('gpiochip4') pld_line = chip.get_line(PLD_PIN) pld_line.request(consumer="PLD", type=gpiod.LINE_REQ_DIR_IN)
try:
while True:
pld_state = pld_line.get_value()
if pld_state == 0:
print ("Powerloss detected")
time.sleep(10) # Change this to preferred value
pld_state = pld_line.get_value()
if pld_state == 1:
print ("Power ready")
pass
else:
print ("Shutting down")
time.sleep(1)
call("sudo nohup shutdown -h now", shell=True)
finally:
pld_line.release()