Skip to navigation

Quickstart

Put two virtual chargers online against your CSMS and wait until they connect.

You need an OCPPLab token and the WebSocket URL of your CSMS.

Set it up with your coding agent
Add the OCPPLab SDK to this project and put two virtual chargers online against my CSMS. Follow the [OCPPLab quickstart](https://docs.ocpplab.io/get-started/quickstart) step by step, in this project’s language (TypeScript or Python). Read the token from the `OCPPLAB_TOKEN` environment variable and the CSMS URL from `CSMS_WS_URL`; never write either into a file.
1

Install the SDK

npm i ocpplab
2

Set your token and CSMS URL

Generate a token in Studio under Settings → SDK tokens. It is shown once.

export OCPPLAB_TOKEN="<token>"
export CSMS_WS_URL="wss://csms.example.com/ocpp"
3

Deploy the chargers

The script creates a location with two chargers, then polls their deployment stage until both are online.

// Put virtual chargers online against your CSMS, then wait until they connect.
//
// export OCPPLAB_TOKEN="<api-key>"
// export CSMS_WS_URL="wss://csms.example.com/ocpp"
// npx tsx examples/quickstart.ts
//
// Creating a location returns 202 at once; the chargers deploy in the background,
// so this polls their deployment stage until every one is online.
import { OcpplabSDK } from "ocpplab";
const IDENTITIES = ["DEMO-CP-001", "DEMO-CP-002"];
async function main(): Promise<void> {
// Defaults to https://api.ocpplab.io; pass baseUrl for another host.
const client = new OcpplabSDK({ token: process.env.OCPPLAB_TOKEN! });
const accepted = await client.evcharger.location.create({
name: "Demo hub",
address: "1 Parvis de la Defense",
city: "Puteaux",
country: "FRA",
coordinates: { lat: 48.892, lng: 2.238 },
chargers: IDENTITIES.map((identity) => ({
identity,
brand_slug: "wallbox",
model: "wallbox-pulsar-plus",
connector_type: "Type2",
ws_url: process.env.CSMS_WS_URL!,
})),
});
console.log(`location ${accepted.location_id}: ${accepted.detail}`);
const deadline = Date.now() + 600_000;
while (true) {
const { items: chargers } = await client.evcharger.deploymentRuntimeOps.status({
identity: IDENTITIES,
});
for (const charger of chargers) {
console.log(charger.identity, charger.stage, charger.outcome, charger.hint ?? "");
}
if (chargers.length > 0 && chargers.every((charger) => charger.stage === "online")) {
return;
}
if (chargers.some((charger) => charger.outcome === "failed" || charger.outcome === "stuck")) {
throw new Error("a charger failed to deploy; see the hint above");
}
if (Date.now() > deadline) {
throw new Error("chargers were not online after 10 minutes");
}
await new Promise((resolve) => setTimeout(resolve, 5_000));
}
}
void main();
4

Run it

npx tsx quickstart.ts

Each poll prints one line per charger, for example DEMO-CP-001 online succeeded. Your CSMS now sees two chargers boot.

Why it polls

Creating a location returns 202 Accepted at once and deploys the chargers in the background. The script calls deploymentRuntimeOps.status (deployment_runtime_ops.status in Python) every 5 seconds until each charger’s stage is online. If a charger’s outcome is failed or stuck, its hint says why. See Long-running operations.

Next steps

  • Choose another charger model: evcharger.catalog.listBrands(), then listModels(brand_slug).
  • Start from one of the 20 ready-made location templates: evcharger.templates.list().
  • Run a charging session: Plug, charge and unplug.