TTN Smart Sensor (Ellenex)

Sensor

Codec Description

Codec for Ellenex

Codec Preview

function decodeUplink(input) { switch (input.fPort) { case 15: // return error if length of Bytes is not 8 if (input.bytes.length != 8) { return { errors: ['Invalid uplink payload: length is not 8 byte'], }; } if(input.bytes[0] == 0x80) { //Used for FMS2 let primarySense = readHex2bytes(input.bytes[1], input.bytes[2]); //Pressure for FMS2 //Does not account for negative numbers let pulseCounter = input.bytes[3] << 24 | input.bytes[4] << 16 | input.bytes[5] << 8 | input.bytes[6]; }else if(input.bytes[0] == 0x82) { //TODO } //let secondarySense = readHex2bytes(input.bytes[5], input.bytes[6]); let batteryVoltage = input.bytes[7] * 0.1; return { // Decoded data data: { primarySense: primarySense, pulseCounter: pulseCounter, batteryVoltage: +batteryVoltage.toFixed(1), }, }; default: return { errors: ['Unknown FPort: please use fPort 1'], }; } } /* * The readHex2bytes function is to decode a signed 16-bit integer * represented by 2 bytes. */ function readHex2bytes(byte1, byte2) { let result = (byte1 << 8) | byte2; // merge the two bytes // check whether input is signed as a negative number // by checking whether significant bit (leftmost) is 1 let negative = byte1 & 0x80; // process negative value if (negative) { //result = ~(0xFFFF0000 | (result - 1)) * (-1); // minus 1 and flip all bits result = result - 0x10000; } return result; }

This codec is sourced from The Things Network. All rights belong to The Things Network.

This codec is licensed under the GNU General Public License v3 (GPL v3). Modifications, if any, are clearly marked. You are free to use, modify, and distribute the codec under the terms of GPL v3.

Community Feedback