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.

The Hex Payload Decoder is only applicable for non-LoRaWAN data sources, such as MQTT, HTTP, or Onomondo. LoRaWAN devices use Device Templates or Custom Decoder for decoding.

How It Works

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.

Required Input Format

Data must be published as JSON with the following structure:

{ "payload_hex": "hex_value" }

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

Example

1

Incoming payload

{ "payload_hex": "7B2274656D7065726174757265223A32352C2268756D6964697479223A36302C227072657373757265223A313031332C2262617474657279223A39307D" }
2

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 };
}
3

Decoded payload

{
  "temperature": 123,
  "humidity": 34,
  "pressure": 29797,
  "battery": 109
}

Creating a Custom Decoder Function

1

Select the Function Type

  1. Open the device details page in the Qubitro Portal.

  2. Click the Functions tab.

  3. Click Create Function and select Decoder Function.

  4. Choose Hex Payload Decoder as the formatter type.

2

Write the Decoder Code

  1. Enter your custom decoder function in the editor.

  2. Adjust the function to match your device’s payload format.

3

Save and Apply the Function

  1. Click Save to apply the decoder function.

Last updated