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.
On this page
A basic meter's optical interface only pushes. A gateway on the LMN, or a service tool on a meter's sealed interface, also asks: it opens an SML file, reads or writes process parameters, reads profiles such as the logbook, and closes the file. sml-kit types every one of these messages and writes them as well as it reads them.
Send a request file๐
A client never sends a lone request: it sends an SML file, an open request, the requests and a close request. SmlFile writes all of them in one call, each with a transaction ID unique in the file (the file ID's first seven bytes and the message number) and its own CRC:
use sml_kit::{Body, CloseRequest, GetListRequest, OpenRequest, SmlFile, encode_frame, messages};
let bodies = [
Body::OpenRequest(OpenRequest {
codepage: None,
client_id: b"gw-1",
req_file_id: b"F42",
server_id: Some(ServerId::new(meter)),
username: None,
password: None,
sml_version: None,
}),
Body::GetListRequest(GetListRequest {
client_id: b"gw-1",
server_id: Some(ServerId::new(meter)),
username: None,
password: None,
list_name: None,
}),
Body::CloseRequest(CloseRequest { global_signature: None }),
];
let n = SmlFile { file_id: b"F42", messages: &bodies }.write(&mut payload)?;
let len = encode_frame(&payload[..n], &mut wire)?;
port.write_all(&wire[..len])?;A file that does not open first and close last, or has more than 256 messages, is Error::InvalidFile. The meter repeats each request's transaction ID in its answer, so a client finds the answer to its get-list request like this:
let asked = b"F42\x01"; // message 1 of file F42
for message in messages(answer_frame) {
let message = message?;
if message.transaction_id == asked {
// message.body is the GetListResponse, or an Attention if the meter refused
}
}The simulator (sim::Telegram) writes its telegrams through the same SmlFile.
Read a parameter๐
FNN Lastenheft EDL names the parameters an EDL meter answers. Device identification lives under 81 81 C7 82 01 FF:
use sml_kit::{Body, GetProcParameterRequest, Message, NameList, ServerId, Writer};
const DEVICE_ID: &[u8] = &[0x81, 0x81, 0xC7, 0x82, 0x01, 0xFF];
let request = Message {
transaction_id: b"1",
group_no: 0,
abort_on_error: 0,
body: Body::GetProcParameterRequest(GetProcParameterRequest {
server_id: Some(ServerId::new(meter)),
username: None,
password: None,
tree_path: NameList::from_slice(&[DEVICE_ID]),
attribute: None,
}),
};
let mut w = Writer::new(&mut buf);
request.write(&mut w)?; // or put the body in an SmlFile, as aboveThe answer is a tree. Find a parameter by name, one call per level:
if let Body::GetProcParameterResponse(r) = message.body {
let manufacturer = r.tree.child(&[0x81, 0x81, 0xC7, 0x82, 0x03, 0xFF]);
let firmware = r.tree.child(&[0x01, 0x00, 0x00, 0x02, 0x00, 0xFF]);
}A parameter's value is a ProcParValue: a plain value, a period entry, a tupel entry, a time, or a list entry. EDL meters send the signed meter reading 01 00 01 11 00 FF as a list entry (choice 5).
Write a parameter๐
use sml_kit::{ProcParValue, SetProcParameterRequest, SmlValue, Tree};
const INFO: &[u8] = &[0x81, 0x81, 0xC7, 0x8C, 0x01, 0xFF]; // INFO interface on/off
let set = Body::SetProcParameterRequest(SetProcParameterRequest {
server_id: Some(ServerId::new(meter)),
username: None,
password: None,
tree_path: NameList::from_slice(&[INFO]),
tree: Tree::leaf(INFO, ProcParValue::Value(SmlValue::Bool(true))),
});The meter answers with an Attention; attention.description() names standard numbers such as 81 81 C7 C7 FE 02, "insufficient authentication".
Set requests change a meter: tariff, INFO interface, PIN, tamper detection. sml-kit encodes them; the meter decides whether to accept them.
Read the logbook๐
use sml_kit::{GetProfileRequest, Time};
let request = Body::GetProfileListRequest(GetProfileRequest {
server_id: None,
username: None,
password: None,
with_rawdata: None,
begin_time: Some(Time::SecIndex(0)),
end_time: None,
tree_path: NameList::from_slice(&[&[0x81, 0x81, 0xC7, 0x89, 0xE1, 0xFF]]),
objects: None,
details: None,
});Each GetProfileListResponse is one period; its entries yield PeriodEntry values with an exact quantity() and the (unverified) signature.
Read a load profile in one answer๐
Send the same request as Body::GetProfilePackRequest and the meter answers with one GetProfilePackResponse: the column headers (OBIS code, unit, scaler) once, then rows of bare values. quantity puts a row's value together with its column:
use sml_kit::{Body, Obis, messages};
for message in messages(payload) {
if let Body::GetProfilePackResponse(profile) = message?.body {
for row in profile.periods.iter().flatten() {
let a_plus = profile.quantity(&row, Obis::ENERGY_IMPORT);
println!("{} A+ {a_plus:?} status {:#x}", row.val_time, row.status);
}
}
}The specification requires one value per column in every row; a decoded profile that breaks this is Error::ListLength, so a value is never paired with the wrong column.
Build, don't encode๐
Lists, trees and name paths are Seq values: decoded ones parse lazily from the frame, built ones borrow an array. Both behave the same and compare equal, so a simulator or a test builds with the types the decoder returns:
use sml_kit::{ListEntries, ListEntry, Obis, Trees, Unit};
let entries = [
ListEntry::unsigned(Obis::ENERGY_IMPORT, Unit::WH, -1, 123_456_789),
ListEntry::number(Obis::POWER, Unit::W, 0, 1337),
];
let list = ListEntries::from_slice(&entries);unsigned writes Unsigned, number writes Integer. Meters send energy either way (18 of 31 public captures unsigned), and power signed; the decoder accepts both, and SmlValue::as_integer reads either as an exact i128. Packed-profile cells are ProfileValue::new(value).
Credentials๐
SML's only authentication is a user name and password in cleartext, in every request. Every request type prints its password as <redacted> in Debug, and no parser's Debug shows payload bytes, so logging a message never logs a password. Protect the link itself: TLS on the gateway LMN, the seal on a meter's service interface.
Evidence๐
These messages are tested against FNN Lastenheft EDL and TR-03109-1, not against captures: none are public. If you have one, please open an issue.