Skip to main content

OCPP Charger Integration

In order to register OCPP charger, you need to:

  1. Initialize SDK client.
  2. Register a charger.
  3. Get devices list.
  4. Configure OCPP connection details.

Step 1: Initialize SDK Client

Initialize Client using the Hiven apiUrl (optional, defaults to https://api.hiven.energy) and headersGetter (optional, defaults to async () => ({})) providing custom authorization headers.

import { createClient } from '@hiven-energy/hiven-client';

const client = createClient({
apiUrl: '<apiUrl>',
headersGetter: async () => ({
'X-Api-Key': '<apiKey>',
'X-User-Id': '<userId>',
}),
});

Step 2: Register a Charger

Register a charger by sending its name to the API:

const handleRegisterCharger = async (name: string) => {
// ...
await client.registerCharger({
name,
});
// Start polling for new devices
};

Step 3: Get Devices List

As soon as 200 response is received after registering charger, the charger should already be added.

Validate it by fetching the list of chargers:

client.getDevicesList(userId: string, options?: Options);

Important note: The userId is a unique identifier of a user in your system. Read more here.

Important note[2]: Hiven stores access and refresh tokens in Hiven Backend, so you don't have to worry about it.

Step 4: Configure OCPP Connection Details

After a charger is added to Hiven to make it operational, OCPP connection details (Charge Point Identity, Charge Point URL and Password) have to be added to the charger's configuration in an Admin Panel of charger's manufacturer.

Charge Point Identity

Charge Point URL can be retrieved from the device object by reading attributes.externalId:

import { Charger } from '@hiven-energy/hiven-client';

const getOCPPChargePointIdentity = (device: Charger) => device.attributes.externalId;

An example value is:

xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Charge Point URL

Charge Point URL can be retrieved by combining the URL address of the OCPP server (SteVe currently) and Charge Point Identity.

To retrieve the URL address of the OCPP server:

import { Charger } from '@hiven-energy/hiven-client';

const getOCPPServerUrl = async (device: Charger) => {
const { url } = await client.getSteveUrl();

return `${url}/${getOCPPChargePointIdentity(device)}`;
};

An example value is:

wss://steve.hiven.energy/steve/websocket/CentralSystemService/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Password

Password field should be ignored.

After configuring these 3 fields - the charger is ready to be used for Smart Charging.

Options parameter

Every SDK method is shipped with an optional options?: Options parameter which allows to overwrite any header, set in the headersGetter function during client creation:

interface Options {
headers: Record<string, any>;
}