-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcontrol.py
60 lines (40 loc) · 1.36 KB
/
control.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
# Imports
import webiopi
import sys,os
import subprocess
import time
import signal
from config import config
# Retrieve GPIO lib
GPIO = webiopi.GPIO
tx_pin = 17 #gpio 17
GPIO.setFunction(tx_pin, GPIO.OUT)
armed_file = config['home_alarm_git_dir'] + "/armed.txt"
send_script = config['rf433_dir'] + "/send "
os.system("sudo echo -n 0 > " +armed_file)
def arm():
os.system("sudo echo -n 1 > " + armed_file)
def disarm():
os.system("sudo echo -n 0 > " + armed_file)
def sw1_toggle():
os.system("sudo "+ send_script + config ['switch1'])
def sw2_toggle():
os.system("sudo " + send_script + config ['switch2'])
def sw3_toggle():
os.system("sudo " + send_script + config ['switch3'])
# Instantiate the server on the port 8085, it starts immediately in its own thread
server = webiopi.Server(port=config['port'], login=config['browser_username'], password=config['browser_passwd'])
server.addMacro(arm)
server.addMacro(disarm)
server.addMacro(sw2_toggle)
server.addMacro(sw1_toggle)
server.addMacro(sw3_toggle)
#start keypad.py and alarm.py process
p0 = subprocess.Popen(["sudo","python","keypad.py"],preexec_fn=os.setsid)
p1 = subprocess.Popen(["sudo","python","alarm.py"],preexec_fn=os.setsid)
# Run our loop until CTRL-C is pressed or SIGTERM received
webiopi.runLoop()
os.killpg(p0.pid,signal.SIGTERM)
os.killpg(p1.pid,signal.SIGTERM)
# Stop the server
server.stop()