Repository navigation
Expand file tree
/
Copy pathRFPi_controller.py
More file actions
65 lines (54 loc) · 1.96 KB
/
Copy pathRFPi_controller.py
File metadata and controls
65 lines (54 loc) · 1.96 KB
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
import argparse
import signal
import sys
import time
import logging
from functions import sendMore, getData
from rpi_rf import RFDevice
rfdevice = None
light_args=[{'wrgb':[4095,2000,500,0]},
{'toggle':1},
{'wrgb':[0,4095,800,0]},
{'wrgb':[0,156,30,0]},
]
def exithandler(signal, frame):
rfdevice.cleanup()
sys.exit(0)
logging.basicConfig(level=logging.INFO, datefmt='%Y-%m-%d %H:%M:%S',
format='%(asctime)-15s - [%(levelname)s] %(module)s: %(message)s', )
parser = argparse.ArgumentParser(description='Receives a decimal code via a 433/315MHz GPIO device')
parser.add_argument('-g', dest='gpio', type=int, default=14,
help="GPIO pin (Default: 14(previously 27))")
args = parser.parse_args()
signal.signal(signal.SIGINT, exithandler)
rfdevice = RFDevice(args.gpio)
rfdevice.enable_rx()
timestamp = None
oldtime=time.time()
logging.info("Listening for codes on GPIO " + str(args.gpio))
#print('Listening')
while True:
try:
if rfdevice.rx_code_timestamp != timestamp:
timestamp = rfdevice.rx_code_timestamp
code=str(rfdevice.rx_code)
#print(code)
if code[:2]==code[-2:]=='69' and time.time()-oldtime>=0.5:
num=int(code[2:-2])
print('{}: {}'.format(num,light_args[num]))
sendMore(**light_args[num])
logging.info(str(rfdevice.rx_code) +
" [pulselength " + str(rfdevice.rx_pulselength) +
", protocol " + str(rfdevice.rx_proto) + "]")
# print(str(rfdevice.rx_code) +
# " [pulselength " + str(rfdevice.rx_pulselength) +
# ", protocol " + str(rfdevice.rx_proto) + "]")
oldtime=time.time()
time.sleep(0.05)
except Exception as e:
try:
logging.info(e)
except Exception as e2:
print(e2)
print(e)
rfdevice.cleanup()