From f7f4fe6c9194681956ea68250a39cb9b7ac242b6 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 13 Nov 2016 19:45:26 +0100 Subject: [PATCH] add stdin handler (python) Signed-off-by: Nico Schottelius --- python/adeunisrf.py | 7 +++++++ python/lorautil.py | 9 +++++++++ sodaq_one/sodaq_one.ino | 4 +++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/python/adeunisrf.py b/python/adeunisrf.py index d1e8c11..a4fccd8 100644 --- a/python/adeunisrf.py +++ b/python/adeunisrf.py @@ -10,6 +10,7 @@ import binascii import lorautil import logging +import sys # L A T I T U D E L O N G I TU DE # status temp deg min sec +hem deg min min min @@ -27,6 +28,12 @@ log.setLevel(logging.DEBUG) known_devices = [ "0018B20000000C58", "0018B20000000C37", "0018B20000000C59", "0018B20000000CD0" ] +def convert_gps_from_stdin(): + for line in sys.stdin: + res = get_gps("", line) + if res: + print(res[0][1:]) + def get_gps(deveui, payload): res = [] if not int(payload[0:2], 16) & (2**7): diff --git a/python/lorautil.py b/python/lorautil.py index de979ad..56607ca 100644 --- a/python/lorautil.py +++ b/python/lorautil.py @@ -10,6 +10,8 @@ import logging import select import psycopg2 import psycopg2.extensions +import sys +import time import websocket @@ -46,6 +48,13 @@ def db_insert_json(provider, data, payload='', deveui=''): def jsonToDict(data): return json.loads(data) +def nodered_from_stdin(): + provider = sys.argv[1] + for line in sys.stdin: + print("{} -> {}".format(provider, line)) + nodered_send(provider,line) + time.sleep(0.1) + def nodered_send(provider, data): ws = websocket.create_connection("ws://localhost:1880/{}".format(provider)) diff --git a/sodaq_one/sodaq_one.ino b/sodaq_one/sodaq_one.ino index 39c86e8..9c2fa34 100644 --- a/sodaq_one/sodaq_one.ino +++ b/sodaq_one/sodaq_one.ino @@ -47,6 +47,7 @@ void setup() { String tmps; float tmp; + #define SLEEPTIME 10000 #define LOUDNESS_AVG 60 @@ -69,12 +70,13 @@ void loop() { // loraSend(getTempHumidHDC1000()); // loraSend(getCompass()); + sendIntAsString("battery=", getBatteryVoltage()); if((tmps = gpsGetPostion(120)) != "") { loraSend(tmps); } - sendIntAsString("battery=", getBatteryVoltage()); + /* if(cnt < LOUDNESS_AVG) { */