Hi, I´m new with this things. We are testing a distance sensor but I have trouble with the data that we received.
Sometimes I get this message: ¨Exception generated by quickjs: interrupted¨
Also, sometimes I receive this message: * “Uplink was flagged as re-transmission / frame-counter did not increment”
How can I solve this problems?
This is the codec
/**
* Payload Decoder for Chirpstack and Milesight network server
*
* Copyright 2023 Milesight IoT
*
* @product EM400-UDL
*/
function decodeUplink({fPort, bytes}) {
var decoded= {data:{},
};
for (var i = 0; i < bytes.length; ) {
var channel_id = bytes[i++];
var channel_type = bytes[i++];
// BATTERY
if (channel_id === 0x01 && channel_type === 0x75) {
decoded.data.battery = bytes[i];
i += 1;
}
// TEMPERATURE
else if (channel_id === 0x03 && channel_type === 0x67) {
decoded.data.temperature = readInt16LE(bytes.slice(i, i + 2)) / 10;
i += 2;
}
// DISTANCE
else if (channel_id === 0x04 && channel_type === 0x82) {
decoded.data.distance = readUInt16LE(bytes.slice(i, i + 2));
i += 2;
}
// POSITION
else if (channel_id === 0x05 && channel_type === 0x00) {
decoded.data.position = bytes[i] === 0 ? "normal" : "tilt";
i += 1;
}
// TEMPERATURE WITH ABNORMAL
else if (channel_id === 0x83 && channel_type === 0x67) {
decoded.data.temperature = readInt16LE(bytes.slice(i, i + 2)) / 10;
decoded.data.temperature_abnormal = bytes[i + 2] == 0 ? false : true;
i += 3;
}
// DISTANCE WITH ALARMING
else if (channel_id === 0x84 && channel_type === 0x82) {
decoded.data.distance = readUInt16LE(bytes.slice(i, i + 2));
decoded.data.distance_alarming = bytes[i + 2] == 0 ? false : true;
i += 3;
} else {
break;
}
}
return decoded;
}
/* ******************************************
* bytes to number
********************************************/
function readUInt16LE(bytes) {
var value = (bytes[1] << 8) + bytes[0];
return value & 0xffff;
}
function readInt16LE(bytes) {
var ref = readUInt16LE(bytes);
return ref > 0x7fff ? ref - 0x10000 : ref;
}