Skip to main content

Crate openadr

Crate openadr 

Source
Expand description

§openadr — OpenADR 3.1 in Rust

An implementation of the OpenADR 3 demand-response protocol: a VTN server, a VEN runtime and a typed client, over a shared wire model and a deterministic domain core — one crate, sliced with Cargo features.

OpenADR is how a utility asks flexible load to move. A VTN publishes programmes and events; a VEN — a charge point, a battery, a heat pump — reads them, acts, and reports back. Narrative documentation, including an introduction to the protocol itself, is at https://hupe1980.github.io/openadr.

§Layers

ModuleFeatureWhat
modelalways on (no_std + alloc)wire types, newtypes with invariants, spec sentinels
schemaalways onpayload typing from the Alliance enumeration schemas
corealways oninterval expansion, timeline, object privacy, report scheduling
clientclientbusiness-logic and VEN HTTP clients, role-checked at compile time
venventhe VEN loop: registration, event sync, timeline, report scheduling
conformanceconformancea black-box suite that measures any VTN against the specification
vtnvtnaxum VTN server, storage, authentication, the notification outbox
webhookwebhook-signaturethe webhook signature scheme, both ends of it (no_std)
mqttmqttshared MQTT broker transport
discoveryalways on; mdns for the socketfinding a local VTN over mDNS/DNS-SD, both ends

Storage backends are sqlite and postgres; authentication backends are internal-auth and external-auth; push transports are webhook and mqtt. Every flag is read by a cfg. A subscriber can enable webhook-signature or mqtt on its own. TLS roles use the process provider, with a ring fallback when the default tls-ring feature is enabled.

§Serving

use openadr::vtn::{Vtn, store::MemoryStorage};
let vtn = Vtn::builder().storage(MemoryStorage::shared()).build();
vtn.serve("0.0.0.0:3000").await?;

Vtn::builder is a typestate: build() exists only once a storage backend has been given, so a VTN with nowhere to put an event is a compile error. Without an authenticator it serves unauthenticated readers, which is read-only by construction — every write requires a scope, and an anonymous principal holds none.

§Reading a schedule

use openadr::prelude::*;
// Resolve an event's declared timing into absolute windows: inherited periods, the `now`
// sentinel, unbounded durations, and multi-value payloads that subdivide their interval.
let intervals = IntervalExpander::at(Timestamp::now()).expand(event)?;

// Or the whole sequence, including the intervals the event never lists: a tariff that loops
// for ever, and a forecast whose structure is implied by its `intervalPeriod` alone.
let sequence = IntervalExpander::at(Timestamp::now()).sequence(event)?;

core::Timeline then merges a programme’s concurrent events by priority, splitting the loser around the winner so a long price curve resumes when a short curtailment ends. ven::VenRuntime is that loop with registration, conditional polling and reporting around it.

§Spec version

SPEC_VERSION is the release this crate is written from. There is no 3.0 compatibility in the wire model — 3.1 is not backwards compatible with it — and peers that bend the schema are served by request/response adapters at the edge instead (see model::adapt).

§no_std

default-features = false yields a no_std + alloc build containing model, schema and core — the layers an appliance-class VEN needs, and they build for thumbv7em-none-eabihf and wasm32-unknown-unknown. no_std here means no operating system, not no heap: the wire model is Strings and Vecs, so an allocator is assumed.

Modules§

clientclient
HTTP clients for the two roles.
conformanceconformance
A black-box conformance suite for any OpenADR 3.1 VTN.
core
The domain core: deterministic, I/O-free, and shared by the VTN, the VEN and the tests.
discovery
mDNS/DNS-SD discovery of a local VTN.
model
The OpenADR 3.1 wire model.
mqttmqtt
This crate’s MQTT 3.1.1 client, shared by the VTN’s publisher and the VEN’s subscriber.
prelude
Everything a typical user wants in scope.
schema
Payload typing: what values a payload type may carry, and what the specification says it means.
venven
The VEN runtime: registration, event synchronisation, a maintained timeline, and reporting.
vtnvtn
The VTN server.
webhookwebhook-signature
The webhook signature scheme — both ends of it.

Structs§

MissingCryptoProviderclient or external-auth or mqtt or tls or webhook
No application provider was installed and the ring fallback is disabled.

Constants§

DEFAULT_BASE_PATH
Default base path a VTN is mounted under (/openadr3/3.1.0).
SPEC_VERSION
The OpenADR specification release this crate is written from.

Functions§

install_crypto_providerclient or external-auth or mqtt or tls or webhook
Ensure a provider is installed before constructing a TLS transport.