Hex Payload Decoder
The Hex Payload Decoder allows you to convert incoming hex string payloads into valid JSON data
Overview
The Hex Payload Decoder allows you to convert incoming hex string payloads into valid JSON data for non-LoRaWAN data sources.
How It Works
If a Transformation Function is enabled, data will be processed before storage. The decoder applies first, and then any defined transformation function modifies the data before it is stored in Qubitro.
Tips
Avoid unnecessary logic or external dependencies that could slow down execution.
Use arithmetic operations and bit shifts to convert hex values into readable fields.
Keep payload formatters simple and lightweight.
Need help reviewing your custom formatter? Our team can assist in checking your code for compatibility. Reach out via the Support Page.
Required Input Format
Data must be published as JSON with the following structure:
{ "payload_hex": "hex_value" }
The key must be "payload_hex"
in the incoming JSON payload. Any other key name will not be recognized by the system.
Function Schema
A decoder function processes incoming hex payloads and returns a structured JSON object.
Function Parameters
The decoder function receives a single parameter: input
, which contains:
bytes → A byte array representing the raw payload received.
function decoder(input) {
// Your decoding logic here
}
Return Values
To ensure compatibility with Qubitro’s no-code suite, the output should be a key-value JSON object.
Example
Incoming payload
{ "payload_hex": "7B2274656D7065726174757265223A32352C2268756D6964697479223A36302C227072657373757265223A313031332C2262617474657279223A39307D" }
Formatter code
function decoder(input) {
// Extract values from the input bytes array
// First byte represents temperature
let temperature = input.bytes[0];
// Second byte represents humidity
let humidity = input.bytes[1];
// Third & Fourth bytes represent pressure (16-bit value)
let pressure = (input.bytes[2] << 8) | input.bytes[3];
// Fifth byte represents battery level
let battery = input.bytes[4];
// Return an object containing the decoded values
return { temperature, humidity, pressure, battery };
}
Decoded payload
{
"temperature": 123,
"humidity": 34,
"pressure": 29797,
"battery": 109
}
Creating a Custom Decoder Function
Select the Function Type
Open the device details page in the Qubitro Portal.
Click the Functions tab.
Click Create Function and select Decoder Function.
Choose Hex Payload Decoder as the formatter type.
Write the Decoder Code
Enter your custom decoder function in the editor.
Adjust the function to match your device’s payload format.
Save and Apply the Function
Click Save to apply the decoder function.
Once saved, Qubitro will automatically apply the decoder to all incoming data for the assigned device.
Last updated