// 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();