@crapougnax! This is my driver decoder for a sensor which cayenne lpp format. I want to use your library in my driver. Initially tried only for temperature but was not able to achieve it. My payload is received in Base-64 and i’m converting it into hex string to use at certain places, and returning the values. How should I integrate your library here.
var hexpayload = '';
function decode(payload, port) {
var result = new Object();
// Convert received payload (Base-64) into hex payload //
Object.keys(payload).forEach(function(key) {
thishex = Number(payload[key]).toString(16);
thishex = thishex.length < 2 ? "" + "0" + thishex : thishex;
hexpayload += thishex;
});
result.RawPayload = hexpayload;
if (payload[0] == 1) {
result.PayloadTtype = 'Recalibrate Response'; // dataType 1 //
result.Status = (payload[2] == 0) ? 'Failed' : 'Successful';
} else if (payload[0] == 2) {
result.PayloadTtype = 'Temperature'; // dataType 103 //
result.Value = (parseInt(hexpayload.slice(4), 16).toString(10)) / 10 + 'C';
} else if (payload[0] == 3) {
result.PayloadTtype = 'Battery'; // dataType 2 //
result.Battery = (parseInt(hexpayload.slice(4), 16).toString(10)) / 100 + 'V';
} else if (payload[0] == 21) {
result.PayloadTtype = 'Parking Status'; // dataType 102 //
result.ParkingStatus = (payload[2] == 0) ? 'Occupied' : 'Vacant';
} else if (payload[0] == 28) {
result.PayloadTtype = 'Deactivate Response'; //dataType 1 //
result.ParkingStatus = (payload[2] == 0) ? 'Not Done' : 'Done';
} else if (payload[0] == 33) {
result.PayloadTtype = 'Vehicle Count'; // dataType 0 //
if (payload[2] > 80) {
payload[2] %= 80; //Sensor Reboot due to exceeding limit
result.Count = payload[2];
} else {
result.Count = payload[2];
}
}else {
result.PayloadTtype = 'Invalid-Payload';
}
return {
"result": result,
"port": port
}
}