Where can I find a description of a ChirpStack v4 data packet from an end node?
I have an Arduino MKRWAN 1310 and have not been successful in getting data from it into ChirpStack or NodeRed. I can see the Payload Raw data bytes but cannot find how to process them into meaningful values.
Show me your code of the upload part.
I can give you the sample decode.
I guess you are uploading a string like “Hello”?
I added a converter from bytes array to a string for you.
This is a decoder to decode a string payload in an uplink.
function decodeUplink(input) {
var bytes = input.bytes;
// To convert a byte array bytes to a string returnStr
// To remove a null character at the end
var returnStr = String.fromCharCode.apply(String, bytes ).replace(/\0/g,'');
return {"data": {"returnStr ":returnStr}};
}
Thank you all for your help. I am using the example program that comes with the Arduino MKRWAN library: LoraSendAndReceive.ino. All it does is connect and allow the user to enter a text string to send. Using the codec from IoTThinks, all I see using NodeRed is returnStr : “”. However, in Chirpstack LoRaWAN frames I can see the decimal values of the characters in frm_payload: Raw.
LoRaWAN is NOT for strings. LoRaWAN is for couple of bytes. To my style no more than 10-15 bytes. Strings are bad practice. Use numbers: bytes, not characters.
Use bytes and then feed them with the decoder to an integration. In fact in Chirpstack for a rough view, you can skip the integration. You can go Device profile > Measurements and if your decoder is working fine you can define in Measurements the variables.
After that for Applications > Device > Select Device > Device metrics you can see your decoded data.
Find a way to test your decoder. Chirpstack does not have a tool to help you for this.
Hi clavisound, I realize that LoRaWAN is for short bursts of data. Right now I am just trying to see if the codec gets the bytes being sent. So far I have not been successful.
Start simple. Send one byte - for example battery level - and then decoded it with the coder. In events tab you will see the decoded value not only the encrypted. Configure the node to send every time you press the button or periodically to debug.
Example for one byte - untested
// Decode uplink function.
//
// Input is an object with the following fields:
// - bytes = Byte array containing the uplink payload, e.g. [255, 230, 255, 0]
// - fPort = Uplink fPort.
// - variables = Object containing the configured device variables.
//
// Output must be an object with the following fields:
// - data = Object representing the decoded payload.
function decodeUplink(input) {
var data = {};
data.battery = input.bytes[0];
return {
data: data
};
}
I believe I have not made myself clear. The data which is shown looking at the Events tag are AFTER the codec. The frames tag does show the four bytes I entered into the MKRWAN 1310 in a section named Payload Raw. I have tried displaying the individual bytes within input.bytes and get all 0s. I have also put fixed values into input.bytes in the codec and they get accepted and displayed within both Node Red and ChirpStack.
So, it looks to me like the codec is either not getting the bytes or there is another object I need to try.
Sorry to be so late with this, had some sickness last week.
Here are two versions of decoders I have tried. I am using the Arduino sample program LoraSendAndRecieve.ino to send data to LoRaWAN. For both tests I sent a single byte value of “1” which is a decimal value of 49.
function decodeUplink(input) {
// this works as expected when I send something from the 1310
var Humid = 511;
var Temp = 213;
var VBat = 3006;
return {“data”: { “Humid”:Humid, “Temp”:Temp, “Vbatt”: VBat } };
}
Looking at the Event, I show
object: {} 3 keys
Temp: 213
Vbatt: 3006
Humid: 511
function decodeUplink(input) {
// this does not work: Humid shows a value of null, Temp and Batt are correct
var Humid = input.bytes[0] + input.bytes[1] + input.bytes[2] + input.bytes[3] + input.bytes[4];
var Temp = 213;
var VBat = 3006;
return {“data”: { “Humid”:Humid, “Temp”:Temp, “Vbatt”: VBat } };
}
Looking at the Event, I show
object: {} 3 keys
Humid: null
Vbatt: 3006
Temp: 213