Hi,
this is the first line of my decoder script:
var data = decodeToJson(payload);
and it always produces this error:
[Error: decodeToJson(payload): com.fasterxml.jackson.core.JsonParseException: Illegal character ((CTRL-CHAR, code 1)): only regular white space (\r, \n, \t) is allowed between tokens at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); line: 1, column: 2]]
Does anyone else see this? Any idea why it’s happening?
This is the start of your Device Profile Codec? A quick google of that code looks like it is from the Integrations section on the Things Stack user guide so it will probably not work with Chirpstack. In Chirpstack you need to specify you are decoding an Uplink.
If you are trying to build a JavaScript payload codec in Chirpstack I would suggest starting from the sample code provided with a new device profile.
function decodeUplink(input) {
return {
data: {
// temp: 22.5
}
};
}
I generally always start my codecs with this bit of code because it lets me work with the data in hex rather than the Base64 that the data string is in.
function decodeUplink(input) {
const rawPacket = Buffer.from(input.bytes).toString('hex');
if (typeof rawPacket !== 'string' || rawPacket.length === 0) {
return { data: {} };
}
From this I can use a series of switch statements to determine the packet I received and decode it. If you are using a common sensor someone here may already have a codec written for it they could share. Or you may be able to find some extra guidance here: https://iotthinks.com/create-a-codec-for-lorawan-nodes/
1 Like
Wow, thank you for the head start. I’m new to applications like this. If I might ask, do you think it’s better to set up the codec on Chirpstack or on ThingsBoard? I know either will work, but maybe one is slightly better than the other.
I have honestly never used the ThingsBoard, so I cannot say much in regards to that. In terms of Chirpstack after you figure out your first codec for a device I have found it very easy to just modify that first codec to fit any new device I may want to use.
So it is really a matter of personal preference. But I will say after I build the codec in Chirpstack it was very easy for me to use the HTTP POST integration built into the system to send the JSON from uplinks into another system.