imsys

Run the gateway, administrator and meter

Submit a durable GWA read, recover it after restarting the worker, and backfill an interrupted DLMS meter profile.

gwad administers the gateway and serves the GWA desk. The tools smgw-sim and mme-sim simulate that gateway and its electricity meter.

Open the consoles

From the repository root, after just doctor:

just demo

It builds everything, starts a disposable PostgreSQL, two commissioned gateways with their meters and the desk, and prints three private links. The fixture contains sixteen simulated quarter-hours, one completed read and one pending read.

WorkspaceTry it
mMEOpen Meter register, enter Wh per interval and advance the clock. Consumer display shows completed periods. To restart the four histories, review the meter time and confirm Clear display history.
SMGWGateway status shows the commissioned connections. Pause or resume wake-ups. Open Event journal to follow the callback and meter read.
GWAOpen Read queue → Pending, select the read and choose Dispatch read. Return to the queue after the receipt appears. Reopen the read to inspect its attempts and values in Wh. Use Gateway directory to find a gateway by recipient or name and queue another window.
The GWA desk showing a completed read with its dispatch receipt
Read details: the request, its dispatch receipt and the reservation that reached the meter. The desk follows your light or dark scheme and adapts to a phone.

The meter clock starts at 1970-01-01 00:00 UTC. Each service authorizes its own loopback browser session. Ctrl-C removes the fixtures, keys and database; just demo-down cleans up after a demo that was killed.

Operate a fleet

In Gateway directory, open Demo gateway and Workshop gateway to queue reads against two independently commissioned meters. Both gateways call the same GWA listener. Read details identify the employee who requested the read and who dispatched each attempt. If the revision changes, select Review replacement revision, check the target and reason, then Queue successor read.

If a callback is interrupted, the detail view shows the receipt and its next eligible time. Use the receipt-state filter to find a stopped read. Review the reason before dispatching again. A changed revision requires a successor. Closing the browser leaves an accepted read running.

For an organization deployment, follow the workforce sign-in guide. For a local GWA console, run gwad grant alex dispatcher RECIPIENT or gwad grant sam viewer --all against the initialized database. Give the printed credential to its employee privately. Use it on the sign-in screen at the URL printed by gwad ui ADDR --desk web/desk/dist, after building the desk with just desk. Credentials expire after eight hours. Rerun the grant to rotate access or use gwad revoke alex to end it.

Run the complete exchange

just services

It uses the just db-up database or GWAD_TEST_DATABASE_URL when set, and a disposable PostgreSQL otherwise.

The script builds all three binaries, provisions test credentials and verifies worker recovery, meter backfill and wake-up replay rejection on loopback.

Drive the processes yourself

Build once and provision a fresh fixture directory. The generator refuses to overwrite a previous fixture. Keep the replay database in a private directory and reuse it across gateway restarts.

cargo build --locked -p mme-sim
cargo build --locked -p smgw-sim
cargo build --locked -p gwad -p xtask
just desk
target/debug/xtask gen-pki target/services-pki
mkdir -p -m 700 target/services-state

Run the meter in the first terminal. If port 4059 is occupied, choose a free port and use it in the gateway command too. Its DLMS Profile Generic serves cumulative import energy on OBIS 1-0:1.8.0*255, with quarter-hour reference times, measured times and meter status. The synthetic public-client association uses loopback TCP and a four-second deadline. To read the same meter over SML, add --protocol sml here and --meter-protocol sml to the gateway command.

target/debug/mme-sim --listen 127.0.0.1:4059 --history gap

Run one commissioned gateway in a second terminal. Its arguments select the private gateway bundle, replay database, UDP listen address, GWA callback address and meter address.

target/debug/smgw-sim serve target/services-pki/management/smgw target/services-state/replay.redb \
  127.0.0.1:41001 127.0.0.1:41002 127.0.0.1:4059

Commission the gateway

In a third terminal, open a shell on a disposable PostgreSQL and initialize the catalog. Run the remaining commands in that shell. For a persistent installation, supply your own GWAD_DATABASE_URL instead.

python3 xtask/gwad-postgres.py -- "$SHELL"
target/debug/gwad init

The service-owned policy binds a recipient and bundle handle to an expected peer fingerprint. For this synthetic installation, take the SMGW leaf pin from the PKI generator’s manifest. Keep the policy and its credential directories writable only by the commissioning administrator. Bundle directories are relative to the policy file.

export GWAD_PROVISIONING="$PWD/target/services-pki/provisioning.json"
pin=$(awk '$1 == "management" && $2 == "smgw" { print $5 }' target/services-pki/manifest.tsv)
cat > "$GWAD_PROVISIONING" <<EOF
{"listeners":["127.0.0.1:41002"],"bundles":[
  {"recipient":"0e5453540000000001","handle":"demo","path":"management/gwa","pin":"$pin"}
]}
EOF
cat > target/services-state/gateways.json <<'EOF'
[{"op":"upsert","recipient":"0e5453540000000001","name":"Demo gateway",
  "bundle":"demo","callback":"127.0.0.1:41002","wakeup":"127.0.0.1:41001"}]
