Commit payload and deveui
This commit is contained in:
parent
8cb67e9c34
commit
75361759d7
2 changed files with 12 additions and 4 deletions
2
sql
2
sql
|
@ -1 +1 @@
|
||||||
create table packets ( id SERIAL, received_dt timestamp default now(), provider varchar(128), packet json );
|
create table packets ( id SERIAL, received_dt timestamp default now(), provider varchar(128), packet json, payload varchar(128), deveui varchar(128) );
|
||||||
|
|
|
@ -32,7 +32,10 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
|
||||||
|
|
||||||
# Print on stdout
|
# Print on stdout
|
||||||
print(post_data)
|
print(post_data)
|
||||||
print(self.dataToString(post_data))
|
|
||||||
|
payload = self.dataToString(post_data)
|
||||||
|
deveui = self.dataToDevEUI(post_data)
|
||||||
|
print("{}:{}".format(deveui, payload))
|
||||||
|
|
||||||
# And insert into the db
|
# And insert into the db
|
||||||
self.insert_json("swisscom", post_data)
|
self.insert_json("swisscom", post_data)
|
||||||
|
@ -81,6 +84,11 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
|
||||||
payload = self.dictToPayload(mydict)
|
payload = self.dictToPayload(mydict)
|
||||||
return self.hexToString(payload)
|
return self.hexToString(payload)
|
||||||
|
|
||||||
|
def dataToDevEUI(self, data):
|
||||||
|
mydict = self.jsonToDict(data)
|
||||||
|
eui = mydict['DevEUI_uplink']['DevEUI']
|
||||||
|
return eui
|
||||||
|
|
||||||
def devEUI(self, data):
|
def devEUI(self, data):
|
||||||
root = ET.fromstring(data)
|
root = ET.fromstring(data)
|
||||||
return root[1].text
|
return root[1].text
|
||||||
|
@ -93,11 +101,11 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
|
||||||
myhex = self.payload_hex(data)
|
myhex = self.payload_hex(data)
|
||||||
return bytes.fromhex(myhex).decode('utf-8')
|
return bytes.fromhex(myhex).decode('utf-8')
|
||||||
|
|
||||||
def insert_json(self, provider, data):
|
def insert_json(self, provider, data, payload='', deveui=''):
|
||||||
try:
|
try:
|
||||||
conn = psycopg2.connect("dbname=lorawan")
|
conn = psycopg2.connect("dbname=lorawan")
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
cursor.execute("insert into packets values (DEFAULT, DEFAULT, %s, %s)", (provider, data, ))
|
cursor.execute("insert into packets values (DEFAULT, DEFAULT, %s, %s, %s, %s)", (provider, data, payload, deveui))
|
||||||
cursor.connection.commit()
|
cursor.connection.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
Loading…
Reference in a new issue