Experiment
Codetics OCPP
OCPP 1.6, 2.0.1 and 2.1 implemented in Rust, with a CSMS service on top.
Context
An engineering project in which Codetics implemented the Open Charge Point Protocol in Rust from the specification: every message of three protocol versions as plain Rust types, its own WebSocket stack, and a Charging Station Management System service built on these crates.
- Context
- Charging station management systems keep thousands of long-lived WebSocket connections open, exchange strictly specified JSON messages and trigger physical actions. It is the kind of workload where Rust's guarantees are directly useful.
- Problem
- Explore how far a type-driven Rust design can take protocol correctness and concurrency, without relying on an OCPP library or code generation.
- Technical challenge
- Three protocol versions with hundreds of message types, version-specific error spellings, security profiles with TLS and client certificates, and many concurrent connections.
Engineering approach
- 01
A version-independent core crate: RPC framing (CALL, CALLRESULT, CALLERROR, CALLRESULTERROR, SEND), error codes, RFC 3339 timestamps, constraint validation and subprotocol negotiation.
- 02
One independent crate per protocol version, with every message written by hand as a typed, validated Rust structure.
- 03
A dedicated WebSocket crate implementing RFC 6455 framing and RFC 7692 permessage-deflate compression.
- 04
A CSMS service with TLS security profiles 1 to 3, smart charging, reservations, tariffs and cost calculation, PostgreSQL storage through SQLx and an Axum HTTP API.
- 05
Version handlers that are independent from each other and share only version-neutral logic.
Architecture
- 01
Charging stations
OCPP-J 1.6, 2.0.1 and 2.1 clients
- 02
codetics-ocpp-ws
RFC 6455 WebSocket with RFC 7692 compression
- 03
Version crates
Every message as typed, validated Rust
- 04
CSMS service
Sessions, smart charging, reservations, tariffs
- 05
PostgreSQL · HTTP API
SQLx storage and an Axum API


