Multitech
Creation procedure
Import steps
Payload Management → Sensor Definitions → Import Manufacturer: MClimate Sensor Type: XX XX - the specific name of the sensor you are currently importing
Select both files:
mclimate-aqi-codec.jsmclimate-aqi-definition.json
Click Import, then Save & Apply – the gateway will create read-only Input objects for telemetry and writable Value objects for every
"downlink": trueproperty.
Take note the example file below ends with 2 lines, that are the "decoder", "encoder" variable names. These are an example and need to match the names you have given them when actually importing them in the Multitech Gateway.
In order for the BACnet integration to work, you would need to import both the code below for the Codec file (in the form of a JS file) and the code for the Definition file after it (in the form of a JSON file).
Multitech BACnet Codec file
// DataCake
function Decoder(bytes, port){
var decoded = decodeUplink({ bytes: bytes, fPort: port }).data;
return decoded;
}
// Milesight
function Decode(port, bytes){
var decoded = decodeUplink({ bytes: bytes, fPort: port }).data;
return decoded;
}
// The Things Industries / Main
function decodeUplink(input) {
try{
var bytes = input.bytes;
var data = {};
function toBool(value){
return value == '1';
}
function calculateTemperature(rawData){
return (rawData - 400) / 10;
}
function calculateHumidity(rawData){
return (rawData * 100) / 256;
}
function handleKeepalive(bytes, data) {
// Temperature calculation from two bytes
var temperatureRaw = (bytes[1] << 8) | bytes[2]; // Shift byte[1] left by 8 bits and OR with byte[2]
data.sensorTemperature = Number(calculateTemperature(temperatureRaw).toFixed(2));
// Humidity calculation
data.relativeHumidity = Number(calculateHumidity(bytes[3]).toFixed(2));
// Battery voltage calculation from two bytes
var batteryVoltageRaw = (bytes[4] << 8) | bytes[5];
data.batteryVoltage = Number((batteryVoltageRaw / 1000).toFixed(2));
// CO2 calculation from bytes 6 and 7
var co2Low = bytes[6]; // Lower byte of CO2
var co2High = (bytes[7] & 0xF8) >> 3; // Mask the upper 5 bits and shift them right
data.CO2 = (co2High << 8) | co2Low; // Shift co2High left by 8 bits and combine with co2Low
// Power source status
data.powerSourceStatus = bytes[7] & 0x07; // Extract the last 3 bits directly
// Light intensity from two bytes
var lightIntensityRaw = (bytes[8] << 8) | bytes[9];
data.lux = lightIntensityRaw;
return data;
}
function handleResponse(bytes, data){
var commands = bytes.map(function(byte){
return ("0" + byte.toString(16)).substr(-2);
});
commands = commands.slice(0,-8);
var command_len = 0;
commands.map(function (command, i) {
switch (command) {
case '04':
{
command_len = 2;
var hardwareVersion = commands[i + 1];
var softwareVersion = commands[i + 2];
data.deviceVersions = { hardware: Number(hardwareVersion), software: Number(softwareVersion) };
}
break;
case '12':
{
command_len = 1;
data.keepAliveTime = parseInt(commands[i + 1], 16);
}
break;
case '14':
{
command_len = 1;
data.childLock = toBool(parseInt(commands[i + 1], 16)) ;
}
break;
case '19':
{
command_len = 1;
var commandResponse = parseInt(commands[i + 1], 16);
var periodInMinutes = commandResponse * 5 / 60;
data.joinRetryPeriod = periodInMinutes;
}
break;
case '1b':
{
command_len = 1;
data.uplinkType = parseInt(commands[i + 1], 16) ;
}
break;
case '1f':
{
command_len = 4;
var good_medium = (parseInt(commands[i + 1], 16) << 8) |
parseInt(commands[i + 2], 16);
var medium_bad = (parseInt(commands[i + 3], 16) << 8) |
parseInt(commands[i + 4], 16);
data.boundaryLevels = { good_medium: Number(good_medium), medium_bad: Number(medium_bad) } ;
}
break;
case '1d':
{
command_len = 2;
var deviceKeepAlive = 5;
var wdpC = commands[i + 1] == '00' ? false : commands[i + 1] * deviceKeepAlive + 7;
var wdpUc = commands[i + 2] == '00' ? false : parseInt(commands[i + 2], 16);
data.watchDogParams= { wdpC: wdpC, wdpUc: wdpUc } ;
}
break;
case '21':
{
command_len = 2;
data.autoZeroValue = (parseInt(commands[i + 1], 16) << 8) |
parseInt(commands[i + 2], 16);
}
break;
case '25':
{
command_len = 3;
var good_zone = parseInt(commands[i + 1], 16);
var medium_zone = parseInt(commands[i + 2], 16);
var bad_zone = parseInt(commands[i + 3], 16);
data.measurementPeriod = { good_zone: Number(good_zone), medium_zone: Number(medium_zone), bad_zone: Number(bad_zone) } ;
}
break;
case '2b':
{
command_len = 1;
data.autoZeroPeriod = parseInt(commands[i + 1], 16);
}
break;
case '34':
{
command_len = 1;
data.displayRefreshPeriod = parseInt(commands[i + 1], 16) ;
}
break;
case '41':
{
command_len = 1;
data.currentTemperatureVisibility = parseInt(commands[i + 1], 16) ;
}
break;
case '43':
{
command_len = 1;
data.humidityVisibility = parseInt(commands[i + 1], 16) ;
}
break;
case '45':
{
command_len = 1;
data.lightIntensityVisibility = parseInt(commands[i + 1], 16) ;
}
break;
case '80':
{
command_len = 1;
data.measurementBlindTime = parseInt(commands[i + 1], 16) ;
}
break;
case 'a0': {
command_len = 4;
var fuota_address = (parseInt(commands[i + 1], 16) << 24) |
(parseInt(commands[i + 2], 16) << 16) |
(parseInt(commands[i + 3], 16) << 8) |
parseInt(commands[i + 4], 16);
var fuota_address_raw = commands[i + 1] + commands[i + 2] +
commands[i + 3] + commands[i + 4];
data.fuota = { fuota_address: fuota_address, fuota_address_raw: fuota_address_raw };
break;
}
default:
break;
}
commands.splice(i,command_len);
});
return data;
}
if (bytes[0] == 1) {
data = handleKeepalive(bytes, data);
}else{
data = handleResponse(bytes,data);
bytes = bytes.slice(-10);
data = handleKeepalive(bytes, data);
}
return {data: data};
} catch (e) {
console.log(e)
throw new Error('Unhandled data');
}
}Multitech BACnet Definition file
{
"description": "MClimate CO2 Display Lite (CO2 Display Lite) – BACnet mapping",
"properties": {
"sensorTemperature" : { "type": "float", "units": "celsius" },
"relativeHumidity" : { "type": "float", "units": "%" },
"batteryVoltage" : { "type": "float", "units": "V" },
"CO2" : { "type": "uint16", "units": "ppm" },
"powerSourceStatus" : { "type": "uint8" },
"lux" : { "type": "uint16", "units": "lx" },
"deviceVersions" : { "type": "object" },
"keepAliveTime" : { "type": "uint8", "units": "minutes" },
"childLock" : { "type": "bool" },
"joinRetryPeriod" : { "type": "float", "units": "minutes" },
"uplinkType" : { "type": "uint8" },
"boundaryLevels" : { "type": "object" },
"watchDogParams" : { "type": "object" },
"autoZeroValue" : { "type": "uint16" },
"measurementPeriod" : { "type": "object" },
"autoZeroPeriod" : { "type": "uint8", "units": "days" },
"displayRefreshPeriod" : { "type": "uint8", "units": "minutes" },
"currentTemperatureVisibility":{ "type": "uint8" },
"humidityVisibility" : { "type": "uint8" },
"lightIntensityVisibility" : { "type": "uint8" },
"measurementBlindTime" : { "type": "uint8", "units": "minutes" },
"fuota" : { "type": "object" },
"setKeepAlive" : { "type": "uint8", "units": "minutes", "downlink": true },
"setChildLock" : { "type": "bool", "downlink": true },
"setJoinRetryPeriod" : { "type": "float", "units": "minutes", "downlink": true },
"setUplinkType" : { "type": "uint8", "downlink": true },
"setBoundaryLevels" : { "type": "object", "downlink": true },
"setWatchDogParams" : { "type": "object", "downlink": true },
"setAutoZeroValue" : { "type": "uint16", "downlink": true },
"setMeasurementPeriod" : { "type": "object", "downlink": true },
"setAutoZeroPeriod" : { "type": "uint8", "units": "days", "downlink": true },
"setDisplayRefreshPeriod" : { "type": "uint8", "units": "minutes", "downlink": true },
"setCurrentTemperatureVisibility": { "type": "uint8", "downlink": true },
"setHumidityVisibility" : { "type": "uint8", "downlink": true },
"setLightIntensityVisibility": { "type": "uint8", "downlink": true },
"setMeasurementBlindTime" : { "type": "uint8", "units": "minutes", "downlink": true },
"sendCustomHexCommand" : { "type": "string", "downlink": true }
},
"decoder": "mclimate-c02-display-lite-codec.js",
"encoder": "mclimate-c02-display-lite-codec.js"
}Last updated
Was this helpful?