Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 28 additions & 12 deletions decodeUplink.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*
* Created by Caspar Armster (dasdigidings e.V. / The Things Network Rhein-Sieg) - www.dasdigidings.de
* This function is based on the work from Cameron Sharp at Sensational Systems - cameron@sensational.systems
* This Edit ist based on the PR from https://github.com/mfalkvidd in https://github.com/dasdigidings/the_things_stack_v3_tabs_decoder
*/

function decodeUplink(input) {
Expand All @@ -12,20 +13,34 @@ function decodeUplink(input) {
"bytes": input.bytes, // original payload
"port" : input.fPort // lorawan port
};
var batteryStatus = input.bytes[1];

// Every device transmits the battery status and the temperature
// Battery measurement
battery = input.bytes[1] & 0x0f;
battery = (25 + battery) / 10;
capacity = input.bytes[1] >> 4;
capacity = (capacity / 15) * 100;
switch(batteryStatus){
case 0:
// Device is charging or line powered.
data.charging = true;
data.batteryFault = false;
break;
case 255:
// Device could not measure battery — possible Fault
data.batteryFault = true;
break;
default:
data.charging = false;
data.batteryFault = false;
battery = input.bytes[1] & 0x0f;
battery = (25 + battery) / 10;
data.battery = battery;
capacity = input.bytes[1] >> 4;
capacity = (capacity / 15) * 100;
data.capacity = capacity;
}

// Temperature measurement
temperature = input.bytes[2] & 0x7f;
temperature = temperature - 32;

data.battery = battery;
data.capacity = capacity;
data.temperature = temperature;

// depending on the lorawan port we know which tabs sensor is delivering the data
Expand Down Expand Up @@ -150,14 +165,14 @@ function decodeUplink(input) {
data.temperatureEnvironment = temperatureEnvironment;
data.humidity = humidity;
data.humidityError = humidityError;

} else if (input.fPort === 136) { // Object Locator
// GNSS Fix?
if ((input.bytes[0] & 0x8) === 0) {
positionGnssFix = true;
} else {
positionGnssFix = false;
}

// Accuracy Measurement
positionAccuracy = input.bytes[10] >> 5;
positionAccuracy = Math.pow(2, parseInt(positionAccuracy) + 2);
Expand All @@ -178,10 +193,11 @@ function decodeUplink(input) {
positionLatitude = positionLatitude / 1000000;
positionLongitude = positionLongitude / 1000000;

data.positionGnssFix = positionGnssFix;
data.positionLatitude = positionLatitude;
data.positionLongitude = positionLongitude;
data.positionAccuracy = positionAccuracy;
// removed "position" after "data." to let TTN understand the Location and make it usable for TTN-Mapper.org
data.gnssfix = positionGnssFix;
data.latitude = positionLatitude;
data.longitude = positionLongitude;
data.accuracy = positionAccuracy;
}

return {
Expand Down
2 changes: 1 addition & 1 deletion decodeUplink.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.