Folgende Warnungen sind aufgetreten:
Warning [2] Undefined variable $unreadreports - Line: 34 - File: global.php(961) : eval()'d code PHP 8.2.2 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/global.php(961) : eval()'d code 34 errorHandler->error_callback
/global.php 961 eval
/showthread.php 28 require_once
Warning [2] Undefined property: MyLanguage::$thread_modes - Line: 43 - File: showthread.php(1621) : eval()'d code PHP 8.2.2 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/showthread.php(1621) : eval()'d code 43 errorHandler->error_callback
/showthread.php 1621 eval




Themabewertung:
  • 0 Bewertung(en) - 0 im Durchschnitt
  • 1
  • 2
  • 3
  • 4
  • 5
strompi2
#11
Code:
#!/usr/bin/python
# Initialisierung
import RPi.GPIO as GPIO
import time
import os
GPIO.setmode(GPIO.BCM)

# Hier den entsprechden GPIO-PIN auswaehlen
GPIO_TPIN = 21

print "Sicheres Herunterfahren bei Stromausfall (CTRL-C zum Schliessen)"

# Set pin as input
GPIO.setup(GPIO_TPIN,GPIO.IN,pull_up_down = GPIO.PUD_DOWN)      

Current_State  = 0
Previous_State = 0

try:

 print "Warte auf Initialisierung der Spannungsversorgung..."

 
 while GPIO.input(GPIO_TPIN)==1:
   Current_State  = 0

 print "  Bereit"


 while True :

   Current_State = GPIO.input(GPIO_TPIN)

   if Current_State==1 and Previous_State==0:
     Previous_State=1
     if(Previous_State==1):
                   counter = 60    #60sek. warten bis zum shutdown
                   ic = 0
                   while ic <= counter:
                     sleep(1)
                     ic += 1
                     if ic >= counter:
                         if(Current_State==0 and Previous_State==1):   #wenn USB IN wieder versorgt wird, shutdown abbrechen
                           Previous_State=0
                           sleep(0.01)
                           break
                         if(Current_State==1 and Previous_State==1):    #liegt nach Ablauf des counters keine Spannung an USB IN an, RPi shutdown
                           os.system("sudo shutdown -h now")
   elif Current_State==0 and Previous_State==1:
     Previous_State=0

   time.sleep(0.01)

except KeyboardInterrupt:
 print "  Quit"
 GPIO.cleanup()


 
Bezüglich ShutDown Wartezeit...
Ob der Script so funktioniert habe ich nicht getestet und ist wahrscheinlich, falls er denn funktioniert, nicht die eleganteste Lösung.
Kannst ihn ja mal testen, ich komme erst die Tage dazu.
Zitieren


Nachrichten in diesem Thema
strompi2 - von crazyb - 27.02.2017, 14:21
RE: strompi2 - von leviathan - 27.02.2017, 17:44
RE: strompi2 - von crazyb - 27.02.2017, 19:37
RE: strompi2 - von leviathan - 28.02.2017, 17:11
RE: strompi2 - von leviathan - 28.02.2017, 01:50
RE: strompi2 - von cbrauweiler - 28.02.2017, 13:41
RE: strompi2 - von crazyb - 28.02.2017, 14:26
RE: strompi2 - von cbrauweiler - 28.02.2017, 15:14
RE: strompi2 - von gxdigga - 28.02.2017, 17:47
RE: strompi2 - von leviathan - 28.02.2017, 18:24
RE: strompi2 - von gxdigga - 01.03.2017, 23:08
RE: strompi2 - von leviathan - 03.03.2017, 15:08

Gehe zu:


Benutzer, die gerade dieses Thema anschauen: 3 Gast/Gäste
RasPiCarProjekt