-
Notifications
You must be signed in to change notification settings - Fork 0
/
remoteListener.py
executable file
·68 lines (55 loc) · 1.77 KB
/
remoteListener.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/python
from time import sleep
import os
import sys
import subprocess
from subprocess import Popen
import RPi.GPIO as GPIO
# global variables for commands and status
global alertcmd
global alarmOn
# the alertcmd should be slightly different depending on which event triggers it (button or remote)
# because later we can add conditions for doors or other x10 devices
alertcmd = "/root/testalert.py"
# inital alarm status is off
alarmOn = False
status = 0
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(17, GPIO.IN) # RF receiver
GPIO.setup(2, GPIO.IN) # Front push button
GPIO.setup(11, GPIO.OUT, initial=GPIO.HIGH) # green led starts ON
GPIO.setup(9, GPIO.OUT, initial=GPIO.LOW) # red led starts OFF
def alert_action(channel):
from time import sleep
global alertcmd
global alarmOn
global status
print('Edge detected on channel %s'%channel)
#if channel == 17 : alertcmd = "/root/rfalert.py"
if channel == 2 :
alertcmd = "/root/pushAlert.py"
if alarmOn==True:
status = "0"
subprocess.Popen([sys.executable, alertcmd, status])
alarmOn=False
GPIO.output(11,GPIO.HIGH) ## turn green led on
GPIO.output(9,GPIO.LOW) ## turn red led off
print ('Alarm was On now it is Off')
else:
status = "1"
subprocess.Popen([sys.executable, alertcmd, status])
alarmOn=True
GPIO.output(9,GPIO.HIGH) ## turn red LED on
GPIO.output(11,GPIO.LOW) ## turn green LED off
print ('Alarm was OFF now it is ON')
if channel == 17 :
alertcmd = "/root/rfalert.py"
status = "0"
subprocess.Popen([sys.executable, alertcmd, status])
print ("READY")
GPIO.add_event_detect(17, GPIO.RISING, callback=alert_action, bouncetime=200)
GPIO.add_event_detect(2, GPIO.FALLING, callback=alert_action, bouncetime=200)
while True:
sleep(1)
GPIO.cleanup()