-
Notifications
You must be signed in to change notification settings - Fork 0
/
time-shutdown.py
39 lines (30 loc) · 1.16 KB
/
time-shutdown.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python
import RPi.GPIO as GPIO
import time
import subprocess
SENSOR_PIN = 3
GPIO.setmode(GPIO.BCM)
GPIO.setup(SENSOR_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)
#GPIO.wait_for_edge(SENSOR_PIN, GPIO.FALLING)
flag = 0
f = open("/home/christopher/Shutdown-LOG.txt", "a") #Change Directory !
f.write("\nBoot-time: "+ time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime()))
f.close()
def mein_callback(channel):
# Hier kann alternativ eine Anwendung/Befehl etc. gestartet werden.
print('Es gab eine Bewegung!')
global flag
flag = 0
GPIO.add_event_detect(SENSOR_PIN , GPIO.FALLING, callback=mein_callback)
while True:
time.sleep(6) #alle 6 Sekunden aufgerufen
flag = flag + 1
print(flag)
if flag >= 150: #In 10/Minuten wartezeit
print("ABSCHALTEN")
f = open("/home/christopher/Shutdown-LOG.txt", "a") #Change Directory !
f.write("\nShutdown: "+ time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime()))
f.close()
GPIO.cleanup()
subprocess.call(['shutdown', '-h', 'now'], shell=False)
break