Rust crate · no_std · MIT or Apache-2.0
Read German smart meters in Rust
sml-kit decodes SML, the protocol of every German basic meter, from an infrared reading head or the meter bus behind a smart-meter gateway into exact readings. Sans-I/O, no allocator, no dependencies, and it never panics on what a meter sends.
cargo add sml-kit- 216real meter frames tested
- 8manufacturers
- 0dependencies
- 0floats, allocations,
unsafe
From the meter to a number
- Meterpushes an SML telegram about every second over its optical interface
- Reading headturns the infrared light into bytes on a serial port (9600 baud, 8N1)
Decoderfinds the frame in the byte stream and checks its CRCreadoutchecks every message and returns the list of readingsQuantity15338555.7 Wh: exact, with its unit, as the meter sent it
Read a meter
Feed bytes as they arrive, in any piece size. The decoder keeps a frame that spans several reads.
use sml_kit::{Decoder, Obis, readout};
let mut decoder = Decoder::new([0u8; 1024]); // once per meter
loop {
let n = port.read(&mut chunk)?; // a frame may span several reads
decoder.push_slice(&chunk[..n], |frame| {
let Ok(list) = frame.and_then(readout) else { return };
let a_plus = list.quantity(Obis::ENERGY_IMPORT);
// Some(15338555.7 Wh): exact, from meter 1 EMH00 04321349
});
}Simulate one
Write a meter telegram with correct CRCs: for tests, simulators and request files a gateway sends.
use sml_kit::{ListEntry, Obis, Unit, encode_frame, sim::Telegram};
let entries = [
ListEntry::bytes(Obis::MANUFACTURER, b"SIM"),
ListEntry::unsigned(Obis::ENERGY_IMPORT, Unit::WH, -1, 123_456_789),
];
let t = Telegram { server_id, file_id: b"F1", entries: &entries };
let n = t.write(&mut payload)?;
let m = encode_frame(&payload[..n], &mut wire)?;Built for meters you do not control
Exact, never floats
A reading is mantissa × 10^scaler with its unit. A meter reading is evidence for an invoice; it stays exactly what the meter sent.
Never panics on input
Truncated, corrupted and random bytes are errors. Panics are denied by lint, the release build is checked for panic paths, and every parser is fuzzed.
Sans-I/O, no_std
No ports, clocks or allocator inside. The same decoder runs on a Cortex-M, in an Embassy or Tokio task, or over a capture file.
Strict by default
Both CRCs are checked as specified. Each deviation a real meter needs is a named option, and the capture tool tells you which one.
Both directions
Every message a gateway or service tool exchanges is typed, read and written: request files, parameters, profiles, the logbook.
No secrets in logs
Every request that carries a password prints it as <redacted>, and no parser's Debug shows payload bytes.
Tested against real meters
Every CRC-valid frame of the public libsml-testing collection reads, strictly for every meter but one.
- EMH
- ISKRA
- DZG
- Holley
- Itron
- eBZ
- EasyMeter
- Dr. Neuhaus
Documentation
What is SML?
SML (Smart Message Language) explained: the protocol of German smart meters, the optical interface, the PIN, OBIS codes and what a telegram contains.
Getting started
Add sml-kit to a Rust project, feed it bytes from an infrared reading head, and read exact meter values.
The wire format
SML transport v1, the type-length encoding, messages and list entries, byte by byte.
Meter quirks
Which real meters deviate from the SML specification, how sml-kit reads them, and how to find out what your meter needs.
Talking to a meter
Requests, process parameters and profiles: what a gateway or a service tool sends to a meter and how it reads the answer.
Embedded builds
sml-kit on a microcontroller: no std, no allocator, a caller-owned buffer and no panic path.
Status
What sml-kit supports, what real meters have confirmed, and its limits.
Questions
Which meters does sml-kit read?
Any meter that sends SML with transport protocol version 1: every German basic meter (moderne Messeinrichtung) and most electronic household meters (eHZ) before them. It is tested against 216 real frames from EMH, ISKRA, DZG, Holley, Itron, eBZ, EasyMeter and Dr. Neuhaus meters. Three known deviations (Holley CRC and time encoding, the DZG DVS74 power sign) are read through named options.
Do I need the PIN from my meter operator?
Only for the full data set. Without the PIN, most basic meters send energy in whole kilowatt-hours and no power. Ask your meter operator (Messstellenbetreiber) for the four-digit PIN, enter it with a torch at the meter's light sensor and switch the extended data set on (often the menu item InF). sml-kit decodes whatever the meter sends.
My meter sends text that starts with a slash. Is that SML?
No. Text lines such as /ESY5Q3DA1004 and 1-0:1.8.0*255(00012345.6*kWh) are IEC 62056-21 (often called D0), an older protocol. SML is binary and every frame starts with 1b 1b 1b 1b 01 01 01 01. The decode example recognises both and tells you which one you have.
Does it run on a microcontroller such as an ESP32 or STM32?
Yes. Without the default std feature it needs no allocator and no dependencies. CI builds it for Cortex-M4/M7, RISC-V (ESP32-C3) and WebAssembly and fails if a panic path is linked into the release build. An async loop works in Embassy as it is.
Why are readings not floating-point numbers?
A meter reading is evidence for an invoice. sml-kit keeps every value as an exact integer with a decimal exponent and its unit, exactly as the meter sent it, so 15338555.7 Wh stays 15338555.7 Wh. Convert to a float at the edge of your application if you need one.
Are readings authenticated?
No. The CRCs detect transmission errors, not forgery, and sml-kit exposes SML signatures as bytes without verifying them. Treat readings from a channel others can reach as untrusted.