Loading...
Loading...
Loading...
Loading...
Loading...
By following this guide, you can customize Qubitro rule functions using JavaScript to create dynamic conditions.
function run(){
let temperature = ${{TEMPERATURE}};
let humidity = ${{HUMIDITY}};
let light = ${{LIGHT}};
let motion = ${{MOTION}};
let voltage = ${{VDD}};
}function run() {
let temperature = ${{TEMPERATURE}};
let humidity = ${{HUMIDITY}};
if (temperature > 25 && humidity > 70) {
trigger(); // Executes the pre-configured action
}
}function run() {
let temperature = ${{TEMPERATURE}};
let humidity = ${{HUMIDITY}};
if (temperature > 30 && humidity > 80) {
trigger(); // This executes the pre-configured action (e.g., send a notification)
}
}function run() {
let coordinates = ${{coordinates}}; // Assuming format [latitude, longitude]
// Convert coordinates array to an object
let incomingLocation = {
lat: coordinates[0],
lon: coordinates[1]
};
// Define the restricted zone (assembly area)
const restrictedZone = {
A: { lat: 40.822608, lon: 29.352864 },
B: { lat: 40.822652, lon: 29.353246 },
C: { lat: 40.822289, lon: 29.352890 },
D: { lat: 40.822327, lon: 29.353346 }
};
// Check if the incoming coordinates fall within the restricted area
const isInsideRectangle = (point, rect) => {
const minLat = Math.min(rect.A.lat, rect.B.lat, rect.C.lat, rect.D.lat);
const maxLat = Math.max(rect.A.lat, rect.B.lat, rect.C.lat, rect.D.lat);
const minLon = Math.min(rect.A.lon, rect.B.lon, rect.C.lon, rect.D.lon);
const maxLon = Math.max(rect.A.lon, rect.B.lon, rect.C.lon, rect.D.lon);
return point.lat >= minLat && point.lat <= maxLat && point.lon >= minLon && point.lon <= maxLon;
};
if (isInsideRectangle(incomingLocation, restrictedZone)) {
trigger(); // Triggers the predefined alert (e.g., send a warning notification)
}
}function run() {
let temperature = ${{TEMPERATURE}};
let humidity = ${{HUMIDITY}};
let lightLevel = ${{LIGHT}};
let co2Level = ${{CO2}};
// Trigger alert if temperature is too high and humidity is too low
if (temperature > 28 && humidity < 40) {
trigger(); // Executes the pre-configured alert
}
// Trigger alert if light levels drop too low while CO2 is high
if (lightLevel < 200 && co2Level > 1000) {
trigger(); // Executes the pre-configured alert
}
// Immediate action required for extreme conditions
if (temperature > 35 || humidity > 80 || co2Level > 1500) {
trigger(); // Executes the pre-configured alert
}
}By following this guide, you can customize Qubitro decoder functions to decode various sensor payloads and extract valuable network metrics from any LNS integration.
function decoder(input) {
var bytes = input.bytes; // Retrieve the raw data payload
var fPort = input.fPort; // Retrieve the fPort number
var metadata = input.metadata; // Retrieve LNS metadata
return {}; // Customize and return a JSON object as needed
}function decoder(input) {
const bytes = input.bytes;
const fPort = input.fPort;
// Combine two bytes into one number and adjust the scale (divide by 100)
const temperature = ((bytes[0] << 8) + bytes[1]) / 100;
return {
"bytes": bytes,
"fPort": fPort,
"temperature": temperature,
};
}function decoder(input) {
var bytes = input.bytes;
var fPort = input.fPort;
var data = {};
// Ensure the payload contains enough data for both sensors
if (bytes.length < 4) {
return { error: 'Payload too short' };
}
// Extract bytes for temperature and humidity
var temperatureBytes = bytes.slice(bytes.length - 4, bytes.length - 2);
var humidityBytes = bytes.slice(bytes.length - 2);
// Convert the byte arrays into 16-bit integers and scale accordingly
var temperature = ((temperatureBytes[0] << 8) | temperatureBytes[1]) / 100.0;
var humidity = ((humidityBytes[0] << 8) | humidityBytes[1]) / 100.0;
data["temperature"] = temperature;
data["humidity"] = humidity;
return data;
}function decoder(input) {
var bytes = input.bytes; // Sensor data payload
var fPort = input.fPort; // fPort value
var metadata = input.metadata; // LNS metadata from the uplink
var snr, rssi;
// Extract network metrics if available (works with any LNS provider)
if (metadata && metadata.gws && metadata.gws.length > 0) {
snr = metadata.gws[0].snr; // SNR from the first gateway
rssi = metadata.gws[0].rssi; // RSSI from the first gateway
}
// Additionally decode sensor-specific data (example calculations)
return {
STATUS: bytes[0] & 0x01, // Sensor status
BATTERY: (25 + (bytes[1] & 0x0f)) / 10, // Battery level estimate
COUNT: (bytes[7] << 16) | (bytes[6] << 8) | bytes[5], // Count extracted from multiple bytes
SNR: snr, // Signal-to-noise ratio from metadata
RSSI: rssi // Received signal strength indicator from metadata
};
}Explore the recommended guides below to quickly familiarize yourself with core platform features and workflows.
Learn how to publish multiple hex payloads using MQTTX and decode them using Qubitro’s Decoder Function. This guide walks you through secure MQTT setup, payload formatting, and real-time data decoding
Username and topic)function decoder(input) {
const longitude = ((input.bytes[0] << 24) | (input.bytes[1] << 16) | (input.bytes[2] << 8) | (input.bytes[6] & 0xC0)) /1000000;
const latitude = ((input.bytes[3] << 24) | (input.bytes[4] << 16) | (input.bytes[5] << 8) | ((input.bytes[6] & 0x30) << 2)) /1000000;
const hMSL32 = ((((input.bytes[6] & 0x0F) << 8 ) + input.bytes[7]) * 2) - 191;
const hAccCoeff = (input.bytes[8] & 0xE0) >> 5;
const vAccCoeff = (input.bytes[8] & 0x1C) >> 2;
const heading = ((input.bytes[8] & 0x03) << 2) + ((input.bytes[9] & 0xC0) >> 6);
const speed = (input.bytes[9] & 0x3F);
const battery = ((input.bytes[10]*256) + input.bytes[11]);
const year = (input.bytes[12] >> 2) + 2000;
const month = ((input.bytes[12] & 0x03) << 2) + ((input.bytes[13] & 0xC0) >> 6);
const day = (input.bytes[13] & 0x3E) >> 1;
const hour = ((input.bytes[13] & 0x01) << 4) + ((input.bytes[14] & 0xF0) >> 4);
const minute = ((input.bytes[14] & 0x0F) << 2) + ((input.bytes[15] & 0xC0) >> 6);
const second = (input.bytes[15] & 0x3F);
const timestampSeconds = Math.floor(new Date(year, month, day, hour, minute, second).getTime() / 1000);
return {
longitude,
latitude,
coordinates: [latitude, longitude],
hMSL32,
hAccCoeff,
vAccCoeff,
heading,
speed,
battery,
time: timestampSeconds
};
}{
"payload_hex": "00C08802808560A184000FFB648EAD0F,00c088028085909784000ffb648ead46,00c089028085109284000ffe648ead89,00c088028085e09c84000ffe648eadcb"
}




