Skip to content

embeddedLance/ArduinoOcpp

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Icon   ArduinoOcpp

OCPP-J 1.6 client for the ESP8266 and the ESP32 (more coming soon)

Reference usage: OpenEVSE

PlatformIO package: ArduinoOcpp

Website: www.arduino-ocpp.com

Full compatibility with the Arduino platform. Need a FreeRTOS version? Please contact me

Make your EVSE ready for OCPP 🚗🔌🔋

You can build an OCPP Charge Point controller using the popular, Wi-Fi enabled microcontrollers ESP8266, ESP32 and comparable. This library allows your EVSE to communicate with an OCPP Central System and to participate in your Charging Network.

✔️ Works with SteVe and The Mobility House OCPP package

✔️ Passed compatibility tests with further commercial Central Systems

✔️ Integrated and tested in many charging stations

Features

  • handles the OCPP communication with the charging network
  • implements the standard OCPP charging process
  • provides an API for the integration of the hardware modules of your EVSE
  • works with any TLS implementation and WebSocket library. E.g.

For simple chargers, the necessary hardware and internet integration is usually far below 1000 LOCs.

Usage guide

Please take examples/ESP/main.cpp as the starting point for your first project. It is a minimal example which shows how to establish an OCPP connection and how to start and stop charging sessions. This guide explains the concepts for a minimal integration.

  • To get the library running, you have to install all dependencies (see the list below). In case you use PlatformIO, you can just add matth-x/ArduinoOcpp to your project using the PIO library manager.

  • In your project's main file, include ArduinoOcpp.h.

  • Before establishing an OCPP connection you have to ensure that your device has access to a Wi-Fi access point. All debug messages are printed on the standard serial (i.e. Serial.print("debug msg")). To redirect debug messages, please refer to src/ArduinoOcpp/Platform.h.

  • To connect to your OCPP Central System, call OCPP_initialize(String OCPP_HOST, uint16_t OCPP_PORT, String OCPP_URL). You need to insert the address parameters according to the configuration of your central system. Internally, the library passes these parameters to the WebSocket object without further alteration.

    • To secure the connection with TLS, you have to configure the WebSocket. Please take examples/ESP-TLS/main.cpp as an example.
  • In your setup() function, you can add the configuration functions from ArduinoOcpp.h to properly integrate your hardware. For example, the library needs access to the energy meter. All configuration functions are documented in ArduinoOcpp.h.

  • Add OCPP_loop() to your loop() function.

Sending OCPP operations

There are a couple of OCPP operations you can initialize on your EVSE. For example, to send a Boot Notification, use the function

void bootNotification(const char *chargePointModel, const char *chargePointVendor, OnReceiveConfListener onConf = nullptr, ...)`

In practice, it looks like this:

void setup() {

    ... //other code including the initialization of Wi-Fi and OCPP

    bootNotification("My CP model name", "My company name", [] (JsonObject confMsg) {
        //This callback is executed when the .conf() response from the central system arrives
        Serial.print(F("BootNotification was answered. Central System clock: "));
        Serial.println(confMsg["currentTime"].as<String>()); //"currentTime" is a field of the central system response
        
        //Notify your hardare that the BootNotification.conf() has arrived. E.g.:
        //evseIsBooted = true;
    });
    
    ... //rest of setup() function; executed immediately as bootNotification() is non-blocking
}

The parameters chargePointModel and chargePointVendor are equivalent to the parameters in the Boot Notification as defined by the OCPP specification. The last parameter OnReceiveConfListener onConf is a callback function which the library executes when the central system has processed the operation and the ESP has received the .conf() response. Here you can add your device-specific behavior, e.g. flash a confirmation LED or unlock the connectors. If you don't need it, the last parameter is optional.

Receiving OCPP operations

The library also reacts on CS-initiated operations. You can add your own behavior there too. For example, to flash a LED on receipt of a Set Charging Profile request, use the following function.

setOnSetChargingProfileRequest([] (JsonObject payload) {
    //...
});

You can also process the original payload from the CS using the payload object.

To get started quickly with or without EVSE hardware, you can flash the sketch in examples/SECC onto your ESP. That example mimics a full OCPP communications controller as it would look like in a real charging station. You can build a charger prototype based on that example or just view the internal state using the device monitor.

Dependencies

In case you use PlatformIO, you can copy all dependencies from platformio.ini into your own configuration file. Alternatively, you can install the full library with dependencies by adding matth-x/ArduinoOcpp in the PIO library manager.

Supported operations

Operation name supported in progress not supported
Core profile
Authorize ✔️
BootNotification ✔️
ChangeAvailability ✔️
ChangeConfiguration ✔️
ClearCache ✔️
DataTransfer ✔️
GetConfiguration ✔️
Heartbeat ✔️
MeterValues ✔️
RemoteStartTransaction ✔️
RemoteStopTransaction ✔️
Reset ✔️
StartTransaction ✔️
StatusNotification ✔️
StopTransaction ✔️
UnlockConnector ✔️
Smart charging profile
ClearChargingProfile ✔️
GetCompositeSchedule ✖️
SetChargingProfile ✔️
Remote trigger profile
TriggerMessage ✔️
Firmware management
GetDiagnostics ✔️
DiagnosticsStatusNotification ✔️
FirmwareStatusNotification ✔️
UpdateFirmware ✔️

Next development steps

  • introduce proper offline behavior and package loss / fault detection
  • handle fragmented input messages correctly
  • add support for multiple power connectors
  • add support for the ESP32
  • reach full compliance to OCPP 1.6 Smart Charging Profile
  • integrate Authorization Cache
  • get ready for OCPP 2.0.1

Further help

I hope this guide can help you to successfully integrate an OCPP controller into your EVSE. If something needs clarification or if you have a question, please send me a message.

✉️ : matthias A⊤ arduino-ocpp DО⊤ com

If you want professional assistance for your EVSE project, you can contact me as well. I'm looking forward to hearing about your ideas!

About

OCPP 1.6 client for ESP32 / ESP8266

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 99.3%
  • C 0.7%