openadr 0.11.1

OpenADR 3.1 in Rust: VTN server, VEN runtime, typed client and an open conformance suite
Documentation

openadr

OpenADR 3.1 in Rust — a VTN server, a VEN runtime, a typed client and an open conformance suite, in one crate sliced with Cargo features and one binary.

OpenADR is how utilities and grid operators ask flexible load to move: dynamic prices, capacity limits, curtailment. A VTN publishes programmes and events; a VEN — a charge point, a battery, a heat pump — reads them, acts, and reports back.

Documentation · Getting started · What OpenADR is · API reference

Quickstart

$ brew install hupe1980/tap/openadr
$ openadr dev
  VTN        http://127.0.0.1:3000/openadr3/3.1.0   (in memory — gone when you stop it)
  Inspector  http://127.0.0.1:3000/_inspect#…
  Clients    bl-1 (business logic) · ven-1 (VEN)
  Seeded     dynamic-price   24 h price curve, rolls forward every 15 minutes
             capacity-limit  an event in 2 minutes, and one for feeder-7 that ven-1 cannot see

In another terminal:

$ source .openadr-dev.env
$ openadr get events
$ openadr watch events                      # prints only when something changes
$ openadr trigger event                     # a capacity limit one minute out; also cancel, report
$ openadr conformance --report report.html  # 52 checks, as a page you can send
$ cargo run --features ven --example ven    # a VEN reading the curve (from a checkout)

The inspector shows the timeline against now, which events the VEN can and cannot see — asked of the VTN with the VEN's own credential — and every delivery. Errors end with the openadr explain command that describes them. CI holds this quickstart to under 60 seconds.

Features

  • Object privacy holds on every path. One Access value decides visibility for REST reads, webhook delivery and MQTT topic routing, inside the SQL query. On a broker the VTN answers the authorization callback, so one VEN cannot subscribe to another's topic.
  • Durable notifications. Notifications are written to an outbox in the same transaction as the object, delivered by a leased dispatcher, with dead letters you can query and retry, and a circuit breaker for subscribers that stop answering.
  • Interoperability is measured. openadr conformance runs 52 black-box checks against any VTN, each citing the sentence it tests; 51 are proven able to fail against deliberately broken VTNs. It writes an HTML report and a badge, runs in your CI as a GitHub Action, and runs weekly here against another implementation's current release.
  • Exact values and schedules. Prices use decimal arithmetic, and a value JSON cannot carry exactly is refused, never rounded. Timestamp preserves nanoseconds, and StartTime::Now and Duration::Forever represent the protocol’s scheduling sentinels.
  • Polling is the normal case, with ETag on every read. Push over webhooks and MQTT wakes the VEN loop, which re-reads from the VTN: a broker can cost a VEN latency, never correctness.
  • Microcontroller to cloud. The wire model, payload schema and domain core are no_std + alloc (thumbv7em-none-eabihf, wasm32). One binary on SQLite, or many on PostgreSQL. No system C library to install; cargo deny passes, with two documented exceptions in test and build tooling and none in the crate.

Install

$ brew install hupe1980/tap/openadr                  # the binary (macOS arm64, Linux)
$ docker run --rm -p 127.0.0.1:3000:3000 ghcr.io/hupe1980/openadr dev --listen 0.0.0.0:3000 --ephemeral
$ cargo install openadr --features vtn,client,internal-auth,sqlite,conformance

$ cargo add openadr --no-default-features -F std    # model + schema + core only
$ cargo add openadr --features vtn,postgres          # the server
$ cargo add openadr --features ven                   # the VEN loop, on top of the client
$ cargo add openadr --features conformance           # measure any VTN

Features: std and tls-ring (default) · jiff · client · ven · conformance · vtn · sqlite · postgres · internal-auth · external-auth · webhook · webhook-signature · mqtt · mdns · tls. CI builds each feature separately and tests the all-features configuration. See Embedding and no_std.

Rust 1.88 or later; sqlite and postgres need 1.94. Without default features the crate depends on serde, serde_json, jiff, rust_decimal, rust_decimal_macros and thiserror only, and a test keeps it that way. Drop -F std for no_std.

For a VEN using AWS-LC, see TLS provider selection.

A durable VTN

$ openadr vtn --database ./openadr.sqlite \
      --client-hashed "bl-1:$(openadr hash-secret "$BL_SECRET"):bl"

Every endpoint, an OAuth2 client-credentials grant with Argon2id-hashed secrets, object privacy, a notification outbox, GET /metrics and GET /openapi.json. A postgres:// URL makes it the multi-instance deployment; --tls-cert/--tls-key serve HTTPS directly. See Running a VTN.

A VEN

let ven = VenRuntime::with_meter(client, config, HouseMeter);
ven.register().await?;                     // idempotent, and checks the VTN's clock

loop {
    ven.sync().await?;                     // conditional: a quiet cycle is a 304
    if let Some(segment) = ven.active_at(ven.now()) {
        act_on(&segment.payloads);         // priority already resolved
    }
    ven.submit_due_reports().await?;       // each window filed exactly once
    ven.wait_for_work().await;             // or a push notification, whichever comes first
}

See the VEN runtime and the domain core.

Layout

Module Feature Contents
model always (no_std) wire types, validated newtypes, spec sentinels, profile adapters
schema always (no_std) the Alliance's six enumeration files, generated
core always (no_std) interval expansion, timelines, object privacy, report scheduling
webhook webhook-signature (no_std) the webhook signature scheme — signing and verifying
discovery always (socket behind mdns) finding a local VTN over mDNS/DNS-SD
client client BL and VEN HTTP clients, role-checked at compile time
ven ven the VEN loop: registration, conditional sync, timeline, reports
mqtt mqtt this crate's MQTT 3.1.1 client
conformance conformance the black-box suite, its HTML report and badge
vtn vtn axum server: storage, auth, handlers, outbox, caching, metrics, inspector
vtn::store sqlite, postgres in-memory, SQLite and PostgreSQL behind one tested trait

Status

Pre-1.0 breaking changes are listed in CHANGELOG.md. For the Rust API, Cargo features, compiler floor and scriptable CLI, see Compatibility.

Integration tests exercise PostgreSQL, Keycloak, MQTT, TLS and mDNS. Tests or conformance checks cite the sections containing all 34 tracked normative statements. See implementation status and limits.

$ cargo test --all-features
$ cargo xtask spec-sync && cargo xtask check-model        # the wire model against the pinned spec
$ cargo test --all-features --test interop -- --ignored   # the suite against another VTN

The weekly Interop workflow publishes a dated HTML report and machine-readable JSON for the exact peer image it measured.

Specification

The wire model tracks OpenADR 3.1.0, accepting 3.1.1's clarified resource bodies. Peers that bend the schema get explicit, tested adapters (ClientBuilder::adapter) rather than looser types. Every ambiguity and departure is in Reading the specification.

The specification is published by the OpenADR Alliance, free with registration. Its OpenAPI document and enumeration files are Apache-2.0: the VTN serves a transcoded copy of the first, and schema is generated from the second, both attributed. The Definition and User Guide are the Alliance's copyright and are not redistributed. cargo xtask spec-sync fetches the public mirror at the commit spec.lock pins. This project is independent of the Alliance.

Contributing

The most useful thing to send is a disagreement found by running openadr conformance against a real VTN — see CONTRIBUTING.md. Vulnerabilities: SECURITY.md.

Licence

Apache-2.0 OR MIT, at your option.