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.Executorspawns the background read loop and per-handler tasks;Timerdrives request/ping timeouts. Both are dyn-safe (boxed-future style) soClient<E>stays generic over one type parameter only, the same wayTransportSink/TransportStreamare already boxed instead of threaded through as generics.tokio-runtime(seeruntime::tokio) provides the default std impls; embedded users supply their own (e.g. backed byembassy-executor/embassy-time).
Structs§
- Client
- The OCPP client engine, generic over one version’s protocol error type.
OCPP1_6ClientandOCPP2_0_1Clientare justClient<OCPP1_6Error>/Client<OCPP2_0_1Error>- the dispatch/timeout/error machinery below is written once and shared by every version. - Connect
Options - Reconnect
Policy - Bounded exponential backoff between reconnect attempts. The delay doubles (by
multiplier) after each failed attempt, capped atmax_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§
- Client
Error - 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. - Negotiated
Client - A
Clientfor whichever OCPP version the server actually picked when connecting viaconnect. Which variants exist depends on whichocpp_1_6/ocpp_2_0_1/ocpp_2_1features are enabled, same as the version-specificconnect_*functions. - Ocpp
Version - An OCPP version
connectcan offer/accept. Only variants for features enabled in this build exist, same asNegotiatedClient’s variants. - Reconnect
Behavior - Whether a
connect_*call should reconnect automatically on disconnect. Defaults toEnabledwithReconnectPolicy::default()- production charge points are expected to keep retrying the CSMS connection, so that’s the out-of-the-box behavior; setConnectOptions::reconnecttoDisabledto opt out. - Transport
Event - 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_pingpossible without the generic client knowing anything WebSocket-specific.
Traits§
- Action
- One OCPP action: its wire name plus its request/response types.
- Protocol
Error - Implemented once per OCPP version by that version’s error enum (
OCPP1_6Error,OCPP2_0_1Error, …), so the genericcrate::Clientengine 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::recvreturningOk(None)orErr(_)). - Transport
Sink - The write half of a transport: sends one complete OCPP-J text frame at a time.
- Transport
Stream - The read half of a transport: yields one
TransportEventat a time, orNonewhen the other side closed the connection.
Functions§
- connect
- Connect to an OCPP server over WebSocket, offering the given
versions(or, ifNone, every version compiled into this crate via itsocpp_1_6/ocpp_2_0_1/ocpp_2_1features) in theSec-WebSocket-Protocolheader, and using whichever one the server picks - rather than requiring the caller to already know the server’s supported version likeconnect_1_6/connect_2_0_1/connect_2_1do.versionsalso 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.
- websocket_
transport - Opens one WebSocket connection to
addressspeakingversion, and hands back the transport halves aReconnectoris required to return - so a custom reconnector can redial without reimplementing this crate’s WebSocket plumbing.
Type Aliases§
- Transport
Error - A transport-agnostic boxed error, so
TransportSink/TransportStreamstay dyn-safe regardless of what’s underneath (WebSocket today, a framed serial link later).