When I look in the LoRaWAN frames within Chirpstack the frm_payload field contains the data I need.
However, the data that is recieved within node red does not contain this field, or if it does, it appears to be encrypted. This is the same message I have shown above within Chirpstack:
Hi, thank you for the suggestion. I did some more reading and and then saw your comment it appears the data I get in node red is base64 as you suggested. Converting it to hex and going from there appears to be give me the data I am looking for.
The data is in format base64 as @le_on suggested. You might need to convert it to HEX, BIN, DEC, Time Series Predix or whatever format the data needs for your application.
I suggest you to use a “function” node to decode and transform the data properly before reaching final destination.
Here is mine solution for a Temp + Hum sensor from Milesight:
See I decode and transform my base64 data in the node called “Time Series Predix Generator” (because I need to send data to a SCADA, which expects the data to income in this format).
Also note that the nodes “device Filter” can help you to differ the owner of the messages arriving (the device).
I can provide you with a proper script for this transformation… But I would thing first if you really need the data in HEX format, thought.
Where are you planning to send the data to? Are you sure HEX is the format required?
This is something you may get sure about it before start typing a script.
Nevertheless, I give you the code you need (in Javascript, which is the default language for the vast majority of devices and servers).
//Base64 to hexadecimal converter
function base64ToHex(str) {
const raw = atob(str);
let result = ‘’;
for (let i = 0; i < raw.length; i++) {
const hex = raw.charCodeAt(i).toString(16);
result += (hex.length === 2 ? hex : ‘0’ + hex);
}
return result.toUpperCase();
}
If you are planning to implement it on Node-RED, you should create a function node and call it this way:
If you enter this two lines in a function node in your Node-RED flow, then you got your base64 data converted to hex (msg.payload is the way you tell the node you want to transform the data incoming).
In hindsight I was initially asking for hex as we have a test system in the office that requires hex input. Going forwards decimal would be more appropriate.
It depends on the device from which the packets are coming, and the way they communicate with the server, it is not the same Modbus TCP/RTU than LoRaWAN, or pulses (analogic) devices.
For example LoRaWAN devices send uplinks in base64 or HEX format, whereas