Skip to main content

Crate ocpp_client

Crate ocpp_client 

Source
Expand description

OCPP client (charge point side) protocol implementation.

The engine (Client<E>, Action, Transport{Sink,Stream}) is shared by every OCPP version; OCPP1_6Client/OCPP2_0_1Client are just that engine parameterized with each version’s error type. See CLAUDE.md for the broader architecture/roadmap.

Re-exports§

pub use runtime::Elapsed;
pub use runtime::Executor;
pub use runtime::Timer;
pub use runtime::tokio::TokioExecutor;
pub use runtime::tokio::TokioTimer;
pub use ocpp_types;
pub use rustls;

Modules§

ocpp_1_6
ocpp_2_0_1
ocpp_2_1
runtime
Runtime abstraction so the engine (Client<E>) doesn’t hard-depend on tokio. Executor spawns the background read loop and per-handler tasks; Timer drives request/ping timeouts. Both are dyn-safe (boxed-future style) so Client<E> stays generic over one type parameter only, the same way TransportSink/TransportStream are already boxed instead of threaded through as generics. tokio-runtime (see runtime::tokio) provides the default std impls; embedded users supply their own (e.g. backed by embassy-executor/embassy-time).

Structs§

Client
The OCPP client engine, generic over one version’s protocol error type. OCPP1_6Client and OCPP2_0_1Client are just Client<OCPP1_6Error> / Client<OCPP2_0_1Error> - the dispatch/timeout/error machinery below is written once and shared by every version.
ConnectOptions
ReconnectPolicy
Bounded exponential backoff between reconnect attempts. The delay doubles (by multiplier) after each failed attempt, capped at max_delay - but the number of attempts itself is unbounded: a charge point should keep trying to reach its CSMS indefinitely rather than giving up after N tries.

Enums§

ClientError
Everything that can go wrong sending or receiving a single OCPP action, flattened into one type instead of the Result<Result<Response, ProtocolError>, Box<dyn Error>> shape.
NegotiatedClient
A Client for whichever OCPP version the server actually picked when connecting via connect. Which variants exist depends on which ocpp_1_6/ocpp_2_0_1/ocpp_2_1 features are enabled, same as the version-specific connect_* functions.
OcppVersion
An OCPP version connect can offer/accept. Only variants for features enabled in this build exist, same as NegotiatedClient’s variants.
ReconnectBehavior
Whether a connect_* call should reconnect automatically on disconnect. Defaults to Enabled with ReconnectPolicy::default() - production charge points are expected to keep retrying the CSMS connection, so that’s the out-of-the-box behavior; set ConnectOptions::reconnect to Disabled to opt out.
TransportEvent
One thing read off a transport: a complete OCPP-J text frame, or a protocol-level keepalive event. Carrying ping/pong through the abstraction (rather than hiding it entirely inside the WebSocket adapter) keeps send_ping/on_ping possible without the generic client knowing anything WebSocket-specific.

Traits§

Action
One OCPP action: its wire name plus its request/response types.
ProtocolError
Implemented once per OCPP version by that version’s error enum (OCPP1_6Error, OCPP2_0_1Error, …), so the generic crate::Client engine can build and read CALLERROR payloads without knowing which version it’s carrying.
Reconnector
(Re-)establishes a transport connection from scratch. Called by Client’s background read loop after the current transport reports it closed (TransportStream::recv returning Ok(None) or Err(_)).
TransportSink
The write half of a transport: sends one complete OCPP-J text frame at a time.
TransportStream
The read half of a transport: yields one TransportEvent at a time, or None when the other side closed the connection.

Functions§

connect
Connect to an OCPP server over WebSocket, offering the given versions (or, if None, every version compiled into this crate via its ocpp_1_6/ocpp_2_0_1/ocpp_2_1 features) in the Sec-WebSocket-Protocol header, and using whichever one the server picks - rather than requiring the caller to already know the server’s supported version like connect_1_6/connect_2_0_1/connect_2_1 do. versions also controls preference order (offered in the slice’s order); the choice among the offered set is entirely the server’s per RFC 6455.
connect_1_6
Connect to an OCPP 1.6 server over WebSocket.
connect_2_0_1
Connect to an OCPP 2.0.1 server over WebSocket.
connect_2_1
Connect to an OCPP 2.1 server over WebSocket.

Type Aliases§

TransportError
A transport-agnostic boxed error, so TransportSink/TransportStream stay dyn-safe regardless of what’s underneath (WebSocket today, a framed serial link later).