add support for sending to ttn2prom
This commit is contained in:
parent
d4349fa854
commit
6602000cb7
4 changed files with 39 additions and 3 deletions
|
@ -13,7 +13,7 @@ import psycopg2.extensions
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import websocket
|
import websocket
|
||||||
|
import requests
|
||||||
|
|
||||||
logging.basicConfig(format='%(levelname)s: %(message)s')
|
logging.basicConfig(format='%(levelname)s: %(message)s')
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
@ -60,6 +60,16 @@ def nodered_send(path, data):
|
||||||
ws.send("%s" % data)
|
ws.send("%s" % data)
|
||||||
ws.close()
|
ws.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
myobj = {'somekey': 'somevalue'}
|
||||||
|
|
||||||
|
|
||||||
|
def ttn2prom_send(path, data):
|
||||||
|
url = 'http://localhost:8047/'
|
||||||
|
x = requests.post(url, data = data)
|
||||||
|
|
||||||
channels = [ "loriot", "swisscom", "ttn" ]
|
channels = [ "loriot", "swisscom", "ttn" ]
|
||||||
|
|
||||||
def pg_conn_notify():
|
def pg_conn_notify():
|
||||||
|
|
|
@ -16,4 +16,5 @@ if __name__ == '__main__':
|
||||||
conns = lorautil.pg_conn_notify()
|
conns = lorautil.pg_conn_notify()
|
||||||
|
|
||||||
while True:
|
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)
|
||||||
|
|
|
@ -60,5 +60,4 @@ if __name__ == '__main__':
|
||||||
print(get_temperature(payload_hex))
|
print(get_temperature(payload_hex))
|
||||||
print(get_humidity(payload_hex))
|
print(get_humidity(payload_hex))
|
||||||
|
|
||||||
|
|
||||||
# print("{} {}".format(payload_raw, payload_hex))
|
# print("{} {}".format(payload_raw, payload_hex))
|
||||||
|
|
26
python/ttn_receiver_ttn.py
Normal file
26
python/ttn_receiver_ttn.py
Normal file
|
@ -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)
|
Loading…
Reference in a new issue