CommentStreams:2b543ed81c6d2188ca20c72f9045582c

< X1200
Revision as of 12:49, 4 September 2024 by 87.122.222.160 (talk) (Migrated comment #5095)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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:

  1. !/usr/bin/env python3
  2. 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()