Begin to add binary support for swisscom receiver

This commit is contained in:
Nico Schottelius 2016-11-12 16:09:33 +01:00
parent f849f0f95b
commit acf5f05b81
7 changed files with 84 additions and 18 deletions

71
python/adeunisrf.py Normal file
View File

@ -0,0 +1,71 @@
#!/usr/bin/env python3
# Send lora packet to node-red when being triggered by postgresql
# Nico Schottelius <nico.schottelius -at- ungleich.ch>
# 2016-11-02
# GPLv3+
# Bit 6 = 1 : accelerometer was triggered
#
# Bit 5 = 0 : BTN1 was NOT triggered
#
# Bit 4 = 1 : GPS info is present
#
# Bit 3 = 1 : MAC Down Counter is present
#
# Bit 2 = 1 : MAC up Counter is present
#
# Bit 1 = 1 : Battery voltage information is present
#
# Bit 0 = 0 : RSSI + SNR information is NOT present
#
# * Byte 02 : 1E = 0001 1110 (Temperature in °C, signed in twos complement) = 30 °C
#
# * Byte 03 : 47 = GPS Latitude, degrees
#
# * Byte 04 : 22 = GPS Latitude, minutes
#
# * Byte 05 : 49 = GPS Latitude, minutes
#
# * Byte 06 : 60 = GPS Latitude, minutes + Hemisphere (0 = North)
#
# * Byte 07 : 00 = GPS Longitude, minutes
#
# * Byte 08 : 83 = GPS Longitude, minutes
#
# * Byte 09 : 18 = GPS Longitude, minutes
#
# * Byte 10 : 70 = GPS Longitude, minutes + Hemisphere (0 = East)
#
# * Byte 11 : none (because Byte 12 is starting with a 0 and not 1, 2 or 3)
#
# * Byte 12 : 08 = Uplink frame counter
#
# * Byte 13 : 08 = Downlink frame counter
#
# * Byte 14 : 0E = MSB Battery voltage )
#
# * Byte 15 : FD = LSB Battery voltage ) è 3.837 V
#
# * Byte 16 : none
#
# * Byte 17 : none
# should be: 46.969943, 9.038999
import binascii
def decode_pkg(pkg):
return binascii.a2b_hex(s)
def has_gps(pkg):
return pkg[0] & 0x10
def gpsdata(pkg):
if not has_gps(pkg):
return (0,0)
if __name__ == '__main__':
decode_pkg()

View File

@ -10,8 +10,11 @@ import psycopg2
import psycopg2.extensions
import websocket
import adeunisrf
channels = [ "loriot", "swisscom", "ttn" ]
def to_nodered(provider, data):
ws = websocket.create_connection("ws://localhost:1880/{}".format(provider))
ws.send("%s" % data)

View File

@ -15,15 +15,14 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
length = int(self.headers['Content-Length'])
post_data = self.rfile.read(length).decode('utf-8')
try:
payload = self.dataToString(post_data)
except UnicodeDecodeError:
payload = ""
payload = self.payload_hex(post_data)
deveui = self.get_deveui(post_data)
# Try to decode to unicode
try:
deveui = self.dataToDevEUI(post_data)
payload = self.data_to_unicode(payload)
except UnicodeDecodeError:
deveui = ""
pass
print("deveui/payload: {}:{}".format(deveui, payload))
@ -31,25 +30,18 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
lorautil.db_insert_json("swisscom", post_data, payload, deveui)
lorautil.db_notify("swisscom", payload, deveui)
def dictToPayload(self, thedict):
return thedict['DevEUI_uplink']['payload_hex']
def payload_hex(self, data):
mydict = lorautil.jsonToDict(data)
return mydict['DevEUI_uplink']['payload_hex']
def hexToString(self, myhex):
def data_to_unicode(self, myhex):
return bytes.fromhex(myhex).decode('utf-8')
def dataToString(self, data):
mydict = lorautil.jsonToDict(data)
payload = self.dictToPayload(mydict)
return self.hexToString(payload)
def dataToDevEUI(self, data):
def get_deveui(self, data):
mydict = lorautil.jsonToDict(data)
eui = mydict['DevEUI_uplink']['DevEUI']
return eui
def payload(self, data):
myhex = self.payload_hex(data)
return bytes.fromhex(myhex).decode('utf-8')
if __name__ == '__main__':
server_address = ('0.0.0.0', 8000)