summaryrefslogtreecommitdiff
path: root/receive.py
diff options
context:
space:
mode:
Diffstat (limited to 'receive.py')
-rwxr-xr-xreceive.py65
1 files changed, 65 insertions, 0 deletions
diff --git a/receive.py b/receive.py
new file mode 100755
index 0000000..4836809
--- /dev/null
+++ b/receive.py
@@ -0,0 +1,65 @@
+#!/usr/bin/env python3
+
+from RFXtrx import PySerialTransport
+import sys, datetime, os
+
+#WIND ['04:00']
+#RAIN ['eb:00', '7d:00', '02:00']
+#TEMP ['10:02', 'ec:01', '25:01', '62:02', 'd9:00', '2a:0e', '60:01']
+#KNOWN_DEVICES = ['']
+
+if __name__ == "__main__":
+ transport = PySerialTransport('/dev/ttyUSB0')
+ transport.reset()
+
+ while True:
+ if os.path.isfile('/home/pi/weather/stop'):
+ break
+
+ recv = transport.receive_blocking()
+
+ if not recv:
+ continue
+
+ timestamp = datetime.datetime.timestamp(datetime.datetime.now())
+
+ sys.stderr.write("Raw: %s\n"%str(recv))
+
+ try:
+ device_id = recv.device.id_string
+ device_type = recv.device.type_string
+ except Exception as e:
+ sys.stderr.write("Cannot find device id, exception %s." % str(e))
+ continue
+
+ data = {}
+ for k,v in recv.values.items():
+ data[k.lower().replace(" ", "_")] = v
+
+ data_type = None
+ if "rain_rate" in data:
+ data_type = "rain"
+ elif "wind_gust" in data:
+ data_type = "wind"
+ elif "temperature" in data:
+ data_type = "temp"
+ else:
+ sys.stderr.write("Unknown device '%s' with id '%s', ignoring.\n"%(device_type, device_id))
+ continue
+
+
+ out = [ "type::%s" % data_type,
+ "timestamp::%f" % timestamp,
+ "device_type::%s" % device_type,
+ "device_id::%s" % device_id ]
+
+ for key in sorted(data.keys()):
+ out.append("%s::%s" % (key, data[key]))
+
+ print("\t".join(out))
+ sys.stderr.flush()
+ sys.stdout.flush()
+
+sys.stderr.write("stop\n")
+sys.stdout.flush()
+