Problem decode CayenneLPP

Hi. I have problem with data arived in Tago.IO

So , the entire messages is:

[ { “variable”: “frequency”, “value”: 868300000, “serie”: 1707670203820 }, { “variable”: “modulation”, “value”: “LORA”, “serie”: 1707670203820 }, { “variable”: “bandwidth”, “value”: 125, “serie”: 1707670203820 }, { “variable”: “spreading_factor”, “value”: 7, “serie”: 1707670203820 }, { “variable”: “code_rate”, “value”: “4/5”, “serie”: 1707670203820 }, { “variable”: “polarization_inversion”, “value”: false, “serie”: 1707670203820 }, { “variable”: “fCnt”, “value”: 14, “serie”: 1707670203820 }, { “variable”: “fPort”, “value”: 10, “serie”: 1707670203820 }, { “variable”: “deviceName”, “value”: “Test2”, “serie”: 1707670203820 }, { “variable”: “adr”, “value”: false, “serie”: 1707670203820 }, { “variable”: “dr”, “value”: 5, “serie”: 1707670203820 }, { “variable”: “objectJSON”, “value”: “{\“analogInput\”:{\“0\”:25.3,\“1\”:65.5,\“2\”:4.92}}”, “serie”: 1707670203820 }, { “variable”: “confirmedUplink”, “value”: false, “serie”: 1707670203820 }, { “variable”: “payload”, “value”: “000209e201021996020201ec”, “serie”: 1707670203820 }, { “variable”: “application_id”, “value”: “2”, “serie”: 1707670203820 }, { “variable”: “application_name”, “value”: “app”, “serie”: 1707670203820 }, { “variable”: “device_name”, “value”: “Test2”, “serie”: 1707670203820 }, { “variable”: “device_eui”, “value”: “6081f9741a7b90ee”, “serie”: 1707670203820 }, { “variable”: “dev_addr”, “value”: “008c3c69”, “serie”: 1707670203820 } ]

Problem it’s with “objectJSON” variable.

Variable “0” it is temperature

Variable “1” it is humidity

Variable “2” it is battery voltage.

Please, someone help me to make this variable available? At this momment i have “objectJSON” variable with exemple contet char “{\“analogInput\”:{\“0\”:25.3,\“1\”:65.5,\“2\”:4.92}}”

In gateway chirpstack messages appears ok

So, please, how can i solve the problem? Can someone help me with a custom paylod parser decoder?

Thanks you!

Hi,

Can you try to use this decoder for the custom connector.

function ParsePayload(payload) {

// Find the objectJSON variable in the payload

const objectJSON = payload.find((x) => x.variable === “objectJSON”);

// Check if objectJSON is found and has a value

if (!objectJSON || !objectJSON.value) {

return [{ variable: “parser_error”, value: “No objectJSON found or value is empty” }];

}

// Parse the JSON string from objectJSON.value

let dataValues;

try {

dataValues = JSON.parse(objectJSON.value).analogInput;

} catch (error) {

return [{ variable: “parser_error”, value: “Invalid JSON format” }];

}

// Extract the variables from the parsed JSON

const dateNow = new Date().toISOString();

const data = [

{ variable: “temperature”, value: dataValues[“0”], unit: “°C”, time: dateNow },

{ variable: “humidity”, value: dataValues[“1”], unit: “%”, time: dateNow },

{ variable: “battery_voltage”, value: dataValues[“2”], unit: “V”, time: dateNow }

];

return data;

}

var objectJSONExists = payload.find((x) => x.variable === “objectJSON”);

if (objectJSONExists) {

payload = ParsePayload(payload);

}

It’s works! Thank you!!

But one more problem. Now I have only 3 variables( temperature, humidity and voltage). I want to have and the others variables ( such as : device_eui , fPort) from original message.

Sure, follows the code updated.

function ParsePayload(payload) {

// Find the objectJSON variable in the payload

const objectJSON = payload.find((x) => x.variable === “objectJSON”);

// Check if objectJSON is found and has a value

if (!objectJSON || !objectJSON.value) {

return [{ variable: “parser_error”, value: “No objectJSON found or value is empty” }];

}

// Parse the JSON string from objectJSON.value

let dataValues;

try {

dataValues = JSON.parse(objectJSON.value).analogInput;

} catch (error) {

return [{ variable: “parser_error”, value: “Invalid JSON format” }];

}

// Extract the variables from the parsed JSON

const dateNow = new Date().toISOString();

const data = [

{ variable: “temperature”, value: dataValues[“0”], unit: “°C”, time: dateNow },

{ variable: “humidity”, value: dataValues[“1”], unit: “%”, time: dateNow },

{ variable: “battery_voltage”, value: dataValues[“2”], unit: “V”, time: dateNow }

];

payload.push(…data);

payload = payload.filter((x) => x.variable !== “objectJSON”);

}

var objectJSONExists = payload.find((x) => x.variable === “objectJSON”);

if (objectJSONExists) {

ParsePayload(payload);

}

Thank you again. It’s works!

But it’s strange, beacause I have a microcontroller Heltec Stick Lite with this software:

https://github.com/lnlp/LMIC-node

Initially I used Helium server and it’s worked perfect in Tago.

More exactly: in past I had this flow: Lmic-node(heltec stick lite) → Helium network ( helium console with CayenneLPP decoder) → Tago.IO And it’s works perfect ( I saw all variable including with unit)

And now I have: Same program in microcontroler (Lmic-node) ->ChirpStack gateway (I selected preedefined codec CayenneLPP) → Tago.Io

So I think it’s a probblem with code codec CayenneLPP inside ChirpStack. I tryed to found code from CayenneLPP codec used in Helium console ( to use a custom java script codec in my chirpstack gateway) , but I don’t found it.

Hey George,

Right, whats happening is that you changed LNS’s from Helium to Chirpstack. With this change, your Device now uses the ChirpStack Network Connector at TagoIO instead of the Helium Network Connector.

The Helium Network Connector has a feature implemented in it that allows it to format already decoded data from the Helium Payload over to TagoIO Format.

Contrary to the Helium Connector, the ChirpStack Connector doesn’t have this feature implemented, so the decoded data from the ChirpsStack codec CayenneLPP:

{ “variable”: “objectJSON”, “value”: “{\“analogInput\”:{\“0\”:25.3,\“1\”:65.5,\“2\”:4.92}}” }

,Isn’t automatically being transformed to TagoIO Formatted data at the Network Connector level. Instead, the ChirpStack Connector is sending over the decoded data inside a single variable: “objectJSON”.

Hopefully this makes things more clear! :slight_smile:

Yes, thank you! Now it’s much clearer.