Skip to content

Instantly share code, notes, and snippets.

@rroemhild
Last active August 20, 2019 10:52
Show Gist options
  • Save rroemhild/6247fced9139fd22414dd48563ed0a00 to your computer and use it in GitHub Desktop.
Save rroemhild/6247fced9139fd22414dd48563ed0a00 to your computer and use it in GitHub Desktop.
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