Introduction
This article will show you how to decode payload and customize the uplink format when you connect Ursalink gateway to your MQTT Server. This feature applies to UG6x and UG8x with firmware 80.0.0.64 and above.
Please refer to the article to connect Ursalink gateway to MQTT server at first:
5 Steps to Remotely Control DO via MQTT
Content
Add Decoder to Gateway
Go to "Network Server"--"Applications" and choose the Payload Codec as Custom. Then you can fill the Javascript in Payload decoder function to customize uplink payload.
If you use Ursalink LoRaWAN end-node, you can find the decoder on Github. Before using the the decoder, the decorder function header should be changed.
Original:
function Decoder(bytes, port) {
It should be changed to :
function Decode(fPort, bytes) {
After adding the decoder, the gateway will only send decoded data to third-party servers. Example:
"activity": 73,
"battery": 92,
"co2": 1149,
"humidity": 47.5,
"illumination": 29,
"pressure": 1004.8,
"temperature": 30.8,
"tvoc": 0
Uplink Contents Customization
Uplink contents customization can be achieved by LoRaObject function: Gateway Uplink
Please refer to the image and example to add statement in your decoder.
Example 1: Send only device EUI, RSSI, SNR and raw data to server.
Decoder:
function Decode(fPort, bytes) {
var decoder = {};
decoded.devEUI = LoRaObject.devEUI;
decoded.rssi = LoRaObject.rxInfo[0].rssi;
decoded.snr = LoRaObject.rxInfo[0].loRaSNR;
decoded.data = LoRaObject.data;
return decoded;
}
Result:
"devEUI":24e1611234567890
"rssi": -5,
"snr": 11,
"data": AXVkA2cgAQRoegUAAA==
Example 2: Send all basic information and decoded data to server.
Decoder:
function Decode(fPort, bytes) {
var decoder = {};
//Decoder Content
if(bytes[i]==0x01){
decoded.temperature=(readInt16LE(bytes.slice(i+2, i+4)))/10;
i+=4;
continue;
}
decoded.obj= LoRaObject; //Add all basic information
return decoded;
}
Result:
"temperature" : 23,
"obj" : {
"applicationID" : "1",
"applicationName" : "cloud",
...................
...................
"frequency" : 868300000
}
Comments
0 comments
Please sign in to leave a comment.