Kontron TRACe-LP1 Gateway User Guide – SD.DT.G74.7e
www.kontron.com
// 24
5/
Packet Data Processing with Python (optional)
LoRaWAN™ messages from each devices can optionally be processed through a Python script before being published
over MQTT. This can be used to decode binary LoRaWAN™ payloads to more readable messages, to filter the
messages, to perform local sensor fusion or to distribute multiple MQTT messages from a single LoRaWAN™
message.
This process is made in Python. One or more MQTT messages (with their corresponding topics) can be created and
published over MQTT. The Python main program file is located in
/usr/lib/python2.7/site-packages/ trace_lora.py
Example :
No Python processing :
Topic:
"/Kontron/TRACe/123456789/LoRa/PB868LRH/0e7e346433306021/28 "
Message:
"010011"
With Python processing :
Topic
: "/Kontron/TRACe/123456789/LoRa/PB868LRH/0e7e346433306021/Event "
Message:
"Button Pushed; ;17"
At processing time, if the Python processing is activated for this device, the lora-agent will call the function
"process"
in the file
klora.py ()
with 3 arguments:
the type of the device as specified in fleet.json file
the port
the payload
The following example illustrates the processing of a LoRa pushed button device:
def process(deviceType,port,payload):
if deviceType=="PB868LRH":
return PB868LRH(port,payload)
elif deviceType=="IR868LR":
return IR868LR(port,payload)
elif deviceType=="CM868LRTH":
return CM868LRTH(port,payload)
elif deviceType=="YOUR_DEVICE_TYPE":
return YOUR_DEVICE_FUNCTION(port,payload)
else :
return " "
You can add your own function like this one:
def PB868LRH(port,payload):
p=int(port,16)
if p==0x28:
message="Event"+"|"
if payload[0:2]== "01":
message="Button Pushed; ; "
elif payload[0:2]== "02":
message=" ;Low Battery; "
Summary of Contents for Kontron TRACe-LP1
Page 1: ...USER GUIDE www kontron com Kontron TRACe LP1 Gateway SD DT G74 7e February 2019 ...
Page 6: ...Kontron TRACe LP1 Gateway User Guide SD DT G74 7e www kontron com 6 ...
Page 21: ...Kontron TRACe LP1 Gateway User Guide SD DT G74 7e www kontron com 21 ...
Page 29: ...Kontron TRACe LP1 Gateway User Guide SD DT G74 7e www kontron com 29 ...