Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
LoRaWAN Tabs decoder for The Things Network Console
/**
* Payload example on port 100: 01FB3700001F0000
**/
function Decoder(bytes, port) {
var decoded = {};
if (port === 100) {
decoded.open = bytes[0] & 0x01;
decoded.voltage = (25 + (bytes[1] & 0xf)) / 10;
decoded.capacity = parseInt(((bytes[1] & 0xf0) / 16) * 100 / 15);
decoded.temperature = (bytes[2] & 0x7f) - 32;
decoded.time_elapsed = (bytes[4] << 8 | bytes[3]) & 0xffff;
decoded.total_count = (bytes[7] << 8 | bytes[6] << 16 | bytes[5]) & 0xffffff;
}
return decoded;
}
/**
* Without CO2 and VOC; bytes are set to FF for newer Tabs sensors
* Payload example on port 103: 08FB353BFFFFFFFF
**/
function Decoder(bytes, port) {
var decoded = {};
if (port === 103) {
decoded.voltage = (25 + (bytes[1] & 0xf)) / 10;
decoded.capacity = parseInt(((bytes[1] & 0xf0) / 16) * 100 / 15);
decoded.temperature = (bytes[2] & 0x7f) - 32;
decoded.humidity = bytes[3] & 0x7f;
}
return decoded;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment