mbus-kit

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³"
    }
}