In this article
Categories

Milesight EM-310-UDL payloads on N2N DL for AlphaX

Print

Example fixed length LoRaWAN payload formatter for Milesight EM-310-UDL on N2N DL console

Decoder Example
function parseDeviceMsg(buf:Buffer, loraMsg:LoraMessage):ParserReading[] {

let dynamic = [];

for (var i = 0; i < parseInt(buf.length);) {
var channel_id = buf.readUInt8(i++);
var channel_type = buf.readUInt8(i++);

// BATTERY
if (channel_id === 0x01 && channel_type === 0x75) {
//decoded.battery = buff[i];
dynamic.push({channelId: 255, value:buf.readUInt8(i)});
i += 1;
}

// DISTANCE
else if (channel_id === 0x03 && channel_type === 0x82) {
//decoded.distance = readUInt16LE(bytes.slice(i, i + 2));
dynamic.push({channelId: 1, value:buf.readUInt16LE(i)});
i += 2;
}

// POSITION
else if (channel_id === 0x04 && channel_type === 0x00) {
//decoded.position = bytes[i] === 0 ? “normal” : “tilt”;
dynamic.push({channelId: 2, value:(buf.readUInt8(i) === 0 ? 0 : 1)});
i += 1;
} else {
//dynamic.push({channelId: 5, value:5});
break;
}
}

return dynamic;
}