From 3cfb50e9fa16619d84c71dbdb1ccea289a233102 Mon Sep 17 00:00:00 2001 From: Maps Date: Tue, 8 Sep 2015 17:07:15 +0200 Subject: [PATCH] pt100: feed.py the log file --- sensors/data/feed.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 sensors/data/feed.py diff --git a/sensors/data/feed.py b/sensors/data/feed.py new file mode 100755 index 0000000..6162c9b --- /dev/null +++ b/sensors/data/feed.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python + +import argparse +import sys +import time + +import serial + +parser = argparse.ArgumentParser() +parser.add_argument('--timestamps', action='store_true', help='Add timestamps to the output') +parser.add_argument('device', help='The serial port to open') +args = parser.parse_args() + + +ser = serial.Serial(args.device, baudrate=38400, timeout=0.1) + +output = sys.stdout + +last_time = int(time.time()) - 1 + +try: + while True: + now = int(time.time()) + if args.timestamps and now != last_time: + output.write(b'#{}\n'.format(now)) + last_time = now + line = ser.readline() + if not line: continue + line = line.strip() + output.write(line + b'\n') + output.flush() +except KeyboardInterrupt: + sys.stderr.write(b'Ctrl-C pressed, exiting...\n') + sys.exit(1) + -- 2.43.0