M-Bus – Heat meter – Kamstrup MULTICAL 402
Info
MULTICAL 402 can be read from the clear LED display or remotely using a variety of communication methods including, wired and wireless M-Bus, radio and pulse output. This allows for scalable network solutions from handheld to full AMR. This ensures safe reading for export to billing packages, less labour costs, low installation costs and reading at any time. The meter has a user-friendly interface, which has a helpful set/re-set function that can easily be adjusted using the two front keys allowing various settings to be changed. Data loggers ensure that valuable data is stored allowing analysis of energy consumption and evidence of any problems such as pressure loss and tamper detection. With meter sizes up to DN50, MULTICAL 402 answers most sub-metering requirements. The mix of high accuracy ultrasonic measuring technology, common AMR options, data logger and up to 16 years battery lifetime makes MULTICAL 402 a very price competitive energy meter suited for almost any residential application.
Kamstrup MULTICAL 402 Technical Description
Uitlezen via Raspberry Pi (libmbus)
Hardware nodig: MBUS naar USB of RS232/TTL converter
Software nodig: libmbus
Boudrate: 2400
Adres: 68
Commando voor XML telegram:Â mbus-serial-request-data -b 2400 /dev/ttyUSB0 68
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
<?xml version="1.0" encoding="ISO-8859-1"?> <MBusData> <SlaveInformation> <Id>61537968</Id> <Manufacturer>KAM</Manufacturer> <Version>11</Version> <ProductName></ProductName> <Medium>Heat: Outlet</Medium> <AccessNumber>0</AccessNumber> <Status>10</Status> <Signature>0000</Signature> </SlaveInformation> <DataRecord id="0"> <Function>Instantaneous value</Function> <StorageNumber>0</StorageNumber> <Unit>Fabrication number</Unit> <Value>61537968</Value> <Timestamp>2015-05-29T13:43:51</Timestamp> </DataRecord> <DataRecord id="1"> <Function>Instantaneous value</Function> <StorageNumber>0</StorageNumber> <Unit>Energy (kWh)</Unit> <Value>10</Value> <Timestamp>2015-05-29T13:43:51</Timestamp> </DataRecord> <DataRecord id="2"> <Function>Instantaneous value</Function> <StorageNumber>0</StorageNumber> <Unit>Volume (1e-2 m^3)</Unit> <Value>272</Value> <Timestamp>2015-05-29T13:43:51</Timestamp> </DataRecord> <DataRecord id="3"> <Function>Instantaneous value</Function> <StorageNumber>0</StorageNumber> <Unit>On time (hours)</Unit> <Value>2424</Value> <Timestamp>2015-05-29T13:43:51</Timestamp> </DataRecord> <DataRecord id="4"> <Function>Instantaneous value</Function> <StorageNumber>0</StorageNumber> <Unit>Flow temperature (1e-2 deg C)</Unit> <Value>1846</Value> <Timestamp>2015-05-29T13:43:51</Timestamp> </DataRecord> <DataRecord id="5"> <Function>Instantaneous value</Function> <StorageNumber>0</StorageNumber> <Unit>Return temperature (1e-2 deg C)</Unit> <Value>1838</Value> <Timestamp>2015-05-29T13:43:51</Timestamp> </DataRecord> <DataRecord id="6"> <Function>Instantaneous value</Function> <StorageNumber>0</StorageNumber> <Unit>Temperature Difference (1e-2 deg C)</Unit> <Value>8</Value> <Timestamp>2015-05-29T13:43:51</Timestamp> </DataRecord> <DataRecord id="7"> <Function>Instantaneous value</Function> <StorageNumber>0</StorageNumber> <Unit>Power (100 W)</Unit> <Value>0</Value> <Timestamp>2015-05-29T13:43:51</Timestamp> </DataRecord> <DataRecord id="8"> <Function>Maximum value</Function> <StorageNumber>0</StorageNumber> <Unit>Power (100 W)</Unit> <Value>47</Value> <Timestamp>2015-05-29T13:43:51</Timestamp> </DataRecord> <DataRecord id="9"> <Function>Instantaneous value</Function> <StorageNumber>0</StorageNumber> <Unit>Volume flow (m m^3/h)</Unit> <Value>0</Value> <Timestamp>2015-05-29T13:43:51</Timestamp> </DataRecord> <DataRecord id="10"> <Function>Maximum value</Function> <StorageNumber>0</StorageNumber> <Unit>Volume flow (m m^3/h)</Unit> <Value>1390</Value> <Timestamp>2015-05-29T13:43:51</Timestamp> </DataRecord> <DataRecord id="11"> <Function>Instantaneous value</Function> <StorageNumber>0</StorageNumber> <Tariff>1</Tariff> <Device>0</Device> <Unit>Energy (kWh)</Unit> <Value>0</Value> <Timestamp>2015-05-29T13:43:51</Timestamp> </DataRecord> <DataRecord id="12"> <Function>Instantaneous value</Function> <StorageNumber>0</StorageNumber> <Tariff>2</Tariff> <Device>0</Device> <Unit>Energy (kWh)</Unit> <Value>0</Value> <Timestamp>2015-05-29T13:43:51</Timestamp> </DataRecord> <DataRecord id="13"> <Function>Instantaneous value</Function> <StorageNumber>0</StorageNumber> <Tariff>0</Tariff> <Device>1</Device> <Unit>Volume (1e-2 m^3)</Unit> <Value>1</Value> <Timestamp>2015-05-29T13:43:51</Timestamp> </DataRecord> <DataRecord id="14"> <Function>Instantaneous value</Function> <StorageNumber>0</StorageNumber> <Tariff>0</Tariff> <Device>2</Device> <Unit>Volume (1e-2 m^3)</Unit> <Value>1</Value> <Timestamp>2015-05-29T13:43:51</Timestamp> </DataRecord> <DataRecord id="15"> <Function>Instantaneous value</Function> <StorageNumber>0</StorageNumber> <Tariff>0</Tariff> <Device>3</Device> <Unit>Energy (kWh)</Unit> <Value>0</Value> <Timestamp>2015-05-29T13:43:51</Timestamp> </DataRecord> <DataRecord id="16"> <Function>Instantaneous value</Function> <StorageNumber>0</StorageNumber> <Unit>Time Point (time & date)</Unit> <Value>2015-05-19T05:17:00</Value> <Timestamp>2015-05-29T13:43:51</Timestamp> </DataRecord> <DataRecord id="17"> <Function>Instantaneous value</Function> <StorageNumber>1</StorageNumber> <Unit>Energy (kWh)</Unit> <Value>0</Value> <Timestamp>2015-05-29T13:43:51</Timestamp> </DataRecord> <DataRecord id="18"> <Function>Instantaneous value</Function> <StorageNumber>1</StorageNumber> <Unit>Volume (1e-2 m^3)</Unit> <Value>0</Value> <Timestamp>2015-05-29T13:43:51</Timestamp> </DataRecord> <DataRecord id="19"> <Function>Maximum value</Function> <StorageNumber>1</StorageNumber> <Unit>Power (100 W)</Unit> <Value>0</Value> <Timestamp>2015-05-29T13:43:51</Timestamp> </DataRecord> <DataRecord id="20"> <Function>Maximum value</Function> <StorageNumber>1</StorageNumber> <Unit>Volume flow (m m^3/h)</Unit> <Value>0</Value> <Timestamp>2015-05-29T13:43:51</Timestamp> </DataRecord> <DataRecord id="21"> <Function>Instantaneous value</Function> <StorageNumber>1</StorageNumber> <Tariff>1</Tariff> <Device>0</Device> <Unit>Energy (kWh)</Unit> <Value>0</Value> <Timestamp>2015-05-29T13:43:51</Timestamp> </DataRecord> <DataRecord id="22"> <Function>Instantaneous value</Function> <StorageNumber>1</StorageNumber> <Tariff>2</Tariff> <Device>0</Device> <Unit>Energy (kWh)</Unit> <Value>0</Value> <Timestamp>2015-05-29T13:43:51</Timestamp> </DataRecord> <DataRecord id="23"> <Function>Instantaneous value</Function> <StorageNumber>1</StorageNumber> <Tariff>0</Tariff> <Device>1</Device> <Unit>Volume (1e-2 m^3)</Unit> <Value>0</Value> <Timestamp>2015-05-29T13:43:51</Timestamp> </DataRecord> <DataRecord id="24"> <Function>Instantaneous value</Function> <StorageNumber>1</StorageNumber> <Tariff>0</Tariff> <Device>2</Device> <Unit>Volume (1e-2 m^3)</Unit> <Value>0</Value> <Timestamp>2015-05-29T13:43:51</Timestamp> </DataRecord> <DataRecord id="25"> <Function>Instantaneous value</Function> <StorageNumber>1</StorageNumber> <Tariff>0</Tariff> <Device>3</Device> <Unit>Energy (kWh)</Unit> <Value>0</Value> <Timestamp>2015-05-29T13:43:51</Timestamp> </DataRecord> <DataRecord id="26"> <Function>Instantaneous value</Function> <StorageNumber>1</StorageNumber> <Unit>Time Point (date)</Unit> <Value>2000-00-00</Value> <Timestamp>2015-05-29T13:43:51</Timestamp> </DataRecord> <DataRecord id="27"> <Function>Manufacturer specific</Function> <Value>00 10 00 00 35 00 00 00 2C 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 EA A9 00 00 D0 52 00 00 1F FD 24 00 B0 FE AA 03 00 00 00 00 01 11 01 05 04 70 01 02 00 00 00 00 00</Value> <Timestamp>2015-05-29T13:43:51</Timestamp> </DataRecord> </MBusData> |
Commands sent to the MBUS device need to be even parity 1 stop bit, the arduino hardware serial library supports this but the softserial arduino library does not. I tried various suggested modifications to the softserial library but couldnt get it to work so in the end settled on the temporary solution of sending the command string on the hardware serial tx line and receiving the reply on the softserial rx line. This at least kept most of the activity off the hardware serial port used to communicate with the computer.
Here’s an example of the print out from the arduino reader showing the part of the kamstrup heatmeter data frame that we where most interested in:
Energy (kWh): 10
Volume (m3): 2.72
Ontime (hours): 2423
Flow temperature: 18.36
Return temperature: 18.16
Temperature difference (K): 0.20
Power (W): 0
Max Power (W): 47
Volume flow (m3/h): 0
Max volume flow (m3/h): 1390
To decode the data frame its a matter of reading each byte in the frame and understanding from the data frame specification what each byte corresponds too. For example the first part of the header that specifies the frame type, data length and address is read like this:
start1 = bytes[0]
length1 = bytes[1]
length2 = bytes[2]
start2 = bytes[3]
control = bytes[4]
address = bytes[5]
control_information = bytes[6]
The first record starts at byte 25 and is 6 bytes long, the first 2 bytes corresponding to type and units and the last 4 bytes the value. Which can be decoded with, where i is the start byte of the record (i.e 25)
value = bytes[i+2] + (bytes[i+3]<<8) + (bytes[i+4]<<16) + (bytes[i+5]<<24)
It would be good to do some more reading up on the protocol in order to create a more generic less hardcoded arduino library for reading MBUS meters and sort the software serial library even parity bit issue but the above gives a working initial solution that can be built upon and integrated into the OpenEnergyMonitor system. Data could now be sent via RFM12/69 to an emonbase for logging in emoncms.
A small step-up converter can be used to provide the 34V required for the MBUS
Arduino Script to read-out:
1 |
#include SoftwareSerial mySerial(5,3); unsigned long last = 0; unsigned long now = 0; char str[16]; int bid = 0; byte bytes[120]; byte dlen = 0; #define RF_freq RF12_433MHZ // Frequency of RF12B module can be RF12_433MHZ, RF12_868MHZ or RF12_915MHZ. You should use the one matching the module you have.433MHZ, RF12_868MHZ or RF12_915MHZ. You should use the one matching the module you have. const int nodeID = 5; // emonTx RFM12B node ID const int networkGroup = 210; // emonTx RFM12B wireless network group - needs to be same as emonBase and emonGLCD needs to be same as emonBase and emonGLCD #define RF69_COMPAT 0 // set to 1 to use RFM69CW #include // make sure V12 (latest) is used if using RFM69CW ISR(WDT_vect) { Sleepy::watchdogEvent(); } typedef struct { int address; int flowT; int returnT; int deltaT; int power; int maxpower; int flow; int maxflow; long energy; long volume; long ontime; } PayloadTX; // neat way of packaging data for RF comms PayloadTX emontx; const int LEDpin = 9; void setup() { Serial.begin(2400,SERIAL_8E1); mySerial.begin(2400); // command packet to request frame str[0] = (char) 16; str[1] = (char) 64; str[2] = (char) 253; str[3] = (char) 61; str[4] = (char) 22; str[5] = (char) 16; str[6] = (char) 64; str[7] = (char) 253; str[8] = (char) 61; str[9] = (char) 22; str[10] = (char) 16; str[11] = (char) 91; str[12] = (char) 147; str[13] = (char) 238; str[14] = (char) 22; str[15] = '\0'; /* // command packet to request frame str[0] = (char) 16; str[1] = (char) 64; str[2] = (char) 253; str[3] = (char) 61; str[4] = (char) 22; str[5] = (char) 16; str[6] = (char) 64; str[7] = (char) 253; str[8] = (char) 61; str[9] = (char) 22; str[10] = (char) 16; str[11] = (char) 91; str[12] = (char) 147; str[13] = (char) 159; str[14] = (char) 22; str[15] = '\0'; */ rf12_initialize(nodeID, RF_freq, networkGroup); pinMode(LEDpin,OUTPUT); } void loop() { now = millis(); if (mySerial.available()) { byte val = (byte) mySerial.read(); bytes[bid] = val; bid++; if (bytes[0]!=104) { bid = 0; } if (bid==3) { if (bytes[1]==bytes[2]) { dlen = bytes[1]; } else { bid = 0; } } if (bid==100) { parse(); bid = 0; } } if ((now-last)>10000) { last = now; Serial.println(str); mySerial.println(str[0]); } } void parse() { Serial.print("Address: "); Serial.println(bytes[5]); emontx.address = (int) bytes[5]; byte i=25; Serial.print("Energy (kWh): "); Serial.println(decodeval(i)); emontx.energy = decodeval(i); i+=6; Serial.print("Volume (m3): "); Serial.println(decodeval(i)*0.01); emontx.volume = decodeval(i); i+=6; Serial.print("Ontime (hours): "); Serial.println(decodeval(i)); emontx.ontime = decodeval(i); i+=6; Serial.print("Flow temperature: "); Serial.println(decodeval(i)/100.0); emontx.flowT = decodeval(i); i+=6; Serial.print("Return temperature: "); Serial.println(decodeval(i)/100.0); emontx.returnT = decodeval(i); i+=6; Serial.print("Temperature difference (K): "); Serial.println(decodeval(i)/100.0); emontx.deltaT = decodeval(i); i+=6; Serial.print("Power (W): "); Serial.println(decodeval(i)); emontx.power = decodeval(i); i+=6; Serial.print("Max Power (W): "); Serial.println(decodeval(i)); emontx.maxpower = decodeval(i); i+=6; Serial.print("Volume flow (m3/h): "); Serial.println(decodeval(i)); emontx.flow = decodeval(i); i+=6; Serial.print("Max volume flow (m3/h): "); Serial.println(decodeval(i)); emontx.maxflow = decodeval(i); i+=6; // if ready to send + exit loop if it gets stuck as it seems too int rf = 0; while (!rf12_canSend() && rf<10) {rf12_recvDone(); rf++;} rf12_sendStart(0, &emontx, sizeof emontx); // set the sync mode to 2 if the fuses are still the Arduino default // mode 3 (full powerdown) can only be used with 258 CK startup fuses rf12_sendWait(2); delay(100); digitalWrite(LEDpin, HIGH); delay(20); digitalWrite(LEDpin, LOW); // flash LED } long decodeval(long i) { return bytes[i+2] + (bytes[i+3]<<8) + (bytes[i+4]<<16) + (bytes[i+5]<<24); } |
Source: https://openenergymonitor.org/forum-archive/sites/default/files/kamstrup402_mbus_reader_rf12.html