Wireless M-Bus meter decoder (gophertrunk wmbus)
Wireless M-Bus (EN 13757-4) is the 868 MHz radio protocol of European
utility meters: heat cost allocators on radiators, water, gas, heat and
electricity meters, and the OMS (Open Metering System) devices built on it.
Most meters broadcast a short telegram every few seconds to minutes.
gophertrunk wmbus decodes them from a live SDR, an rtl_tcp server, or a
capture file.
What it decodes
- Modes T1 and C1, the two meter-to-reader modes nearly all installed meters use, both on 868.95 MHz at 100 kchip/s. T1 is 3-of-6 coded; C1 uses frame format A or B. Mode S1 (868.3 MHz) is not decoded.
- The sender of every telegram: manufacturer code (e.g.
TCHTechem,QDSQundis,KAMKamstrup), the 8-digit meter ID printed on the device, version and device type. - The readings of unencrypted meters: the EN 13757-3 data records
(volume, energy, heat cost allocation units, temperatures, dates, …),
including historic values such as the reading at the last set day
(
[storage 1]).
Encrypted meters
Most OMS meters encrypt their readings with AES-128 (security mode 5,
or mode 7 with an authentication layer), using a per-meter key held by
the metering company. For these, wmbus still shows who sent the telegram,
when, and the device type, and prints the security mode, for example:
T1-A -11.7 dBFS BMT 19131290 water (v13) encrypted: AES-128-CBC with IV (mode 5), access 121
No decryption is attempted, and there is no key option yet.
Listening live
gophertrunk wmbus # local RTL-SDR at 868.95 MHz, 1.6 MS/s
gophertrunk wmbus -rtltcp 127.0.0.1:1234 # through an rtl_tcp server, e.g. on a phone
gophertrunk wmbus -gain 400 -ppm 30 # fixed 40 dB gain, 30 ppm correction
Each telegram prints one line, with one indented line per data record. This is an unencrypted Qundis heat cost allocator (a test telegram from wmbusmeters’ simulation set, modulated and decoded by GopherTrunk):
2026-10-10 14:03:12.418 C1-A -6.9 dBFS QDS 78563412 heat cost allocator (v35)
heat cost allocation 127
heat cost allocation [storage 1] 145
date [storage 1] 2018-12-31
heat cost allocation [storage 17] 79
date [storage 17] 2019-01-31
date (error) invalid date FFFF
date time 2019-02-20 11:32
Storage 0 is the current value, and higher storage numbers are historic
values. Here, storage 1 is the reading at the last set day. A capture file
prints the time into the capture (t= 2.802s) instead of the wall clock.
-jsonprints one JSON object per telegram instead. Itsframefield is the telegram’s raw bytes in hex. See Reading telegrams from a script.-
-allalso prints frames whose CRC failed, with the CRC block that failed:C1-A -7.9 dBFS 0x097D 98A18249 electricity (v01) CRC FAILED (block 1 of 4; block 1 is the header, so the sender shown is unreliable) C1-A -12.0 dBFS DWZ 11130881 heat cost allocator (v80) CRC FAILED (blocks 3,4 of 4; header OK)Block 1 carries the sender (manufacturer, ID, device type). When it fails, those fields are whatever the damaged bytes decode to; a manufacturer shown as a hex number such as
0x097Dis not a real code. When only later blocks fail, the sender is right and the damage is in the payload. With-json, a failed frame carriescrc_blocks,crc_failed_blocks,header_crc_okandraw(the frame as received, CRC bytes included), so it can be checked offline.On a live run, a failed frame that the SDR dropped IQ in the middle of says so:
CRC FAILED (blocks 4,5 of 5; header OK) — cut by dropped IQ (the SDR dropped chunks during it), not a weak meter. That failure says nothing about the meter’s signal: the device never delivered the rest of the telegram. With-jsonsuch a frame has"iq_gap": true, its saved snippet hasiq_gapin its.metadata.json, and the progress lines count them (; 3 of the CRC failures were cut by dropped IQ). Replaying that snippet cannot recover it. A failed frame without the mark failed on the air: a weak or interfered signal. -seconds Nstops after N seconds.-save-frames DIRkeeps the radio signal (IQ) around each telegram; see Saving telegrams to share.-log FILEappends every telegram line and progress line to FILE as it happens, and everything else GopherTrunk prints too: SDR / USB warnings, the stop hints, and the reason a live run ended (for examplewmbus: IQ stream ended: …when the SDR or rtl_tcp server goes away). It survives Ctrl-C and a closed terminal; prefer it to| tee, which Ctrl-C kills along with GopherTrunk (or use| tee -i). If a run stops on its own,tail -n 20 FILEshows why. Only a process the system kills outright (Android freeing memory,kill -9) gets no chance to write anything; Termux then shows[Process completed (signal 9)], andtermux-wake-lockbefore starting usually prevents it.- Ctrl-C,
kill/pkill gophertrunk(SIGTERM) and a closed terminal all stop a live run the same way, with its summary. If the SDR does not close within 5 s (a USB transfer stuck on a phone) it says so and exits anyway. On Termux undersu, the terminal’s Ctrl-C can endsuwithout reaching GopherTrunk: the process has no terminal of its own (psshows its TTY as?). GopherTrunk notices and says so at start; then typeqand Enter to stop it, or stop it from a root shell withpkill gophertrunk, or give-seconds. The same holds forcaptureandpower. - If the SDR disappears mid-run (it drops off the USB bus, or the rtl_tcp
server hangs up), a live run waits for it and carries on, logging
wmbus: lost the SDR at …with the reason andwmbus: SDR back after …when it reopens. On a walk this keeps a loose OTG cable from ending the recording unnoticed (issue #1256).-reconnect=falsestops instead, with the reason. - The run never asks “Show full diagnostic trace? [y/N]” while it is
reading
qfrom the terminal: the two would compete for the same input. Add-verbose-errorsif you want the full trace printed. -status 30s(the default) prints a progress line that often;0turns it off.gophertrunk help wmbuslists every flag.
Progress line. Meters send every couple of minutes to every few hours, so a live run can be quiet for a long time. The progress line shows it is alive:
wmbus: listening 5m0s (14:02:39): 3 frames (1 CRC-valid, 2 CRC-failed), 412 access codes, 0 dropped chunks, carrier -50.1 kHz (-58 ppm)
The first time is stream time, how much IQ the decoder has worked through; the time in brackets is the time of day, so the line lines up with the telegram timestamps. The two drift apart whenever IQ is dropped.
- Access codes are sync words. They also appear by chance in noise, so a steady trickle with no frames is normal.
- CRC-failed frames are telegrams that were heard but damaged: the
signal is there but weak, clipped or interfered with. Add
-allto see them. -
Dropped chunks must stay at 0. Any drop means the computer did not keep up with the SDR and a telegram in the gap is lost. A warning is printed the first time it happens. Lowering
-ratedoes not help: since v1.3.5 the decoder costs about the same at any rate from 1.024 to 1.6 MS/s, so keep the 1.6 MS/s default. Close other programs and check the USB link, or record withcaptureand decode the file afterwards, which has no real-time limit.When the drops come from the computer starving GopherTrunk of CPU, the warning says how much of real time the decoder actually got, for example
in the last 3m44s the decoder got through only 30s of IQ (13% of real time). On a phone this is the system throttling the process, usually because the screen went off or Termux went to the background: on the 1 Nov 2026 walk in issue #1256 about 10 of 21 minutes went unheard that way. Keep the screen on (Termux’s “keep screen on” option), runtermux-wake-lockbefore starting, and exempt Termux from battery optimisation. - Repaired (
12 CRC-valid of which 2 repaired) counts telegrams that passed only after a CRC repair; see Weak telegrams below. - Carrier appears once a telegram has decoded: it is where the meters’ signal sits relative to 868.95 MHz. Every meter heard through one dongle shows the same offset, so this is mostly the dongle’s own frequency error.
Tuning. An RTL-SDR’s crystal can be tens of ppm off, which is tens of
kHz at 868 MHz (issue #1256: an S5’s dongle heard every meter about 50 kHz,
58 ppm, low). The decoder hears a carrier up to about ±120 kHz off. Once a
telegram decodes with a valid CRC it re-centres on that telegram’s carrier
and narrows its channel filter to it, which keeps out noise from the rest of
the band: on that S5’s saved telegrams it decoded 128 of 156 instead of 97.
It refines the estimate with every CRC-valid telegram after that, and
widens the filter again after two minutes without one in case the dongle
has drifted. So -ppm is rarely needed. When the offset is over 20 ppm, the
progress line suggests a -ppm value that would centre the tuner; the sign
convention is the driver’s, so try both signs and keep the one that shrinks
the offset. If nothing decodes near a meter, try -ppm and a fixed -gain.
Weak telegrams. At the edge of reception a telegram can fail its CRC
on one or two bits. For C mode telegrams the decoder then tries flipping the
bits it was least sure of, at most two per CRC block, and accepts the
telegram only if the block’s CRC then passes. The CRC catches every error of
up to five bits in a block, so a real one- or two-bit error has exactly one
repair. A telegram repaired this way prints (CRC repaired: N bits), and
its JSON carries corrected_bits. A badly damaged block passes this way
about once in 500 tries, so skip telegrams with corrected_bits if a reading
must never be wrong. The decoder also limits the clicks that FM reception
produces at low signal levels, which are what made the strongest-looking
bits of a weak telegram the wrong ones. On the S5’s saved telegrams the two
together took the CRC-valid count from 128 to 133.
Gain. -gain (on wmbus and capture) takes tenths of a dB: -gain 200
is 20 dB, -gain 0 the tuner’s minimum, and auto lets the tuner’s AGC
choose, which a strong nearby transmitter can drive into clipping. Start
around -gain 200 and step down while capture reports clipping; step up
only if telegrams are weak (the dBFS level on each line). With an external
preamplifier in front of the dongle, start low (-gain 0 to -gain 100):
the preamplifier already supplies the gain, and too much clips the ADC.
Without one, -gain 0 is usually too little: on the S5’s walk at -gain 0
the strongest telegrams reached only about 7 of the converter’s 127 steps.
Reading telegrams from a script
-json writes one JSON object per line to standard output, one per
telegram, and nothing else: progress lines go to standard error. Pipe it
into the script:
gophertrunk wmbus -json | perl meters.pl
Each object carries time, mode, crc_ok, level_dbfs,
carrier_offset_hz, manufacturer, id, device, encrypted, frame
(the telegram in hex), corrected_bits (only when the CRC repair flipped
bits; see Weak telegrams) and records, one per reading, with quantity,
storage, value (a number) or text (a date, or hex for data GopherTrunk
does not decode) and unit where they apply. A minimal Perl reader, using
only the core JSON::PP module:
#!/usr/bin/perl
use strict;
use warnings;
use JSON::PP;
$| = 1;
while (my $line = <STDIN>) {
my $t = eval { decode_json($line) } or next;
next if exists $t->{status}; # a progress line (from a -json -log file)
next unless $t->{crc_ok}; # with -all, CRC-failed frames come through too
for my $r (@{ $t->{records} || [] }) {
my $v = $r->{value} // $r->{text}; # a number, or text such as a date
next unless defined $v;
printf "%s %s %s %s storage=%d %s %s\n",
$t->{time}, $t->{manufacturer}, $t->{id}, $r->{quantity},
$r->{storage} // 0, $v, $r->{unit} // '';
# ...or insert into your database here (DBI).
}
}
To keep a file and read it as well, use -json -log meters.json. With
-json, the progress lines in the log are JSON too
({"time": …, "status": "wmbus: listening …"}), and so are the warnings
and the stop reason, so every line of the file parses; skip the ones with a
status key, as the example does. A script
can follow the file with tail -F meters.json | perl meters.pl while
GopherTrunk runs, or read it afterwards.
Decoding a capture
gophertrunk wmbus -in meters.cu8 # rate/centre from meters.metadata.json
gophertrunk wmbus -in meters.flac # wav/flac containers carry their own rate
gophertrunk wmbus -in rtl.cu8 -rate 2400000 # rtl_sdr capture: no sidecar, so give the rate
gophertrunk wmbus -in wide.cu8 -rate 2400000 -offset 325000 # capture centred 325 kHz below 868.95 MHz
A headerless file (.cu8, .raw, .bin) carries no sample rate. When
gophertrunk capture wrote it, the .metadata.json beside it does, and
wmbus -in reads the rate, format and centre frequency from there (it says
so on the first lines). Without a sidecar, -rate (or -sample-rate)
defaults to 1.6 MS/s. Decoding at the wrong rate finds access codes but no
frames, and stretches the reported duration: a 30 s capture at 2.8 MS/s read
at 1.6 MS/s reports 52.5 s. Flags you give override the sidecar.
Headerless files default to rtl_sdr’s unsigned 8-bit format (-format u8);
cs16 and f32 work too. A u8 file holds two bytes (I and Q) per sample, so
30 s at 2.8 MS/s is 168 MB. To record a capture with GopherTrunk:
gophertrunk capture -freq 868950000 -sample-rate 1600000 -seconds 60 -format u8 -out meters.cu8
gophertrunk capture -freq 868950000 -sample-rate 1024000 -seconds 60 -format flac -out meters.flac
1.6 MS/s decodes slightly more weak telegrams. FLAC is smaller, but it cannot store rates above 1,048,575 S/s, hence 1.024 MS/s for it.
To look at a capture rather than decode it, gophertrunk spectrum -in
meters.cu8 prints its averaged spectrum and the carriers in it. It reads the
format, sample rate and centre from the capture’s .metadata.json (flags you
give win); without one, give -format u8 -sample-rate 1600000 -freq
868950000. A file read in the wrong format is refused rather than printed as
NaN. Each carrier line is its offset from the centre (and its frequency, when
the centre is known), its peak level in dBFS and how far it stands above the
noise floor (SNR). A wM-Bus capture is mostly noise between telegrams, so
expect few carriers in the average; meters show up only if they sent often.
GopherTrunk has no waterfall for a whole capture file;
inspectrum shows each telegram as a
burst. inspectrum picks the sample format from the file extension, and
reads .raw / .bin as 32-bit float: a u8 capture with those names shows as
one solid red block. Name (or link) it .cu8, then set the sample rate in its
side panel.
Saving telegrams to share
A meter sends a telegram every few seconds to few minutes, and each one lasts
only tens of milliseconds, so a whole capture is mostly empty air: 30 s at
1.6 MS/s is about 96 MB even in rtl_sdr’s 8-bit format. -save-frames keeps just the part that matters:
gophertrunk wmbus -rtltcp 127.0.0.1:1234 -save-frames meters/ # live, phone + rtl_tcp
gophertrunk wmbus -save-frames meters/ # live, local dongle
gophertrunk wmbus -in street.cu8 -save-frames meters/ # cut a big capture down
For every telegram it prints, it writes two files to the directory:
<time>_<mode>_<manufacturer>_<id>.wav: the IQ from just before the telegram to just after it, typically 100–400 KB. The WAV carries its own sample rate, sogophertrunk wmbus -in <file>.wavreplays it (the offset comes from the snippet’s.metadata.json).<time>_<mode>_<manufacturer>_<id>.metadata.json: the sample rate, the centre frequency and offset, and the decoded telegram (manufacturer, ID, device type, CRC result, level, and the raw frame in hex).
This works live, including through rtl_tcp, and on a capture you already
have. (gophertrunk capture -rtltcp host:port records a whole capture through
rtl_tcp too, but most of it is empty air between telegrams.)
Only CRC-valid telegrams are saved unless -all is given; with -all,
telegrams whose CRC failed are saved too, which is the useful case when a
meter does not decode. A live run prints wmbus: saved <file> as each one is
written, and says at start-up when it is keeping CRC-valid telegrams only.
To report results, the printed lines (or -json lines) can be pasted as text
on its own. Zip the meters/ directory when the signal itself needs looking
at.
Verification
The decoder was checked against two independent decoders:
- rtl-wmbus. Its four real-air sample captures decode with every telegram rtl-wmbus finds with a valid CRC, byte for byte. GopherTrunk also decodes five more CRC-valid telegrams that rtl-wmbus misses.
- wmbusmeters. Unencrypted telegrams from its test set decode to the same meter IDs and readings its drivers report.
On air (issue #1256, 20 Oct 2026), a Samsung S5 with an RTL-SDR walking
past a block of flats decoded Qundis heat cost allocators and Diehl water
meters. Its 156 saved telegrams are the yield check for receiver changes
(TestWMBusRealAirSnippets): 74 decoded with a valid CRC on v1.3.1, 97
with the mid-chip clock, 128 with the carrier tracking, and 133 with the
FM click limit and the CRC repair (decoded one at a time, without a carrier
estimate carried over from earlier telegrams: 97, then 110). If you try it
near meters, a capture with the decoder’s output is welcome on that issue.