Load profiles and maximum demand
Calculate interval demand with TAF 8, or backfill a meter’s registered history with TAF 15 over DLMS/COSEM, SML or OMS.
Choose the profile by where registration takes place. TAF 8 derives demand at the gateway. TAF 15 captures records that the meter already registered, including their original timestamps, units and status. Both examples run locally. BSI TR-03109-1 v2.0, §§3.2.12–13
Calculate demand with TAF 8
Run cargo run -p smgw-core --example taf8. The register rises from 1,000 Wh to 1,300 Wh in 15 minutes, giving 1,200 W. The next interval adds 200 Wh and averages 800 W. The peak stays at 1,200 W with the time of the first interval’s end.
Commission one import, export or reactive-energy register. Supply the local daily or monthly billing boundaries as UTC seconds. Electricity profiles accept 5- or 15-minute slots. Record the opening balance, then every boundary through the close. The result retains the register’s decimal scale. A scale of −3 uses milliwatt-hours for active energy and milliwatts for demand.
Use Reading::MISSING for an absent endpoint. Both adjacent intervals carry a flagged zero and preserve the existing peak. A permanent fault freezes the peak through the close. The read-only provisional method gives the local average partway through a slot. Archive each completed interval and start the next billing window with its opening reading. TAF 8 API
Backfill meter records with TAF 15
Run cargo run -p smgw-core --example taf15. The meter supplies the second quarter-hour before the first. Importing the first record twice returns Duplicate on the retry. Reading the history yields 300 Wh, then 200 Wh, each with its original meter time.
Commission one electricity or gas OBIS channel, its unit, the meter’s first reference instant, and the number of slots. Gas also supports hourly registration. Use missing() to select slots for a retry and records() to read the captured history in reference-time order. A conflicting record returns an error and the first record stays intact. The host authenticates the meter, stores the completed history, and authorizes delivery. TAF 15 API
Read a DLMS Profile Generic buffer
Run the example from the workspace root. The gateway opens a DLMS association to a synthetic read-only meter, requests a clock range and releases the association. Both peers exchange protocol messages in process.
cargo run --locked -p smgw-lmn --features simulator --example dlms_backfill
Initial read: 2 records, missing slot 900 UTC s
Backfill: 1 inserted, 1 duplicate. Replay: 2 duplicates.
Conflict rejected. Slot 900 retains 1235.5 Wh, measured at 902 UTC s, status 1.
The first response contains slots 0 and 1800. After the meter fills slot 900, the gateway requests 900 through 1800, inclusive. The new row and its exact overlap give separate counts. A later change to the value at 900 rejects that entire read. The original coefficient 12355 and scale −1, source timestamp and status remain available for billing.
Connect a meter reader
| smgw-lmn feature | Entry point |
|---|---|
acquisition (default) | Implement AttributeReader on a bounded meter association. The importer works without an allocator or OS. |
sml | Import SML packed profiles and push readings (below). Works without an allocator or OS. |
mbus | Record authenticated OMS gas telegrams (below). Works without an allocator or OS. |
blocking | Connect over a BudgetedTransport and pass the client to BlockingReader::new(meter_id, &mut client, &mut scratch). |
loopback-client | Read the commissioned meter from smgw-sim over DLMS/COSEM or SML. |
loopback-meter with default features disabled | Serve a snapshot of the mme register from mme-sim over DLMS/COSEM or SML. |
simulator | Run both roles in the backfill example. |
Set the deadline on the underlying transport. Each GET has one APDU byte allowance across all response blocks. The encoded value must also fit both the client response capacity and caller scratch.
On overflow, check requires_reconnect(). Exhausting the APDU allowance retires the association. For a completed value too large for scratch, enlarge the buffer or select fewer slots and retry. A failed read preserves the destination history. Recovery API
Commission the class 7 profile logical name and the class 3 register's OBIS code and unit. Bind the channel to the identity established by the meter association. Configure distinct measurement-time and meter-status capture descriptors when the meter supplies them. With only the standard captured clock, its timestamp supplies both TAF 15 time fields. Supported register units are Wh, varh and uncorrected m³. Source API
Use ClockRange::from_unix to request the missing slots within your window, or ClockRange::new for concrete meter clocks with a known UTC deviation. A single-slot read uses the same instant at both ends. A successful empty response leaves the requested slots available for retry. Clock range API
The importer resolves capture descriptors in the advertised order, supports up to 32 columns, and expands repeated or delta-encoded cells. Each page can contain at most as many rows as the destination has slots. It checks the capture period, complete descriptor list and scaler/unit around each selected buffer read. Invalid clock quality, nonzero fractional seconds, off-grid reference times, conflicting records or a failed closing read all leave the history unchanged. The caller supplies a coherent, authorized meter association and handles storage and delivery. Importer API · DLMS/COSEM kit
Read an SML meter
Most German electricity meters speak SML. Run the loopback example: a meter thread answers three GetProfilePack requests over TCP.
cargo run --locked -p smgw-lmn --features simulator --example sml_backfill
Initial read: 2 records, missing slot 900 UTC s
Backfill: 1 inserted, 2 duplicates.
Conflict rejected: a different record already uses this reference or measurement timestamp. Slot 900 retains 1235.5 Wh, status 1.
Decode each frame with sml-kit (smgw_lmn::sml::protocol) and pass the GetProfilePackResponse to read_profile_pack. Commission an sml::Source: the meter's server ID, the profile's tree_path OBIS, and the register channel. The importer checks the server ID, the profile, the registration period and the register column's unit (Wh, varh or m³). It keeps the column's scaler and each row's status exactly. Every row needs a calendar timestamp inside the requested range. A row stamped with a seconds index has no calendar time, so it is rejected rather than guessed. Any rejected row discards the whole answer. SML importer API
A basic meter only pushes its register with a seconds index. Record the first reading the gateway receives in each slot with capture_reading and a Slot { reference_utc, received_utc } from the gateway's trusted clock. The reception must fall in [reference, reference + period). Push reading API
To run the simulator pair over SML, start the meter with mme-sim --protocol sml and the gateway with smgw-sim serve … --meter-protocol sml. Both consoles show the protocol next to the meter endpoint. just demo commissions one gateway per protocol.
Record an OMS gas meter
Gas meters transmit wireless M-Bus telegrams secured according to OMS. The example decrypts the published OMS Annex N telegrams with their test keys:
cargo run --locked -p smgw-lmn --features mbus --example oms_gas
accepted mode 7 · counter 2739 · 28504.27 m³
rejected replay · message counter did not increase
rejected mode 5 · telegram is not authenticated by an OMS MAC or tag
rejected tamper · verification failed: message authentication code mismatch
history · 1 of 24 hourly slots filled
Open the radio frame with mbus-kit (smgw_lmn::mbus::protocol::wireless::open) and the meter's key. Then pass its application layer to capture_telegram. Only a telegram whose AFL CMAC (mode 7) or CCM tag (mode 10) verified is accepted. Mode 5 and the ELL only encrypt: anyone in radio range can flip plaintext bits through the IV inputs without the key. The importer reads the single instantaneous, storage-0 volume record in m³ that the MAC or tag covers. A record nothing protects is ignored.
To simulate a gas meter in a test, write fresh telegrams with smgw_lmn::mbus::protocol::sim::Telegram: mode 7 or 10 with a rising counter, or mode 5 to check that it is refused. A round trip shows only that writer and decoder agree. The Annex N frames stay the independent evidence.
Store the returned counter in the same transaction as the history and pass it back as last_counter. A counter that does not rise is a replay. Losing it reopens the meter to replays until the next fresh telegram. OMS importer API