Skip to content

Improvements to Browan Tab Object locator / Tab-all#8

Open
mfalkvidd wants to merge 1 commit intodasdigidings:mainfrom
mfalkvidd:object-locator-improvements
Open

Improvements to Browan Tab Object locator / Tab-all#8
mfalkvidd wants to merge 1 commit intodasdigidings:mainfrom
mfalkvidd:object-locator-improvements

Conversation

@mfalkvidd
Copy link
Copy Markdown

Copy link
Copy Markdown

@Wlanfr3ak Wlanfr3ak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me its only working with removed 3 lines from your PR with this code AND remove position from the data fields to let ttn understand its the location from the device and for ttnmapper!:

`
function decodeUplink(input) {

var data = {
    "bytes": input.bytes, // original payload
    "port" : input.fPort  // lorawan port
};
var batteryStatus = input.bytes[1];


switch(batteryStatus){
    case 0:
        
        data.charging = true;
        data.batteryFault = false;
        break;
    case 255:
        
        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 = input.bytes[2] & 0x7f;
temperature = temperature - 32;
data.temperature = temperature;

if (input.fPort === 100) { // Door & Window Sensor

    openingStatusTime = (input.bytes[4] << 8) | input.bytes[3];

    
    openingStatusCount = ((input.bytes[7] << 16) | (input.bytes[6] << 8)) | input.bytes[5];

   
    openingStatus = input.bytes[0] & 0x1;
    if (openingStatus === 1) {
        openingStatusOpen = true;
    } else {
        openingStatusOpen = false;
    }

    data.openingStatusTime = openingStatusTime;
    data.openingStatusCount = openingStatusCount;
    data.openingStatusOpen = openingStatusOpen;
}
 else if (input.fPort === 136) { // Object Locator
    
    if ((input.bytes[0] & 0x8) === 0) {
        positionGnssFix = true;
    } else {
        positionGnssFix = false;
    }
    
    positionAccuracy = input.bytes[10] >> 5;
    positionAccuracy = Math.pow(2, parseInt(positionAccuracy) + 2);

   
    input.bytes[10] &= 0x1f;

    if ((input.bytes[10] & (1 << 4)) !== 0) {
      input.bytes[10] |= 0xe0;
    }

    
    input.bytes[6] &= 0x0f;

  
    positionLatitude = ((input.bytes[6] << 24 | input.bytes[5] << 16) | input.bytes[4] << 8 ) | input.bytes[3];
    positionLongitude = ((input.bytes[10] << 24 | input.bytes[9] << 16) | input.bytes[8] << 8 ) | input.bytes[7];
    positionLatitude = positionLatitude / 1000000;
    positionLongitude = positionLongitude / 1000000;

    data.gnssfix = positionGnssFix;
    data.latitude = positionLatitude;
    data.longitude = positionLongitude;
    data.accuracy = positionAccuracy;
}

return {
    data: data,
    warnings: [],
    errors: []
};

}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants