mbus-kit

The wire format

Wired and wireless M-Bus frames, the CI field, data records and the VIF table, byte by byte.

Wired frames (EN 13757-2)

E5                                  ACK
10  C  A  CS  16                    short frame       CS = C + A
68  L  L  68  C  A  CI  …  CS  16   long frame        CS = sum of the L bytes from C
CMeaning
40SND_NKE: reset the slave
53 / 73SND_UD: send data to the slave (FCB 0/1)
5B / 7BREQ_UD2: request the reading (FCB 0/1)
08, 18, 28, 38RSP_UD: the slave's response

Wireless frames (EN 13757-4)

L  C  M M  A A A A A A  CI …
      ^^^  ID (BCD, LSB first), version, device type
      manufacturer (three letters in 15 bits, LE)

Format A: a CRC after the first 10 bytes and after every following block of 16. Format B: one CRC after block 2 (covering blocks 1 and 2), one after block 3. The CRC is CRC-16/EN-13757 (polynomial 3D65), most significant byte first.

[ELL 8C–8F]  [AFL 90]  TPL CI + header  records
CILayerContent
8C / 8Eextended link layercommunication control, access number (8E: receiver address)
8D / 8Fthe same, encrypted+ session number, payload CRC; AES-CTR when the session number says so
90authentication and fragmentationfragment control, message control, key info, message counter, CMAC, message length
72 / 7A / 78transport layerlong header, short header, none; then records
73 / 7B / 79compact framethe same headers; then format signature, full-frame CRC, data only
6B / 6A / 69format framethe same headers; then a record layout and its signature

Each layer appears at most once, in this order. See Security.

Fragments

A message too long for one frame is split into fragments, each a frame of its own with an AFL. Fragment control: bit 14 more fragments, bits 13–9 which fields follow, bits 7–0 the fragment ID (0 = not fragmented, then 1, 2, 3, …). The first fragment carries message control, counter and the message length, and the transport layer starts in it; pieces are cut anywhere, even mid-record. The last carries the MAC over the whole message.

OMS Annex N N.3, link-layer CRCs removed:

fragment 1:  … 90 09 01 78 65 B3 0A 00 00 56 00 | 7A 05 00 50 07 10 30 53 …   (ID 1, more; MCL, counter, ML 86)
fragment 2:  … 90 02 02 40                       | C4 90 27 8E …               (ID 2, more)
fragment 3:  … 90 0A 03 04 BE 47 ED 4C 9C C1 1A 78 | 06 CC 3E …               (ID 3, MAC)

Compact frames

A meter sends a full frame now and then and compact frames in between: CI 79, then the format signature (CRC-16 of every record's DIF/DIFE/VIF/VIFE bytes), the full-frame CRC (CRC-16 of the records rebuilt), and the data bytes only. The receiver keeps the layouts it has seen; Compact::expand rebuilds the records and checks the full-frame CRC.

The CI field and header (EN 13757-3)

CIHeaderThen
72long: ID (4, BCD), manufacturer (2), version, medium, access no., status, configuration (2)records
7Ashort: access no., status, configuration (2)records
78nonerecords

The configuration field announces encryption: mode in the high byte (bits 0–4), the number of encrypted 16-byte blocks in the high nibble of the low byte (0: none, 15: all). OMS mode 5 with two blocks is 20 05 on the wire; mode 7 adds a configuration field extension byte (key derivation, key id). Mode 10 counts encrypted bytes in the low byte (FF: all) and adds a 2-byte extension, a key version, the message counter, and a tag at the end.

A data record

DIF  [DIFE…]  VIF  [VIFE…]  data
DIF bitsMeaning
7another DIFE follows
6storage number, least significant bit
5–4function: instantaneous, maximum, minimum, during error
3–0data: 1–4, 6, 7 integer of 1–4, 6, 8 bytes · 5 real · 9–C, E BCD of 1–4, 6 bytes · D variable (LVAR)

Each DIFE adds 4 storage bits, 2 tariff bits and 1 subunit bit. 2F is filler; 0F and 1F start manufacturer-specific data.

The value information block

VIF  [VIFE …]          bit 7 of each byte: another VIFE follows (at most 10)

The VIF picks a quantity, unit and decimal exponent from the primary table. Two codes point to an extension table whose code is the first VIFE: FB (larger units) and FD (identifiers, versions, error flags, volts, amperes; FD FD for OMS sensors). Every further VIFE is combinable: it modifies the value.

VIFQuantityUnit and exponent
00–07energyWh × 10^(n−3)
08–0FenergyJ × 10^n
10–17volumem³ × 10^(n−6)
18–1Fmasskg × 10^(n−3)
20–27on time, operating times, min, h, d
28–2FpowerW × 10^(n−3)
38–4Fvolume flowm³/h, m³/min, m³/s
58–67flow, return, difference, external temperature°C / K × 10^(nn−3)
68–6Bpressurebar × 10^(nn−3)
6C / 6Ddate (type G) / time (J), date and time (F, I) by size
78, 79, 7Afabrication number, identification, bus address
7Cplain-text unit (length, then ASCII, last character first)
FB xx, FD xxextension tablese.g. FB 00 MWh × 10⁻¹, FD 17 error flags
7F / FFmanufacturer specific
Combinable VIFEMeaningquantity()
70–77, 7D× 10^(nnn−6), × 10³applied
3A, 3B, 3C, 40/48, 68/6C, 7Euncorrected, forward, backward, limits, during limit exceed, future valuekept
20–35per second … per year, per litre, per kWh …None
39, 42–4F, 6A–6Fstart date of, date of a limit exceedNone, value is a date
41/49, 50–67number of exceeds, durationsNone
78–7Badditive correction constant (offset)None
00–1Crecord error (no data, overflow, …)None
FC xxphases L1–L3, quadrants, unsigned (data type C) …kept
7Fthe rest is manufacturer specificNone

Record::quantity() never returns a value a VIFE has changed in a way the crate does not model: a missing reading is visible, a wrong one is not. record.vib.modifiers() lists every combinable VIFE as a typed Modifier.

Dates and times

TypeBytesContent
G2date
J3time of day with seconds
F4date, hour, minute, invalid and summer-time flags
I6type F with seconds, day of week and week number
MLVAR E2–EAa time offset: count, then resolution (2 s, 1 s, 1/256 s, 1/32768 s); the relative form is a time before reception (3 s before reception)

Compact profiles

VIFE 1F (forward), 13 (inverse) or 1E (with registers) turn an LVAR record into a series: spacing control (increments or readings, unit, element coding), spacing value (seconds to days, half months, 1/3/6 months), then the elements. The series hangs off a base value and a base time of the same storage number; Profile::values(base) yields the readings, Profile::offset(k) and Profile::date(k, base) when each was taken.

A date the meter flags invalid, or one that cannot exist, is still returned: Date::is_valid() and DateTime::is_valid() say so.

The reference telegram, decoded

68 1F 1F 68  08 02 72                      RSP_UD from address 2, long header
78 56 34 12  24 40  01  07  55  00  00 00  ID 12345678, PAD, v1, water, access 0x55
03 13  15 31 00                            volume       12565 × 10⁻³ m³ = 12.565 m³
DA 02 3B  13 01                            volume flow  max, storage 5: 0.113 m³/h
8B 60 04  37 18 02                         energy       tariff 2, subunit 1: 218370 Wh
18 16                                      checksum, stop