EOF
target/debug/gwad inventory preview target/services-state/gateways.json > target/services-state/review.json
cat target/services-state/review.json

Check each recipient, before/after revision, fingerprint and pending-read count. Apply the reviewed file with a unique request ID and reason. Repeat the same command to recover its receipt after a disconnect. A conflict requires a fresh preview. Each manifest can contain up to 500 recipients and 1 MiB of JSON.

target/debug/gwad inventory apply target/services-state/review.json lab-install --reason "Commission demo gateway"
target/debug/gwad inventory receipt lab-install

Submit, run and inspect a read

Submit binds the read to the current active revision, certificate and three-slot quarter-hour window. Run uses the committed route and checks its provisioned identity before sending. Use the ID printed by submit below.

target/debug/gwad submit morning-read 0e5453540000000001 --window-start 0
target/debug/gwad run 1
target/debug/gwad get 1

A successful read prints one RECORD per returned slot. Reuse the submission key to retrieve the same job. Use a new key for another recipient or window. Keys accept 1–128 ASCII letters, digits, dots, underscores and hyphens.

State from getOperator action
pendingFor a one-shot CLI read, run the ID and inspect it after an interruption. For an accepted desk dispatch, follow its receipt. One worker owns the recipient during dispatch. Other recipients can run concurrently with their commissioned callback listeners.
completedRead the committed result. Both get and a repeated run return these exact records without contacting the gateway.
supersededFollow the successor ID to run or inspect the read with its replacement certificate.
failed with ERROR meter-unavailableThe authenticated gateway reported a meter outage. Once the meter is healthy, submit a new key for a fresh read.

An interrupted worker may read the meter twice. PostgreSQL commits the terminal state and records together. Use direct connections or session pooling so the worker holds its recipient lock until disconnect. Remote connections verify the server certificate and hostname. If the clock falls behind the last wake-up timestamp, retry when UTC catches up.

To backfill the quarter-hour yourself, stop mme-sim, restart it on the same address with --history filled, and submit and run a new job. The 900-second slot should contain coefficient 12355 and scale −1, or 1235.5 Wh. Stop the gateway and meter with Ctrl-C.

Replace a pending job after certificate rollover

Provision the replacement bundle and peer pin, then preview and apply the changed manifest. Review its receipt and use the new revision number to supersede the old read. A change to the route also needs review when the certificate stays the same.

target/debug/gwad supersede 1 2 --reason "Scheduled certificate renewal"
target/debug/gwad get 1

The successor keeps the recipient and window. Repeating the same command returns that successor. If dispatch is active, wait for it to finish and review the current state. To retire a recipient, preview an entry such as {"op":"retire","recipient":"0e5453540000000001"} inside a manifest array. Retired gateways and their earlier revisions remain visible to assigned employees. Omitting a recipient leaves its revision in place.

Understand the simulator boundary

The roles and connection direction follow the BSI management workflow. The simulator's GET /simulator/v1/meter-profile exchanges fixture XML over mutually authenticated TLS. The profile is a local diagnostic resource. The separate LMN connection performs the DLMS/COSEM read. BSI operating processes §3.1 · BSI Webservices annex §2.2

Give each daemon its own management credential bundle. Only the GWA bundle contains the wake-up private key. Each TLS endpoint trusts its management root and pins the commissioned peer leaf. The gateway keeps its last successfully read window in memory and retains accepted wake-up timestamps on disk. Run another gateway with its own commissioned identities, listener and replay store when simulating a separate installation. Wake-up policy · Security providers

Measure during a gateway outage

Stop any meter using port 4059 and run cargo run --locked -p mme-sim -- --interactive. The opening register is 1234.0 Wh. With the gateway disconnected, enter:

advance 15
advance 25
usage 0 1800
show

The meter reports 40 deci-Wh of consumption and a final register of 1238.0 Wh. Reconnect the gateway and submit a fresh read job to recover the missing quarter-hours. The service lab commissions the first three slots. The meter itself retains the latest 96 observations and serves each new connection from a consistent snapshot. With this disposable invocation, restarting the meter opens a fresh register.

Run cargo test --locked -p mme-sim --test outage for the automated disconnect and reconnect scenario. Meter API

Read the consumer display

Stop the interactive meter and run cargo run --locked -p mme-sim -- --state target/services-state/meter.sqlite using the private directory created above. This command enables the console and keeps the meter across restarts. From a new database, these commands simulate two years with a uniform increment of 0.1 Wh per quarter-hour.

advance 1 35040
display year
advance 1 35040
display year 2

Both annual queries report dwh=35040, or 3.504 kWh. You can stop and restart with the same file between commands. Time advances only when you issue an advance. The console acknowledges a batch after committing its readings. An existing DLMS association keeps its snapshot until reconnect.

CommandPeriodOldest available age after two years
display day24 powered hours730
display week7 powered days104
display month30 powered days24
display year365 powered days2

Age 1 selects the newest complete period. On day eight the latest week spans the end of day one through the end of day eight. A query before the first complete period returns unavailable. A completed period with no usage returns zero. The import display follows the publicly documented May 2018 FNN Basiszähler v1.4.1 profile. FNN profile, pp. 63–64 · MsbG § 61(3)