{
"sensor_type": "temperature",
"current_temperature": 22,
"average_temperature": 21
}{
"temperature_value": 22,
"humidity_value": 55
}{
"sum": 75,
"average": 15,
"max": 25,
"min": 5
}{
"start_date": "2020-01-01",
"end_date": "2020-01-01",
"duration_hours": "4 hours"
}{
"temp_value": 22,
"humidity_value": 78
}{
"sensor": {
"type": "temperature",
"readings": {
"current": 22,
"average": 21
}
}
}{
"sensor_type": sensor.type,
"current_temperature": sensor.readings.current,
"average_temperature": sensor.readings.average
}{
"sensors": [
{"type": "temperature", "value": 22},
{"type": "humidity", "value": 55}
]
}{
"temperature_value": sensors[type='temperature'].value,
"humidity_value": sensors[type='humidity'].value
}{
"values": [5, 10, 15, 20, 25]
}{
"sum": $sum(values),
"average": $average(values),
"max": $max(values),
"min": $min(values)
}{
"event": {
"start_time": "2020-01-01T08:00:00Z",
"end_time": "2020-01-01T12:00:00Z"
}
}{
"start_date": $fromMillis($toMillis(event.start_time), '[Y0001]-[M01]-[D01]'),
"end_date": $fromMillis($toMillis(event.end_time), '[Y0001]-[M01]-[D01]'),
"duration_hours": ($toMillis(event.end_time) - $toMillis(event.start_time)) / (1000*60*60) & " hours"
}{
"sensorData": {
"temperature": 22,
"humidity": 78
}
}{
"temp_value": $lookup(sensorData, 'temperature'),
"humidity_value": $lookup(sensorData, 'humidity')
}