⬇️MClimate HT + PIR Lite Downlink encoder
Universal Encoder:
Supports: The Thinks Network, Milesight
// Milesight
function Encode(port, obj) {
var encoded = encodeDownlink({ fPort: port, data: obj }).bytes;
return encoded;
}
function Encoder(port, obj) {
var encoded = encodeDownlink({ fPort: port, data: obj }).bytes;
return encoded;
}
// The Things Industries / Main
function encodeDownlink(input) {
var bytes = [];
for (key in input.data) {
switch (key) {
case "setKeepAlive": {
bytes.push(0x02);
bytes.push(input.data.setKeepAlive);
break;
}
case "getKeepAliveTime": {
bytes.push(0x12);
break;
}
case "getDeviceVersions": {
bytes.push(0x04);
break;
}
case "setJoinRetryPeriod": {
var periodToPass = (input.data.setJoinRetryPeriod * 60) / 5;
periodToPass = int(periodToPass);
bytes.push(0x10);
bytes.push(periodToPass);
break;
}
case "getJoinRetryPeriod": {
bytes.push(0x19);
break;
}
case "setUplinkType": {
bytes.push(0x11);
bytes.push(input.data.setUplinkType);
break;
}
case "getUplinkType": {
bytes.push(0x1B);
break;
}
case "setWatchDogParams": {
bytes.push(0x1C);
bytes.push(input.data.SetWatchDogParams.confirmedUplinks);
bytes.push(input.data.SetWatchDogParams.unconfirmedUplinks);
break;
}
case "getWatchDogParams": {
bytes.push(0x1D);
break;
}
case "setUplinkSendingOnButtonPress": {
bytes.push(0x2E);
bytes.push(input.data.setUplinkSendingOnButtonPress);
break;
}
case "getUplinkSendingOnButtonPress": {
bytes.push(0x2F);
break;
}
case "setPIRSensorStatus": {
bytes.push(0x3C);
bytes.push(input.data.setPIRSensorStatus);
break;
}
case "getPIRSensorStatus": {
bytes.push(0x3D);
break;
}
case "setPIRSensorSensitivity": {
bytes.push(0x3E);
bytes.push(input.data.setPIRSensorSensitivity);
break;
}
case "getPIRSensorSensitivity": {
bytes.push(0x3F);
break;
}
case "setPIRMeasurementPeriod": {
bytes.push(0x48);
bytes.push(input.data.setPIRMeasurementPeriod);
break;
}
case "getPIRMeasurementPeriod": {
bytes.push(0x49);
break;
}
case "setPIRCheckPeriod": {
var time = input.data.setPIRCheckPeriod;
var timeFirstPart = time & 0xff;
var timeSecondPart = (time >> 8) & 0xff;
bytes.push(0x4A);
bytes.push(timeSecondPart);
bytes.push(timeFirstPart);
break;
}
case "getPIRCheckPeriod": {
bytes.push(0x4B);
break;
}
case "setPIRBlindPeriod": {
var time = input.data.setPIRBlindPeriod;
var timeFirstPart = time & 0xff;
var timeSecondPart = (time >> 8) & 0xff;
bytes.push(0x4C);
bytes.push(timeSecondPart);
bytes.push(timeFirstPart);
break;
}
case "getPIRBlindPeriod": {
bytes.push(0x4D);
break;
}
case "sendCustomHexCommand": {
var sendCustomHexCommand = input.data.sendCustomHexCommand;
for (var i = 0; i < sendCustomHexCommand.length; i += 2) {
var byte = parseInt(sendCustomHexCommand.substr(i, 2), 16);
bytes.push(byte);
}
break;
}
default: {
}
}
}
return {
bytes: bytes,
fPort: 1,
warnings: [],
errors: [],
};
}
function decodeDownlink(input) {
return {
data: {
bytes: input.bytes,
},
warnings: [],
errors: [],
};
}
// example downlink commands
// {"setPIRBlindPeriod":20} --> 0x4C0014
// {"sendCustomHexCommand":"080F15"} --> 0x080F15
Last updated
Was this helpful?