add stdin handler (python)
Signed-off-by: Nico Schottelius <nico@wurzel.schottelius.org>
This commit is contained in:
parent
3a696ece0c
commit
f7f4fe6c91
3 changed files with 19 additions and 1 deletions
|
@ -10,6 +10,7 @@
|
||||||
import binascii
|
import binascii
|
||||||
import lorautil
|
import lorautil
|
||||||
import logging
|
import logging
|
||||||
|
import sys
|
||||||
|
|
||||||
# L A T I T U D E L O N G I TU DE
|
# 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
|
# status temp deg min sec +hem deg min min min
|
||||||
|
@ -27,6 +28,12 @@ log.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
known_devices = [ "0018B20000000C58", "0018B20000000C37", "0018B20000000C59", "0018B20000000CD0" ]
|
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):
|
def get_gps(deveui, payload):
|
||||||
res = []
|
res = []
|
||||||
if not int(payload[0:2], 16) & (2**7):
|
if not int(payload[0:2], 16) & (2**7):
|
||||||
|
|
|
@ -10,6 +10,8 @@ import logging
|
||||||
import select
|
import select
|
||||||
import psycopg2
|
import psycopg2
|
||||||
import psycopg2.extensions
|
import psycopg2.extensions
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
import websocket
|
import websocket
|
||||||
|
|
||||||
|
|
||||||
|
@ -46,6 +48,13 @@ def db_insert_json(provider, data, payload='', deveui=''):
|
||||||
def jsonToDict(data):
|
def jsonToDict(data):
|
||||||
return json.loads(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):
|
def nodered_send(provider, data):
|
||||||
ws = websocket.create_connection("ws://localhost:1880/{}".format(provider))
|
ws = websocket.create_connection("ws://localhost:1880/{}".format(provider))
|
||||||
|
|
|
@ -47,6 +47,7 @@ void setup() {
|
||||||
String tmps;
|
String tmps;
|
||||||
float tmp;
|
float tmp;
|
||||||
|
|
||||||
|
|
||||||
#define SLEEPTIME 10000
|
#define SLEEPTIME 10000
|
||||||
|
|
||||||
#define LOUDNESS_AVG 60
|
#define LOUDNESS_AVG 60
|
||||||
|
@ -69,12 +70,13 @@ void loop() {
|
||||||
// loraSend(getTempHumidHDC1000());
|
// loraSend(getTempHumidHDC1000());
|
||||||
// loraSend(getCompass());
|
// loraSend(getCompass());
|
||||||
|
|
||||||
|
sendIntAsString("battery=", getBatteryVoltage());
|
||||||
|
|
||||||
if((tmps = gpsGetPostion(120)) != "") {
|
if((tmps = gpsGetPostion(120)) != "") {
|
||||||
loraSend(tmps);
|
loraSend(tmps);
|
||||||
}
|
}
|
||||||
|
|
||||||
sendIntAsString("battery=", getBatteryVoltage());
|
|
||||||
|
|
||||||
|
|
||||||
/* if(cnt < LOUDNESS_AVG) { */
|
/* if(cnt < LOUDNESS_AVG) { */
|
||||||
|
|
Loading…
Reference in a new issue