add stdin handler (python)

Signed-off-by: Nico Schottelius <nico@wurzel.schottelius.org>
This commit is contained in:
Nico Schottelius 2016-11-13 19:45:26 +01:00
parent 3a696ece0c
commit f7f4fe6c91
3 changed files with 19 additions and 1 deletions

View file

@ -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):

View file

@ -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))

View file

@ -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) { */