Click Connect to establish a secure MQTT connection.
1. Go to your device → Functions tab
2. Click Add Function → Choose Decoder Function
3. Paste the following JavaScript code:
Copy 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
};
}
You can also test a single hex payload on the Qubitro Portal to verify your decoder.
Copy {
"payload_hex": "00C08802808560A184000FFB648EAD0F,00c088028085909784000ffb648ead46,00c089028085109284000ffe648ead89,00c088028085e09c84000ffe648eadcb"
}
Open the Storage tab in your Qubitro device and you’ll see structured decoded values like: