-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_433.py
executable file
·100 lines (79 loc) · 2.57 KB
/
test_433.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import io
import re
import sys
import time
import argparse
from pilight import pilight
def handle_code(code): # Simply print received data from pilight
global args
msg = code['message']
if args.verbose:
print "Got code"
if args.raw:
print(code)
else:
if args.protocol:
searchObj = re.search(args.protocol, code['protocol'], re.M|re.I)
if searchObj:
if args.verbose:
print "Got right Protocol"
else:
if args.verbose:
print "Wrong Protocol"
return
mkey = True
if args.message_key == True:
mkey = False
s = "{0}:\t".format(code['protocol'])
for k, v in msg.iteritems():
if args.message_key == k:
mkey = True
s += "{0}: {1}, ".format(k,v)
if mkey == True:
print s
elif args.blink:
print "."
elif args.verbose:
print "Message key not found"
# pylint: disable=C0103
def main():
global args
pilight_client = None
try:
parser = argparse.ArgumentParser(description='Test for 433Mhz sensors')
parser.add_argument('--raw', help='show raw sensor readings', action="store_true")
parser.add_argument('-S' , '--server', help='Server to connect with pilight daemon', default='127.0.0.1')
parser.add_argument('-P' , '--port', help='Port to connect with pilight daemon', default=5000)
parser.add_argument('-p' , '--protocol', help='show only sensor readings with this protocol')
parser.add_argument('-m' , '--message-key', help='show only sensor readings containing this key in the message')
parser.add_argument('-v' , '--verbose', help='show verbose output', action="store_true")
parser.add_argument('--blink', help='say anything on receiving', action="store_true")
args = parser.parse_args()
server433 = args.server
port433 = args.port
print "\n*** gw 433Mhz Testprogramm zum Sensorempfang ***"
print "Verbinde zu pilight-daemon an {0} über Port {1}\n".format(server433, port433)
# Create new pilight connection
pilight_client = pilight.Client(host=server433, port=port433)
# Set a data handle that is called on received data
pilight_client.set_callback(handle_code)
pilight_client.start() # Start the receiver
print "Beginne Überwachung..\n"
if args.raw:
print "Zeige Rohdaten..\n"
while True:
time.sleep(5)
except KeyboardInterrupt:
print "\nAbbruch durch Benutzer Ctrl+C\n"
except RuntimeError,e:
print "RuntimeError {0}".format(e)
except:
print "Unexpected error:", sys.exc_info()[0]
finally:
if pilight_client:
pilight_client.stop() # Stop the receiver
if __name__ == "__main__":
main()