I’m using a decoder sent to me by the manufacturer, but I keep getting the follwoing error when I try to decode a packet
js vm error: (anonymous): Line 12:7 Unexpected identifier (and 16 more errors)
Can;t for the life of me work it out and not getting much response from the manufacturer. If anyone can help I’d be most grateful.
/********************************************
* Sontay LoRaWAN Packet Decoder script *
* v1.1 *
* *
* Compatible with Sontay LoRaWAN sensors *
********************************************/
function decodeUplink(input) {
let SENSOR_TEMP = (1 << 1);
let SENSOR_RH = (1 << 2);
let SENSOR_CO2 = (1 << 3);
let TOTAL_DATA_SLOTS = 4;
var data = {};
var slot = 0;
let sensors = (input.bytes[0] << 8) | (input.bytes[1] & 0xFE);
var vBat = ((input.bytes[1] & 0x01) << 8) | input.bytes[2];
data.Battery = vBat / 100;
if(vBat >= 330)
data.BatteryStatus = "Good";
else if(vBat < 300)
data.BatteryStatus = "Poor";
else
data.BatteryStatus = "OK";
for(let i = 1; i < 16; i++) {
var d = (input.bytes[3+(2*slot)] << 8) | (input.bytes[4+(2*slot)]);
if(d > 0x7FFF)
d -= 0xFFFF; // Correct for a negative value
switch(sensors & (1 << i)) {
case SENSOR_TEMP:
data.Temperature = d / 100;
break;
case SENSOR_RH:
data.Humidity = d / 10;
break;
case SENSOR_CO2:
data.CO2 = d;
break;
default:
continue;
}
if(++slot > TOTAL_DATA_SLOTS)
break;
}
return {
data,
warnings: [],
errors: []
};
}