Implement receiver for ttn v2
This commit is contained in:
parent
b96e09f3e7
commit
4c28cc647f
|
@ -8,6 +8,7 @@ import re
|
||||||
import json
|
import json
|
||||||
import pprint
|
import pprint
|
||||||
import lorautil
|
import lorautil
|
||||||
|
import base64
|
||||||
|
|
||||||
# HTTPRequestHandler class
|
# HTTPRequestHandler class
|
||||||
class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
|
class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
|
||||||
|
@ -15,6 +16,8 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
|
||||||
length = int(self.headers['Content-Length'])
|
length = int(self.headers['Content-Length'])
|
||||||
post_data = self.rfile.read(length).decode('utf-8')
|
post_data = self.rfile.read(length).decode('utf-8')
|
||||||
|
|
||||||
|
print(post_data)
|
||||||
|
|
||||||
payload = self.payload_hex(post_data)
|
payload = self.payload_hex(post_data)
|
||||||
deveui = self.get_deveui(post_data)
|
deveui = self.get_deveui(post_data)
|
||||||
|
|
||||||
|
@ -32,15 +35,14 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
|
||||||
|
|
||||||
def payload_hex(self, data):
|
def payload_hex(self, data):
|
||||||
mydict = lorautil.jsonToDict(data)
|
mydict = lorautil.jsonToDict(data)
|
||||||
return mydict['DevEUI_uplink']['payload_hex']
|
return mydict['payload_raw']
|
||||||
|
|
||||||
def data_to_unicode(self, myhex):
|
def data_to_unicode(self, myhex):
|
||||||
return bytes.fromhex(myhex).decode('utf-8')
|
return base64.b64decode(myhex).decode('utf-8')
|
||||||
|
|
||||||
def get_deveui(self, data):
|
def get_deveui(self, data):
|
||||||
mydict = lorautil.jsonToDict(data)
|
mydict = lorautil.jsonToDict(data)
|
||||||
eui = mydict['DevEUI_uplink']['DevEUI']
|
return mydict['hardware_serial']
|
||||||
return eui
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in New Issue