GWF Kamstrup Multical 603
Last updated
Last updated
// Decode an uplink message from a buffer
// payload - array of bytes
// metadata - key/value object
var medium_table = {
"Gas": "03",
"Electricity": "02",
"Heat: Outlet": "04",
"Heat: Inlet": "0C",
"Water": "07",
"Cold water": "16",
"Other": "00",
"Warm water (30-90ðC)": "06",
};
var deviceLib = [
{
Manufacturer: 'AMT',
Version: 192,
Medium: 'Heat: Outlet',
ProductName: 'Aquametro CALEC ST',
type: 'Aquametro CALEC ST',
Records: [
{
id: 0,
Unit: "Energy (kWh)",
name: 'heatMeterEnergy',
scale: 1,
},
{
id: 1,
Unit: "Volume (1e-1 m^3)",
name: 'waterMeter',
scale: 0.1,
},
{
id: 5,
Unit: "Volume flow (m m^3/h)",
name: 'flowRate',
scale: 1,
},
{
id: 4,
Unit: "Power (W)",
name: 'power',
scale: 1,
},
{
id: 6,
Unit: "Flow temperature (deg C)",
name: 'flowTemperature',
scale: 1,
},
{
id: 7,
Unit: "Return temperature (deg C)",
name: 'returnFlowTemperature',
scale: 1,
}
]
},
{
Manufacturer: 'TCH',
Version: 67,
Medium: 'Heat: Outlet',
ProductName: '',
type: 'TCH Heat Meter 67',
Records: [
{
id: 0,
Unit: "Energy (100 Wh)",
name: 'heatMeterEnergy',
scale: 100,
},
{
id: 1,
Unit: "Volume (m m^3)",
name: 'waterMeter',
scale: 1,
},
{
id: 2,
Unit: "Volume flow (m m^3/h)",
name: 'flowRate',
scale: 1,
},
{
id: 3,
Unit: "Power (W)",
name: 'power',
scale: 1,
},
{
id: 4,
Unit: "Flow temperature (1e-1 deg C)",
name: 'flowTemperature',
scale: 0.1,
},
{
id: 5,
Unit: "Return temperature (1e-1 deg C)",
name: 'returnFlowTemperature',
scale: 0.1,
}
]
},
{
Manufacturer: 'TCH',
Version: 48,
Medium: 'Heat: Outlet',
ProductName: '',
type: 'TCH Heat Meter 48',
Records: [
{
id: 1,
Unit: "Energy (10 kWh)",
name: 'heatMeterEnergy',
scale: 10000,
},
{
id: 2,
Unit: "Volume (1e-2 m^3)",
name: 'waterMeter',
scale: 0.01,
},
{
id: 3,
Unit: "Volume flow (m m^3/h)",
name: 'flowRate',
scale: 1,
},
{
id: 4,
Unit: "Power (W)",
name: 'power',
scale: 1,
},
{
id: 5,
Unit: "Flow temperature (1e-1 deg C)",
name: 'flowTemperature',
scale: 0.1,
},
{
id: 6,
Unit: "Return temperature (1e-1 deg C)",
name: 'returnFlowTemperature',
scale: 0.1,
}
]
},
{
Manufacturer: 'TCH',
Version: 37,
Medium: 'Heat: Outlet',
ProductName: '',
type: 'TCH Heat Meter 37',
Records: [
{
id: 0,
Unit: "Energy (100 Wh)",
name: 'heatMeterEnergy',
scale: 10,
},
{
id: 7,
Unit: "Volume (m m^3)",
name: 'waterMeter',
scale: 1,
},
{
id: 3,
Unit: "Volume flow (m m^3/h)",
name: 'flowRate',
scale: 1,
},
{
id: 6,
Unit: "Power (W)",
name: 'power',
scale: 1,
},
{
id: 4,
Unit: "Return temperature (deg C)",
name: 'returnFlowTemperature',
scale: 1,
}
]
},
{
Manufacturer: 'GWF',
Version: 60,
Medium: 'Water',
ProductName: '',
type: 'GWF Water Meter 60',
Records: [
{
id: 1,
Unit: "Volume (m m^3)",
name: 'waterMeter',
scale: 0.001,
}
]
},
{
Manufacturer: 'FIN',
Version: 54,
Medium: 'Electricity',
ProductName: '',
type: 'FIN 54 Electricity Meter',
Records: [
{
id: 1,
Unit: "Energy (10 Wh)",
name: 'electricityMeterEnergy',
scale: 10,
},
{
id: 17,
Unit: "Power (10 W)",
name: 'power',
scale: 10,
},
{
id: 18,
Unit: "Power (10 W)",
name: 'reactivePower',
scale: 10,
}
]
},
{
Manufacturer: 'GWF',
Version: 60,
Medium: 'Warm water (30-90ðC)',
ProductName: '',
type: 'GWF Warm Water Meter 60',
Records: [
{
id: 1,
Unit: "Volume (m m^3)",
name: 'waterMeter',
scale: 0.001,
}
]
},
{
Manufacturer: 'KAM',
Version: 52,
Medium: 'Heat: Outlet',
ProductName: '',
type: 'KAM Heat Meter 52',
Records: [
{
id: 0,
Unit: "Energy (10 kWh)",
name: 'heatMeterEnergy',
scale: 10000,
},
{
id: 3,
Unit: "Volume (1e-1 m^3)",
name: 'waterMeter',
scale: 0.1,
},
{
id: 13,
Unit: "Volume flow (m m^3/h)",
name: 'flowRate',
scale: 1,
},
{
id: 11,
Unit: "Power (100 W)",
name: 'power',
scale: 100,
},
{
id: 8,
Unit: "Flow temperature (1e-2 deg C)",
name: 'flowTemperature',
scale: 0.01,
},
{
id: 9,
Unit: "Return temperature (1e-2 deg C)",
name: 'returnFlowTemperature',
scale: 0.01,
}
]
},
{
Manufacturer: 'KAM',
Version: 11,
Medium: 'Heat: Outlet',
ProductName: '',
type: 'KAM Heat Meter 11',
Records: [
{
id: 1,
Unit: "Energy (10 kWh)",
name: 'heatMeterEnergy',
scale: 10000,
},
{
id: 2,
Unit: "Volume (1e-1 m^3)",
name: 'waterMeter',
scale: 0.1,
},
{
id: 9,
Unit: "Volume flow (m m^3/h)",
name: 'flowRate',
scale: 1,
},
{
id: 7,
Unit: "Power (100 W)",
name: 'power',
scale: 100,
},
{
id: 4,
Unit: "Flow temperature (1e-2 deg C)",
name: 'flowTemperature',
scale: 0.01,
},
{
id: 5,
Unit: "Return temperature (1e-2 deg C)",
name: 'returnFlowTemperature',
scale: 0.01,
}
]
},
{
Manufacturer: 'KAM',
Version: 17,
Medium: 'Heat: Outlet',
ProductName: '',
type: 'KAM Heat Meter 17',
Records: [
{
id: 1,
Unit: "Energy (kWh)",
name: 'heatMeterEnergy',
scale: 1000,
},
{
id: 2,
Unit: "Volume (1e-2 m^3)",
name: 'waterMeter',
scale: 0.01,
},
{
id: 2,
Unit: "Volume flow (m m^3/h)",
name: 'flowRate',
scale: 1,
},
{
id: 7,
Unit: "Power (100 W)",
name: 'power',
scale: 100,
},
{
id: 4,
Unit: "Flow temperature (1e-2 deg C)",
name: 'flowTemperature',
scale: 0.01,
},
{
id: 5,
Unit: "Return temperature (1e-2 deg C)",
name: 'returnFlowTemperature',
scale: 0.01,
}
]
},
{
Manufacturer: 'REL',
Version: 65,
Medium: 'Electricity',
ProductName: '',
type: 'REL Electricity Meter 65',
Records: [
{
id: 0,
Unit: "Energy (kWh)",
name: 'electricityMeterEnergy',
scale: 1000,
}
]
},
{
Manufacturer: 'WZG',
Version: 3,
Medium: 'Cold water',
ProductName: '',
type: 'WZG Water Meter',
Records: [
{
id: 0,
Unit: "Volume (m m^3)",
name: 'waterMeter',
scale: 0.001,
}
]
},
{
Manufacturer: 'GWF',
Version: 60,
Medium: 'Gas',
ProductName: '',
type: 'GWF Gas Meter 60',
Records: [
{
id: 1,
Unit: "Volume (m m^3)",
name: 'gasMeterVolume',
scale: 1,
}
]
},
{
Manufacturer: 'ACW',
Version: 20,
Medium: 'Gas',
ProductName: 'Itron CYBLE M-Bus 1.4',
type: 'Itron CYBLE M-Bus 1.4',
Records: [
{
id: 4,
Unit: "Volume (1e-1 m^3)",
name: 'gasMeterVolume',
scale: 0.1,
}
]
},
{
Manufacturer: 'ACW',
Version: 9,
Medium: 'Heat: Outlet',
ProductName: 'Itron CF Echo 2',
type: 'Itron CF Echo 2',
Records: [
{
id: 1,
Unit: "Energy (10 kWh)",
name: 'heatMeterEnergy',
scale: 10000,
},
{
id: 2,
Unit: "Volume (1e-1 m^3)",
name: 'waterMeter',
scale: 0.1,
},
{
id: 3,
Unit: "Power (100 W)",
name: 'power',
scale: 100,
},
{
id: 4,
Unit: "Volume flow (m m^3/h)",
name: 'flowRate',
scale: 1,
},
{
id: 5,
Unit: "Flow temperature (1e-1 deg C)",
name: 'flowTemperature',
scale: 0.1,
},
{
id: 6,
Unit: "Return temperature (1e-1 deg C)",
name: 'returnFlowTemperature',
scale: 0.1,
},
{
id: 7,
Unit: "Temperature Difference (1e-2 deg C)",
name: 'deltaT',
scale: 0.01,
},
]
},
{
Manufacturer: 'GWF',
Version: 54,
Medium: 'Gas',
ProductName: '',
type: 'GWF Gas Meter 54',
Records: [
{
id: 1,
Unit: "Volume (1e-2 m^3)",
name: 'gasMeterVolume',
scale: 0.01,
}
]
},
{
Manufacturer: 'REL',
Version: 66,
Medium: 'Gas',
ProductName: '',
type: 'REL Gas Meter 66',
Records: [
{
id: 0,
Unit: "Volume ( m^3)",
name: 'gasMeterVolume',
scale: 1,
}
]
},
{
Manufacturer: 'SON',
Version: 14,
"Medium": "Heat: Inlet",
ProductName: '',
type: 'SON Heat Meter 14',
Records: [
{
id: 3,
Unit: "Energy (kWh)",
name: 'heatMeterEnergy',
scale: 1000,
},
{
id: 4,
Unit: "Volume (1e-1 m^3)",
name: 'waterMeter',
scale: 1,
},
{
id: 4,
Unit: "Volume (1e-2 m^3)",
name: 'waterMeter',
scale: 0.01,
},
{
id: 4,
Unit: "Volume (1e-1 m^3)",
name: 'waterMeter',
scale: 0.1,
},
{
id: 5,
Unit: "Flow temperature (deg C)",
name: 'flowTemperature',
scale: 1,
},
{
id: 6,
Unit: "Return temperature (deg C)",
name: 'returnFlowTemperature',
scale: 1,
},
{
id: 7,
Unit: "Volume flow ( m^3/h)",
name: 'flowRate',
scale: 1,
},
{
id: 8,
Unit: "Power (W)",
name: 'power',
scale: 0.001,
},
]
},
{
Manufacturer: 'SON',
Version: 14,
Medium: 'Heat: Outlet',
ProductName: '',
type: 'SON Heat Meter 14',
Records: [
{
id: 3,
Unit: "Energy (kWh)",
name: 'heatMeterEnergy',
scale: 1000,
},
{
id: 4,
Unit: "Volume (m m^3)",
name: 'waterMeter',
scale: 1,
},
{
id: 4,
Unit: "Volume (1e-2 m^3)",
name: 'waterMeter',
scale: 0.01,
},
{
id: 4,
Unit: "Volume (1e-1 m^3)",
name: 'waterMeter',
scale: 0.1,
},
{
id: 5,
Unit: "Flow temperature (deg C)",
name: 'flowTemperature',
scale: 1,
},
{
id: 6,
Unit: "Return temperature (deg C)",
name: 'returnFlowTemperature',
scale: 1,
},
{
id: 7,
Unit: "Volume flow ( m^3/h)",
name: 'flowRate',
scale: 1,
},
{
id: 8,
Unit: "Power (W)",
name: 'power',
scale: 0.001,
},
]
},{
Manufacturer: 'SON',
Version: 13,
Medium: 'Heat: Outlet',
ProductName: 'Sontex Supercal 531',
type: 'SON Heat Meter 13',
Records: [
{
id: 3,
Unit: "Energy (kWh)",
name: 'heatMeterEnergy',
scale: 1000,
},
{
id: 4,
Unit: "Volume (1e-1 m^3)",
name: 'waterMeter',
scale: 0.1,
},
{
id: 5,
Unit: "Flow temperature (deg C)",
name: 'flowTemperature',
scale: 1,
},
{
id: 6,
Unit: "Return temperature (deg C)",
name: 'returnFlowTemperature',
scale: 1,
},
{
id: 7,
Unit: "Volume flow ( m^3/h)",
name: 'flowRate',
scale: 1,
},
{
id: 8,
Unit: "Power (W)",
name: 'power',
scale: 0.001,
},
]
},
{
Manufacturer: 'SON',
Version: 13,
Medium: 'Heat: Outlet',
ProductName: 'Sontex Supercal 531',
type: 'SON Heat Meter 13',
Records: [
{
id: 3,
Unit: "Energy (kWh)",
name: 'heatMeterEnergy',
scale: 1000,
},
{
id: 4,
Unit: "Volume (1e-1 m^3)",
name: 'waterMeter',
scale: 0.1,
},
{
id: 5,
Unit: "Flow temperature (deg C)",
name: 'flowTemperature',
scale: 1,
},
{
id: 6,
Unit: "Return temperature (deg C)",
name: 'returnFlowTemperature',
scale: 1,
},
{
id: 7,
Unit: "Volume flow ( m^3/h)",
name: 'flowRate',
scale: 1,
},
{
id: 8,
Unit: "Power (W)",
name: 'power',
scale: 0.001,
},
]
},
{
Manufacturer: 'AMT',
Version: 192,
Medium: 'Head: Outlet',
ProductName: 'Aquametro CALEC ST',
type: 'Aquametro CALEC ST',
Records: [
{
id: 0,
Unit: "Energy (kWh)",
name: 'heatMeterEnergy',
scale: 1000,
},
{
id: 1,
Unit: "Volume (1e-1 m^3)",
name: 'waterMeter',
scale: 0.1,
},
{
id: 6,
Unit: "Flow temperature (deg C)",
name: 'flowTemperature',
scale: 1,
},
{
id: 7,
Unit: "Return temperature (deg C)",
name: 'returnFlowTemperature',
scale: 1,
},
{
id: 5,
Unit: "Volume flow (m m^3/h)",
name: 'flowRate',
scale: 1,
},
{
id: 4,
Unit: "Power (W)",
name: 'power',
scale: 0.001,
},
]
},
{
Manufacturer: 'AMT',
Version: 209,
Medium: 'Unknown Medium',
ProductName: 'Aquametro CALEC ST',
type: 'Aquametro CALEC ST',
Records: [
{
id: 0,
Unit: "Volume (1e-2 m^3)",
name: 'waterMeter',
scale: 0.01,
},
{
id: 1,
Unit: "Volume flow (m m^3/h)",
name: 'flowRate',
scale: 1,
},
]
},
{
Manufacturer: 'JAN',
Version: 9,
Medium: 'Electricity',
ProductName: 'Janitza UMG 96S',
type: 'Janitza UMG 96S',
Records: [
{
id: 0,
Unit: "Energy (10 Wh)",
name: 'electricityMeterEnergy',
scale: 10,
},
]
},
{
Manufacturer: 'WZG',
Version: 3,
Medium: 'Water',
ProductName: '',
type: 'WZG Water Meter 3',
Records: [
{
id: 0,
Unit: "Volume (m m^3)",
name: 'waterMeter',
scale: 0.001,
},
]
},
];
/** Decoder **/
// decode payload to string
//var payloadStr = decodeToString(payload);
// decode payload to JSON
//var data = decodeToJson(payload);
//var data = decodeToJson(msg);
var data = msg.hexValue;
function decodeToJson(payload) {
// covert payload to string.
//var str = decodeToString(payload);
// parse string to JSON
//var data = JSON.parse(str);
var data = JSON.parse(payload);
return data;
}
function decodeToString(payload) {
return String.fromCharCode.apply(String, payload);
}
//var deviceName = get_secondary_address(data.SlaveInformation);
var secondaryAddress = get_secondary_address(data.SlaveInformation);
var libIdx = findInLib(data.SlaveInformation);
var deviceType = 'Tesenso M-Bus';
//var deviceType = getDeviceType(libIdx);
//var groupName = 'M-Bus Slaves';
// Result object with device/asset attributes/telemetry data
var result = {
// Use deviceName and deviceType or assetName and assetType, but not both.
//groupName: groupName,
//telemetry: getTelemetry(libIdx, data.DataRecord, data.error),
//telemetry2: JSON.stringify(getTelemetry(libIdx, data.DataRecord, data.error)),
telemetry: JSON.parse(JSON.stringify(getTelemetry(libIdx, data.DataRecord, data.error)))
};
var msg2 = {
values: {},
}
var metadata = {
deviceName: secondaryAddress,
originatorName: secondaryAddress,
//deviceType: deviceType,
idx:libIdx,
Id: data.SlaveInformation.Id,
Manufacturer: data.SlaveInformation.Manufacturer,
version: data.SlaveInformation.Version,
ProductName: data.SlaveInformation.ProductName,
Medium: data.SlaveInformation.Medium,
GatewayMacAddress: data.GatewayMacAddress,
};
/** Helper functions **/
function findInLib(info) {
for (var i = 0; i < deviceLib.length; i++) {
if (
deviceLib[i].Manufacturer === info.Manufacturer &&
deviceLib[i].Version === info.Version &&
deviceLib[i].ProductName === info.ProductName &&
deviceLib[i].Medium === info.Medium
) {
return i;
}
}
return null
}
function getDeviceType(idx) {
var type = 'default'
if (idx != null) {
type = deviceLib[idx].type;
}
return type;
}
/*
function getTelemetry(idx, records, error) {
var decoded = []
if (idx != null) {
for (var i = 0; i < deviceLib[idx].Records.length; i++) {
libRecord = deviceLib[idx].Records[i];
for(var j=0; j<records.length; j++) {
readRecord = records[j];
if (libRecord.Unit === readRecord.Unit && libRecord.id === readRecord.id) {
var ts = new Date(readRecord.Timestamp).getTime();
var obj = {
ts: ts,
values: {}
}
obj.values[libRecord.name] = readRecord.Value*libRecord.scale;
decoded.push(obj)
}
}
}
}
//decoded.push({error: error});
return decoded
}*/
function getTelemetry(idx, records, error) {
var decoded = []
var decoded2 = {}
var msg3 = {
values:{}
}
if (idx != null) {
for (var i = 0; i < deviceLib[idx].Records.length; i++) {
var libRecord = deviceLib[idx].Records[i];
for(var j=0; j<records.length; j++) {
var readRecord = records[j];
if (libRecord.Unit === readRecord.Unit && libRecord.id === readRecord.id) {
//var ts = new Date(readRecord.Timestamp).getTime();
var ts = metadata.ts;
var obj = {
ts: ts,
values: {}
}
obj.values[libRecord.name] = readRecord.Value*libRecord.scale;
//decoded[values[libRecord.name]] = readRecord.Value*libRecord.scale;
msg3.values[libRecord.name] = readRecord.Value*libRecord.scale;
decoded.push(obj)
decoded2["value"+j]=obj
//msg2.values[libRecord.name] = readRecord.Value*libRecord.scale;
}
}
}
}
//decoded.push({error: error});
//return decoded
return msg3.values;
}
function manufacturer_encode(manufacturer) {
if (manufacturer.length != 3) {
return false
}
if (manufacturer.search(/[^A-Za-z\s]/) != -1) {
return false
}
manufacturer = manufacturer.toUpperCase()
var bytes = []
for(var i = 0; i < manufacturer.length; i++){
var code = manufacturer.charCodeAt(i);
bytes.push(code);
}
var id = ((bytes[0] - 64) * 32 * 32 +
(bytes[1] - 64) * 32 +
(bytes[2] - 64))
if (0x0421 <= id <= 0x6b5a)
return (pad((id & 0xFF).toString(16), 2) + pad(((id >> 8) & 0xFF).toString(16), 2)).toUpperCase()
return false
}
/*function get_secondary_address(info) {
var manufacturer = manufacturer_encode(info.Manufacturer)
var version = pad(info.Version.toString(16), 2, '0')
var sec = (info.Id.toString() + manufacturer + version + medium_table[info.Medium]).toUpperCase()
sec = pad(sec, 16, '0')
return sec
}*/
function get_secondary_address(info) {
var deviceEUI = metadata.deviceName;
return deviceEUI + "_" + info.Id;
}
function pad(n, width, z) {
z = z || '0';
n = n + '';
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
}
return {msg: result.telemetry, metadata: metadata, msgType: msgType};
//return result;