Need Help?
Payload Formatter for Dingtek DC200 to AlphaX (TTN)
function decodeUplink(input) {
var data = [input.bytes[8],input.bytes[7]];
// Convert to 16-bit integer
let value = (data[0] << 8) | data[1]; // Extract the 4-bit states let parkStatus = (value & 0xF000) >> 12;
let ultraStatus = (value & 0x0F00) >> 8;
let magStatus = (value & 0x00F0) >> 4;
let powerStatus = value & 0x000F;
return {
data: [
//Header Part
//{ channelId: "PacketHead", value: (input.bytes[0])},
//{ channelId: "ForcedBit", value: (input.bytes[1])},
//{ channelId: "DeviceType", value: (input.bytes[2])},
//{ channelId: "ReportType", value: (input.bytes[3])},
//{ channelId: "PacketSize", value: (input.bytes[4])},
//Data Part
{ channelId: 1, value: (input.bytes[6] | input.bytes[5] << 8)}, //height
{ channelId: 2, value: parkStatus }, //ParkingStatus
{ channelId: 3, value: ultraStatus }, //Ultrasonic Status
{ channelId: 4, value: magStatus }, //Mag Status
{ channelId: 5, value: powerStatus }, //Power Status
{ channelId: 6, value: (input.bytes[12] | input.bytes[11] << 8)}, //Mag X
{ channelId: 7, value: (input.bytes[14] | input.bytes[13] << 8)}, //Mag Y
{ channelId: 8, value: (input.bytes[16] | input.bytes[15] << 8)}, //Mag Z
{ channelId: 9, value: (input.bytes[18] | input.bytes[17] << 8)}, //Frame Counter
{ channelId: 255, value: (input.bytes[10] | input.bytes[9] << 8)/100}, //Battery
//tail Part
//{ channelId: "reserved", value: (input.bytes[19])},
//{ channelId: "packetTail", value: (input.bytes[20])},
],
warnings: [],
errors: [] }
}