Module ocpi

ballerinax/ocpi Ballerina library

1.5.1

Overview

This is a generated connector for Open Charge Point Interface(OCPI) v2.2 OpenAPI specification.

The Open Charge Point Interface (OCPI) enables a scalable, automated EV roaming setup between Charge Point Operators and e-Mobility Service Providers. It supports authorization, charge point information exchange (including live status updates and transaction events), charge detail record exchange, remote charge point commands and the exchange of smart-charging related information between parties.

Prerequisites

Before using this connector in your Ballerina application, complete the following:

  • Obtain your Open Charge Network(OCN) node endpoint URL that is based on OCPI v2.2 specification.
  • Obtain tokens
    1. Follow this link to get OCPI specification detail for authorization and obtain tokens according to your OCN.

Quickstart

To Learn more on OCN, Follow this link or you can refer this link to learn how to test a local OCN. To use the OCPI connector in your Ballerina application, update the .bal file as follows: Follow the following steps to create a simple sample.

Step 1 - Import connector

Copy
import ballerinax/ocpi;

Step 2 - Create a new connector instance

Copy
ocpi:Client baseClient = check new ocpi:Client(serviceUrl = "<OCN node URL>");

Step 3 - Invoke connector operation

  1. Get health status of the OCN node
Copy
string response = check baseClient->getHealth();
  1. Get the ID of the node, Follow this link for more details.
Copy
json response = check baseClient->getMyNodeInfo();

Note: To Add a party to the OCN registry, Use below command if you test the connector using your locally configured OCN Follow this link for more information

    //This should be done using the command line interface 
    // Adding the party to the OCN registry
    // Execute the following in the command line
    //
    // ocn-registry set-party --credentials DE MSP \
    // --roles EMSP \
    // --operator <Operator ID> \
    // --signer <Signer token>
  1. Request a token A
Copy
string authorization = string `Token ${admin_API_key}`;
ocpi:BasicRole[] payload = [
    {
        country_code: "<Country code>",
        party_id: "<Party ID>"
    }
];
json response = check baseClient->generateRegistrationToken(authorization, payload);
  1. Request versions
Copy
string credentials_tokenA = "<Provide_your_credentials_token_A>";
string authorization = string `Token ${credentials_tokenA}`;
cpi:OcpiResponseListVersion response = check baseClient->getVersions(authorization);
  1. Request version details
Copy
string credentials_tokenA = "<Provide_your_credentials_token_A>";
string authorization = string `Token ${credentials_tokenA}`;
ocpi:OcpiResponseVersionDetail response = check baseClient->getVersionsDetail(authorization);
  1. The credentials handshake
Copy
string credentials_tokenA = "<Provide_your_credentials_token_A>";
string authorization = string `Token ${credentials_tokenA}`;
ocpi:Credentials credentials = {
        token: "<Token>",
        url: "<URL>",
        roles: [
            {
                country_code: "<Country Code>",
                party_id: "<Party ID>",
                role: "<Role>",
                business_details: {
                    name: "<Name>"
                }
            }
        ]
    };
ocpi:OcpiResponseCredentials response = check baseClient->postCredentials(authorization, credentials);

This Completes the registration to the OCN Node, Now you are ready to send requests to other parties on the network

  1. Fetch a list of one of the CPO's locations
Copy
string credentials_tokenC = "<Provide_your_credentials_token_C>";
string authorization = string `Token ${credentials_tokenC}`;
string xRequestId = "1";
string xCorrelationId = "1";
string ocpiFromCountryCode = "<From Country Code>";
string ocpiFromPartyId = "<From Party ID>";
string ocpiToCountryCode = "<To Country Code>";
string ocpiToPartyId = "<To Party ID>";
ocpi:OcpiResponseLocationList response = check baseClient->getLocationListFromDataOwner(
    authorization, xRequestId, xCorrelationId, ocpiFromCountryCode, ocpiFromPartyId, ocpiToCountryCode, ocpiToPartyId);
  1. Get an array of tariffs provided by the CPO, with IDs matching those found on the Connector object.
Copy
string credentials_tokenC = "<Provide_your_credentials_token_C>";
string authorization = string `Token ${credentials_tokenC}`;
string xRequestId = "1";
string xCorrelationId = "1";
string ocpiFromCountryCode = "<From Country Code>";
string ocpiFromPartyId = "<From Party ID>";
string ocpiToCountryCode = "<To Country Code>";
string ocpiToPartyId = "<To Party ID>";
ocpi:OcpiResponseTariffList response = check baseClient->getTariffsFromDataOwner(authorization, xRequestId, xCorrelationId, ocpiFromCountryCode, ocpiFromPartyId, ocpiToCountryCode, ocpiToPartyId);
  1. Tell the CPO a driver on the eMSP system wishes to start a session remotely.
Copy
string credentials_tokenC = "<Provide_your_credentials_token_C>";
string authorization = string `Token ${credentials_tokenC}`;
string xRequestId = "1";
string xCorrelationId = "1";
string ocpiFromCountryCode = "<From Country Code>";
string ocpiFromPartyId = "<From Party ID>";
string ocpiToCountryCode = "<To Country Code>";
string ocpiToPartyId = "<To Party ID>";
ocpi:StartSession startSession = {
    response_url: "<Response URL>",
    token: {
        country_code: "<Country Code>",
        party_id: "<Party ID>",
        uid: "<UID>",
        'type: "APP_USER",
        contract_id: "<Contract ID>",
        issuer: "<Issuer>",
        valid: true,
        whitelist: "ALWAYS",
        last_updated: "<Last Update date/time>"
    },
    location_id: "<Location ID>"
};
ocpi:OcpiResponseCommandResponse|error response = baseClient->postStartSession(authorization, xRequestId, xCorrelationId, ocpiFromCountryCode, ocpiFromPartyId, ocpiToCountryCode, ocpiToPartyId, startSession)
  1. Tell the CPO a driver on the eMSP system wishes to stop a session remotely. For more information, Follow this link
Copy
string credentials_tokenC = "<Provide_your_credentials_token_C>";
string authorization = string `Token ${credentials_tokenC}`;
string xRequestId = "1";
string xCorrelationId = "1";
string ocpiFromCountryCode = "<From Country Code>";
string ocpiFromPartyId = "<From Party ID>";
string ocpiToCountryCode = "<To Country Code>";
string ocpiToPartyId = "<To Party ID>";
ocpi:StopSession stopSession = {
    "response_url": "<Response URL>",
    "session_id": "<Session ID>"
};
ocpi:OcpiResponseCommandResponse response = check baseClient->postStopSession(authorization, xRequestId, xCorrelationId, ocpiFromCountryCode, ocpiFromPartyId, ocpiToCountryCode, ocpiToPartyId, stopSession);

Use bal run command to compile and run the Ballerina program.

Import

import ballerinax/ocpi;Copy

Metadata

Released date: 12 months ago

Version: 1.5.1

License: Apache-2.0


Compatibility

Platform: any

Ballerina version: 2201.4.1

GraalVM compatible: Yes


Pull count

Total: 0

Current verison: 0


Weekly downloads


Source repository


Keywords

IT Operations/Cloud Services

Cost/Free


Contributors

Other versions

See more...