From f461190e22a97bde985b067ce01c4ed9c74f7e62 Mon Sep 17 00:00:00 2001 From: pks Date: Sat, 1 May 2021 06:17:55 +0200 Subject: v1 --- v1/receive.py | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 v1/receive.py (limited to 'v1/receive.py') diff --git a/v1/receive.py b/v1/receive.py new file mode 100755 index 0000000..71d0a67 --- /dev/null +++ b/v1/receive.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 + +from RFXtrx import PySerialTransport +import sys, datetime, os + + +if __name__ == "__main__": + transport = PySerialTransport('/dev/ttyUSB0') + transport.reset() + + while True: + if os.path.isfile('/home/pks/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() -- cgit v1.2.3