M-Bus for Rust
Read heat, water and gas meters over the wired bus or by radio: EN 13757-2, -3, -4 and OMS, encrypted or not. Sans-I/O, no_std, no allocator, every record described, and exact readings, never floats.
Read a wired meter
Every telegram of the meter you addressed, or an error that says why not.
use mbus_kit::master::{Baud, Readout, SecondaryAddress, Target};
use mbus_kit::serial::Bus;
let mut bus = Bus::new(port, Baud::B2400); // a serial port or a TcpStream
let meter = SecondaryAddress::pattern("12345678").unwrap();
for telegram in bus.run_readout(Readout::new(Target::Primary(5)).expect_meter(meter))? {
for r in telegram.application()?.records().into_iter().flatten() {
println!("{}", r?); // "volume flow · maximum · storage 5 — 0.113 m³/h"
}
}Receive one by radio
Check the CRCs, decrypt with the meter's key, and know whether the reading is authenticated.
use mbus_kit::oms::Key;
use mbus_kit::wireless::{self, Format};
let key = Key::from_hex(KEY_SHEET).unwrap();
let mut buf = [0u8; 512];
if let Some((t, _)) = wireless::open(&raw, Format::A, &key, &mut buf)? {
// ELS 12345678 gas v51 · Authenticated { counter: 2739 }
println!("{} · {:?}", t.address, t.app.authenticity);
for r in t.app.records().into_iter().flatten() {
println!("{}", r?); // "volume — 28504.27 m³"
}
}The wire format
Wired and wireless frames, the CI field, fragments, compact frames, data records and the VIF table.
Wired master
Complete readouts from the meter you addressed, secondary addressing and a bus search over a real converter or gateway.
JSON and the mbus tool
Every telegram as one JSON line with exact values; decode, read, search and listen from the shell.
Radio receivers
IMST iM871A and iU891A, Amber AMB8465: one decoder, telegrams with RSSI.
Security
OMS modes 5, 7 and 10, the ELL, fragments, keys as secrets, and what a telegram can prove.
Simulating meters
OMS-secured telegrams for gateway tests: rising counters, modes 5, 7 and 10, and the tail attack.
Embedded builds
No allocator, no dependencies and no panic path on a Cortex-M.
Status
What is implemented, what is assumed, and what a real meter still has to confirm.