#ocpp #oca #charger #ocpp16 #eletric-vehicle

ocpp_rs

Protocol implementation for Open Charge Point Protocol (OCPP) in Rust

11 releases

0.2.0 Nov 14, 2024
0.1.13 Sep 7, 2024
0.1.12 Aug 10, 2024
0.1.4 Jul 4, 2024

#382 in Data structures

Download history 133/week @ 2024-08-10 6/week @ 2024-08-17 201/week @ 2024-09-07 25/week @ 2024-09-14 29/week @ 2024-09-21 6/week @ 2024-09-28 1/week @ 2024-10-05 100/week @ 2024-11-09 26/week @ 2024-11-16 3/week @ 2024-11-23

129 downloads per month

MIT license

130KB
2K SLoC

OCPP-RS

OCPP-RS is a Rust library for implementing the Open Charge Point Protocol (OCPP) in Rust.

it currently supports OCPP 1.6.

Documentation

  • Full implementation of OCPP 1.6 Protocol
  • Currently most feature complete implementation of OCPP 1.6 in rust
  • Batteries included, serialization and deserialization is provided here
  • No_std, should work fine on embedded devices that allow heap allocation with a global allocator
  • Inspired by a python ocpp library

Usage

In Cargo.toml, add the following dependency:

[dependencies]
ocpp-rs = "^0.2"

Particularities

Since the original OCPP 1.6 protocol does not contain a type field for CallResult, when parsing CallResultlt, you need to handle Special cases where JSON payloads are ambiguous, like empty objects like: {}, these might get serialized as a EmptyResponse instead of the variant you are waiting for like GetConfiguration.

Look at this file to see how to properly handle CallResults: example

Example

Receiving a payload from a client:

use ocpp_rs::v16::parse::{self, Message};
use ocpp_rs::v16::call::{Action, Call};

// Example incoming message
let incoming_text = "[2, \"19223201\", \"BootNotification\", { \"chargePointVendor\": \"VendorX\", \"chargePointModel\": \"SingleSocketCharger\" }]";
let incoming_message = parse::deserialize_to_message(incoming_text);
if let Ok(Message::Call(call)) = incoming_message {
    match call.payload {
        Action::BootNotification(_boot_notification) => {
            // Do something with boot_notification
        }
        _ => {
            // Handle other actions
        }
    }
}

Sending a payload to a client:

let response = Message::CallResult(CallResult::new(
    "1234".to_string(),
    ResultPayload::StartTransaction(call_result::StartTransaction {
        transaction_id: 0,
        id_tag_info: IdTagInfo {
            status: ocpp_rs::v16::enums::ParsedGenericStatus::Accepted,
            expiry_date: None,
            parent_id_tag: None,
        },
    }),
));

let json = parse::serialize_message(&response)?;
println!("Sending to client: {}", json);

Dependencies

~2.8–3.5MB
~75K SLoC