Loading...
Loading...
Loading...
Loading...
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.
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.
• 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.
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.
Create a simple decoder function that extracts the raw bytes, fPort, and metadata:
In this example, assume that the sensor sends temperature data encoded in two bytes. The function converts these bytes into a decimal temperature value:
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:
Decoder functions can also extract network metrics (such as SNR and RSSI) from the metadata. This example demonstrates how to do so:
This guide explains how to use JSONata expressions in Qubitro Transformation Functions to manipulate and structure real-time data before it is stored or used for automated actions.
JSONata provides a flexible, lightweight way to filter, calculate, and restructure data without writing traditional code.
A few things to remember:
Data can be modified on-the-fly before storage and automation.
TF applies immediately to incoming data, whether raw or already decoded.
Once a device sends data, TF automatically applies the JSONata expression configured by the user.
If a Decoder Function exists, it will process raw data first, and then TF will apply JSONata expressions on the decoded output. If there is no decoder, TF will apply transformations directly to the published data.
Here are some core JSONata concepts:
Mathematical functions: $sum(values), $average(values), $max(values), $min(values).
Ternary operators: condition ? trueValue : falseValue.
String and numeric literals: "text" for strings, 42 for numbers.
Using the root object: $ refers to the root JSON object.
Accessing fields: fieldname retrieves a specific property.
Convert a multi-level JSON object into a flat structure for better Qubitro compatibility.
Transform an array of objects into structured key-value pairs.
Use JSONata to compute sums, averages, and find min/max values dynamically.
Modify timestamps into human-readable formats or compute durations.
This method is useful when field names may change dynamically.
By following this guide, you can customize Qubitro rule functions using JavaScript to create dynamic conditions.
This guide explains how to use JavaScript within Qubitro’s rule functions to define custom conditions and automate actions based on real-time data.
A few notes to remember:
Rule Functions operate only on real-time data – They cannot query historical data from the database.
Each Rule Function executes a single pre-configured action – It does not support executing multiple actions within one function.
Actions are predefined during function setup – The trigger() function executes only the action assigned when creating the rule.
Although the examples here focus on environmental monitoring and geofencing, the same approach applies to any scenario requiring event-driven automation.
Qubitro provides a simple way to access sensor values in JavaScript using predefined keys. These keys allow you to reference the latest device data without complex parsing.
Define variables using predefined keys:
Each variable directly pulls the corresponding real-time value from the incoming data.
With variables defined, you can create logical conditions to decide when the function should trigger an action.
This function triggers an action if the temperature is above 25°C and humidity exceeds 70%.
The trigger()
function is used to execute predefined action when conditions are met.
This example ensures that a device does not enter a restricted assembly area. If it does, the function triggers an alert.