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. TCH Techem, QDS Qundis, KAM Kamstrup), 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) not set
    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. date (error) not set is the day of the meter’s last error, and this meter has had none. A capture file prints the time into the capture (t= 2.802s) instead of the wall clock.

  • -json prints one JSON object per telegram instead. Its frame field is the telegram’s raw bytes in hex. See Reading telegrams from a script.
  • -all also 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 0x097D is 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 carries crc_blocks, crc_failed_blocks, header_crc_ok and raw (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 -json such a frame has "iq_gap": true, its saved snippet has iq_gap in 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 N stops after N seconds.
  • -save-frames DIR keeps the radio signal (IQ) around each telegram; see Saving telegrams to share.
  • -log FILE appends 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 example wmbus: 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 FILE shows 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)], and termux-wake-lock before 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 under su, the terminal’s Ctrl-C can end su without reaching GopherTrunk: the process has no terminal of its own (ps shows its TTY as ?). GopherTrunk notices and says so at start; then type q and Enter to stop it, or stop it from a root shell with pkill gophertrunk, or give -seconds. The same holds for capture and power.
  • 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 and wmbus: SDR back after … when it reopens. On a walk this keeps a loose OTG cable from ending the recording unnoticed (issue #1256). -reconnect=false stops instead, with the reason. Every waiting line rings the terminal bell (Termux vibrates the phone on it by default), and once the SDR has been gone for a minute the line says whether it is still on the USB bus and asks for a replug: on the 8 Nov walk the dongle came back by itself after 8 s once, then dropped off the bus for good, and only unplugging and replugging it brought it back (a phone’s OTG port stays off after a disconnect). The run carries on from the replug.
  • The run never asks “Show full diagnostic trace? [y/N]” while it is reading q from the terminal: the two would compete for the same input. Add -verbose-errors if you want the full trace printed.
  • -status 30s (the default) prints a progress line that often; 0 turns it off. gophertrunk help wmbus lists 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), 5 access codes in 41 bursts, 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.

  • Bursts counts the times something rose out of the channel’s noise: a meter, or any other transmitter on the channel. The decoder only works on the IQ around a burst (see CPU below), so this number moving is the sign that the receiver is hearing the channel. A few bursts with no frames is normal.
  • Access codes are the sync words found in those bursts. Up to v1.4.0 the decoder also ran on the noise between bursts and found a steady trickle of them there by chance; that trickle is gone.
  • CRC-failed frames are telegrams that were heard but damaged: the signal is there but weak, clipped or interfered with. Add -all to 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 -rate does 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 with capture and 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), run termux-wake-lock before starting, and exempt Termux from battery optimisation. Every drop warning rings the terminal bell, which Termux turns into a vibration, so you notice it with the phone in a pocket.

    If the drops continue with the screen off, look for the phone’s performance or power profile. On the issue #1256 reporter’s Samsung S5 (LineageOS, Android 11), moving it from “balanced” to “more performance” took three runs (23 Nov 2026, 18.5 minutes, screen switching off on its own) to 0 dropped chunks, where earlier walks lost 20-30 % of the IQ. The setting’s name and place differ between Android builds.

Overlapping telegrams. Where many meters are in range, one can key up while another is still sending. The stronger one then takes over the receiver. After v1.4.3 the decoder keeps looking for the start of a new telegram while it is still receiving one, so the stronger telegram is decoded; before, it was lost and only the weaker one’s CRC failure was logged. The weaker telegram still fails from the point the other one began. On the 23 Nov 2026 run in issue #1256, 4 of 721 saved telegrams had a stronger meter hidden in them this way.

CPU. A meter is on the air for a few milliseconds every few minutes, so nearly all of the IQ is noise. After v1.4.0 the decoder watches the channel’s power and demodulates only the IQ around a burst that rises out of the noise, starting 1.3 ms before it. On noise that takes about a fifteenth of the CPU the decoder took before (0.004 of a desktop core at 1.6 MS/s, where it took 0.06), which is what a slow or throttled phone needs. The burst detector opens 1.5 dB over the noise; on the 16 Nov 2026 walk in issue #1256 the weakest telegram that decoded was 4.6 dB over it, and the same 602 of 770 saved telegrams decode with and without the gate.

One case where it can cost reception: a strong transmitter that stays on for many seconds elsewhere in the dongle’s 1.6 MHz span raises what the detector takes for noise, and a weak telegram may then not open it. -no-gate runs the decoder on all of the IQ, as before, if you want to compare.

  • 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. A telegram can fail its CRC on a few bits. For C mode telegrams the decoder then tries flipping the bits it was least sure of, and accepts the telegram only if the block’s CRC then passes. It tries one or two of a block’s 16 least reliable bits, then three of its 8 least reliable bits. The CRC catches every error of up to five bits in a block, so a real error of up to three bits 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 400 tries, so skip telegrams with corrected_bits if a reading must never be wrong.

The decoder reads each bit by comparing the energy at the two FSK tones, not by FM-demodulating the signal first. That matters when a meter is not far above the receiver’s noise: on the S5 reporter’s five walks (2,005 saved telegrams, issue #1256) it decodes 1,418 in the order they were heard, where the FM demodulator it replaced decoded 1,190, and it hears 350 different meters instead of 296. Most of the gain is in telegrams that looked strong but were only 8 to 20 dB above that tuner’s noise floor.

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, so gophertrunk wmbus -in <file>.wav replays 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, 133 with the CRC repair, and 141 with the tone-comparing detector (decoded one at a time, without a carrier estimate carried over from earlier telegrams: 97, 110, then 140). If you try it near meters, a capture with the decoder’s output is welcome on that issue.