Wallbox Integration
In order to register a Wallbox charger, you need to:
- Initialize SDK client.
- Log in to Wallbox account.
- Get the list of Wallbox chargers associated to the account.
- Register a charger.
- Get devices list.
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: Log In to Wallbox Account
Let the users log into their Wallbox account by providing email and password:
const handleWallboxLogin = async (username: string, password: string) => {
// ...
await client.registerWallboxAccount(username, password);
// Get the list of Wallbox chargers
};
Step 3: Get the List of Wallbox Chargers Asociated to the Account
After successful log in, a list of Walbox chargers associated to user account should be retrieved in order to let the user select which Wallbox charger should be added to Hiven:
const getWallboxChargers = async (username: string, password: string) => {
// ...
await client.getWallboxChargers();
// Display them in UI and let user select the one which should be added to Hiven
};
Step 4: Register a Charger
Register a charger by sending its name and other parameters to the API.
vendor- should always equal toChargerManufacturer.WALLBOXvendorDeviceId- id of the device user chose to be added to HivenautoSetupOCPPConnection- boolean indicating whether Hiven should modify OCPP Connection values in the user's account, so that no manual action is needed from user after adding charger to the system
If set to false, users have to manually set OCPP Url and Charger Point Identity values in their Wallbox accounts.
import { ChargerManufacturer } from '@hiven-energy/hiven-client';
const handleRegisterCharger = async (id: string, name: string) => {
// ...
await client.registerCharger({
name,
vendor: ChargerManufacturer.WALLBOX,
vendorDeviceId: id,
autoSetupOCPPConnection: true,
});
// Start polling for new devices
};
Step 5: 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.
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>;
}