How to Decode Uplink Messages with Qubitro Decoder Functions
By following this guide, you can customize Qubitro decoder functions to decode various sensor payloads and extract valuable network metrics from any LNS integration.
This guide explains how to use Qubitro’s decoder functions to parse raw uplink messages received via LNS integrations—such as The Things Stack, Loriot, and others.
Although the examples here refer to decoding sensor data (like temperature or humidity), these functions work the same way for any LNS provider.
Key Concepts
Decoder Function
A custom function that Qubitro automatically invokes with an input object containing the uplink message’s raw data, the fPort, and additional metadata.
Input Properties
• bytes: A byte array representing the raw data payload.
• fPort: The port number used for the uplink message.
• metadata: Rich network details from the LNS (e.g., signal quality, gateway information), regardless of the provider.
How It Works
Qubitro supplies the decoder function with an input object that includes all necessary properties.
Your function should extract the required sensor values by converting raw bytes into human-readable data. You can also extract network metrics—like RSSI and SNR—from the metadata.
Accessing Input Properties
Create a simple decoder function that extracts the raw bytes, fPort, and metadata:
Decoding a Temperature Sensor Message
In this example, assume that the sensor sends temperature data encoded in two bytes. The function converts these bytes into a decimal temperature value:
Decoding Temperature and Humidity Data
This example demonstrates handling multiple sensor readings. The function first checks if the payload is long enough and then extracts temperature and humidity from the last four bytes:
Accessing Metadata for Network Metrics
Decoder functions can also extract network metrics (such as SNR and RSSI) from the metadata. This example demonstrates how to do so:
Last updated