Update receiver to use lorautil

This commit is contained in:
Nico Schottelius 2016-11-02 17:13:04 +01:00
parent 5e122197da
commit 3fcd397fcb
2 changed files with 6 additions and 2 deletions

View file

@ -3,6 +3,8 @@
# 2016-11-02 # 2016-11-02
# GPLv3+ # GPLv3+
import psycopg2
dbname="lorawan" dbname="lorawan"
def db_notify(provider, payload='', deveui=''): def db_notify(provider, payload='', deveui=''):

View file

@ -13,6 +13,8 @@ import json
import base64 import base64
import os import os
import lorautil
#Call back functions #Call back functions
# gives connection message # gives connection message
@ -29,14 +31,14 @@ def on_message(client,userdata,msg):
payload = base64.b64decode(mydict['payload']).decode('utf-8') payload = base64.b64decode(mydict['payload']).decode('utf-8')
print("{}: {}".format(deveui, payload)) print("{}: {}".format(deveui, payload))
insert_json("ttn", myjson, payload, deveui) lorautil.db_insert_json("ttn", myjson, payload, deveui)
lorautil.db_notify("ttn", payload, deveui)
def on_log(client,userdata,level,buf): def on_log(client,userdata,level,buf):
print("message:" + msg) print("message:" + msg)
print("userdata:" + str(userdata)) print("userdata:" + str(userdata))
if __name__ == '__main__': if __name__ == '__main__':
mqttc= mqtt.Client() mqttc= mqtt.Client()
mqttc.on_connect=on_connect mqttc.on_connect=on_connect