-

CommentStreams:349c3b14b8ade3fe3331b162fd247b6a

From Geekworm Wiki
< CommentStreams:4ac399bd4970c137631654021d17dff8
Revision as of 09:28, 12 June 2024 by 174.174.80.39 (talk) (Migrated reply #4848)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

OK so I got pretty close by modifying the included pld.py script. I can get it to shutdown when on battery with a delay. However, it will execute the second the pi is on battery. I would rather it be on battery for say 10 seconds so random power drops don't shut it down. Any idea on how to implement this?

  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 == 1:
          pass
      else:
           time.sleep(1)
           call("sudo nohup shutdown -h now", shell=True)  #uncomment to implement shutdown when power outage

finally:

pld_line.release()