From 6602000cb7c68e53749a5d8aac759ac41a487a0b Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 12 Mar 2020 14:53:50 +0100 Subject: [PATCH] add support for sending to ttn2prom --- python/lorautil.py | 12 +++++++++++- python/notify.py | 3 ++- python/risinghf.py | 1 - python/ttn_receiver_ttn.py | 26 ++++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 python/ttn_receiver_ttn.py diff --git a/python/lorautil.py b/python/lorautil.py index 29f97ef..a2a5458 100644 --- a/python/lorautil.py +++ b/python/lorautil.py @@ -13,7 +13,7 @@ import psycopg2.extensions import sys import time import websocket - +import requests logging.basicConfig(format='%(levelname)s: %(message)s') log = logging.getLogger(__name__) @@ -60,6 +60,16 @@ def nodered_send(path, data): ws.send("%s" % data) ws.close() + + + +myobj = {'somekey': 'somevalue'} + + +def ttn2prom_send(path, data): + url = 'http://localhost:8047/' + x = requests.post(url, data = data) + channels = [ "loriot", "swisscom", "ttn" ] def pg_conn_notify(): diff --git a/python/notify.py b/python/notify.py index 1795103..54ea714 100644 --- a/python/notify.py +++ b/python/notify.py @@ -16,4 +16,5 @@ if __name__ == '__main__': conns = lorautil.pg_conn_notify() while True: - lorautil.pg_wait_for_pkg(conns, lorautil.nodered_send) +# lorautil.pg_wait_for_pkg(conns, lorautil.nodered_send) + lorautil.pg_wait_for_pkg(conns, lorautil.ttn2prom_send) diff --git a/python/risinghf.py b/python/risinghf.py index 55b62ad..5ccaefe 100644 --- a/python/risinghf.py +++ b/python/risinghf.py @@ -60,5 +60,4 @@ if __name__ == '__main__': print(get_temperature(payload_hex)) print(get_humidity(payload_hex)) - # print("{} {}".format(payload_raw, payload_hex)) diff --git a/python/ttn_receiver_ttn.py b/python/ttn_receiver_ttn.py new file mode 100644 index 0000000..30417ca --- /dev/null +++ b/python/ttn_receiver_ttn.py @@ -0,0 +1,26 @@ +import time +import ttn +import os + +app_id = os.environ['ttn_app_id'] # f.i. "datacenterlight" +access_key = os.environ['ttn_access_key'] # f.i. "ttn-account..." + +def uplink_callback(msg, client): + print("Received uplink from ", msg.dev_id) + print(msg) + +handler = ttn.HandlerClient(app_id, access_key) + +# using mqtt client +mqtt_client = handler.data() +mqtt_client.set_uplink_callback(uplink_callback) +mqtt_client.connect() +time.sleep(60) +mqtt_client.close() + +# using application manager client +app_client = handler.application() +my_app = app_client.get() +print(my_app) +my_devices = app_client.devices() +print(my_devices)