ocpp-kit

OCPP 1.6J · 2.0.1 · 2.1

The Open Charge Point Protocol,
done properly in Rust.

Typed messages for all 194 actions, a sans-I/O protocol engine, and production transports for charging stations, CSMS backends and local controllers — with the version differences modelled rather than averaged away.

cargo add ocpp-kit --features tokio,rustls

Five layers. You pay for what you use.

Typed messages

All 39 / 64 / 91 actions for 1.6J, 2.0.1 and 2.1, generated from the official OCA JSON schemas and checked back against them on every CI run.

Layer 0 →

OCPP-J framing

CALL, CALLRESULT, CALLERROR, plus 2.1’s CALLRESULTERROR and SEND — with the error codes each version actually spells.

Layer 1 →

Sans-I/O engine

A pure state machine: no socket, no clock, no tasks. Every timing rule in OCPP is testable in microseconds, on Tokio, on embassy or in WebAssembly.

Layer 2 →

Transport

Charging station, CSMS and Part 4 chapter 6 local controller, on Tokio and rustls, with security profiles 0 (1.6 only) to 3 and network failover.

Layer 3 →

Domain blocks

Device model, transaction rules, local authorization, composite schedules, and an idempotent CSMS transaction ledger. Components, not a framework.

Layer 4 →

The vocabulary

Security events with their criticality, 74 standardized components, 458 variables and the standardized reason codes — extracted from the specification, not transcribed.

Catalogues →

A charging station, end to end

use ocpp_kit::transport::{BasicAuthPassword, ClientTls, Handler, SecurityProfile, Station};
use ocpp_kit::{Version, v2_1};

async fn boot(handler: impl Handler) -> Result<(), Box<dyn std::error::Error>> {
    let handle = Station::builder()
        .identity("CS-0001")?
        .url("wss://csms.example.com/ocpp")
        // Part 4 §3.2 recommends that a 2.1 station also offer 2.0.1.
        .versions([Version::V2_1, Version::V2_0_1])
        .security_profile(SecurityProfile::TlsBasicAuth)
        .password(BasicAuthPassword::utf8("a-sixteen-plus-character-secret")?)
        .tls(ClientTls::with_webpki_roots()?)
        .handler(handler)
        .build()?
        .spawn()?;

    let boot = handle
        .call(v2_1::BootNotificationRequest::new(
            v2_1::ChargingStation::new("Model-1", "ACME"),
            v2_1::BootReason::PowerUp,
        ))
        .await?;

    println!("{:?}, heartbeat every {}s", boot.status, boot.interval);
    Ok(())
}

What happens without asking

  • The identity becomes the last path segment, as Part 4 §3.1 prescribes.
  • Anything sent before the CSMS accepts the station is queued — B02.FR.02 forbids sending it — and released the moment it does.
  • Reconnects follow the back-off of Part 4 §5.4 and keep the queue, so a reconnect does not repeat BootNotification.
  • Transaction messages are retried on the linear schedule §3.7.1 defines, in chronological order, and queued durably while offline.

Why another OCPP crate

Error codes are exact

OCPP has five distinct codes for five kinds of bad payload, and answering with the wrong one is a conformance failure. A missing member is an OccurrenceConstraintViolation; a string where an integer belongs is a TypeConstraintViolation; on 1.6 a format violation is spelled FormationViolation.

Numbers are exact

Every OCPP number is a decimal mantissa and scale, never an f64. A meter reporting 2935.600 kWh claims three decimals of resolution, and it goes back out as 2935.600; a session’s energy is the exact difference of two registers.

Typed messages →

The billable value

Under calibration law a customer may only be billed for the record the meter signed — which 1.6 hides inside a string and whose public-key field the specification and its own example message disagree about. Both shapes are read, and the record is carried verbatim.

Signed meter values →

The types cannot drift

Every action’s request and response is round-tripped through pseudo-random schema-valid payloads and validated back against the official schema — over 9 000 round trips per test run.

How it is verified →

Compression, because 2.1 requires it

Part 4 §3.4 makes RFC 7692 mandatory for a CSMS. No general-purpose Rust WebSocket crate implements it, so the frame layer is in this crate — checked against an independent implementation and fuzzed.

The WebSocket layer →

Real hardware, not just the spec

The strict default is what the schemas say. A lenient policy additionally accepts offset-less timestamps, numeric strings and undefined enum values — via a repair loop that only runs after a strict parse has failed, and reports every repair it made.

Talking to real hardware →

Runs where the protocol runs

With default features there is no async runtime, no TLS and no domain logic in your binary — just the types, the framing and the engine.