OCPP WS IOocpp-ws-io
OCPP CLI

Project Setup & Generation

Commands for scaffolding projects, generating types, and managing certificates.

ocpp generate

Generates a custom protocol's TypeScript types, the augmentation that declares it to ocpp-ws-io, and its strict-mode validator, all from one JSON schema file, so the types and what strict mode validates always agree.

Usage

ocpp generate [options]

Options

OptionAliasDefaultDescription
--schema-s-Schema URL or local file path.
--name-n-Subprotocol name (e.g. my-custom-protocol).
--out-o./@types/ocpp-ws-ioOutput directory for the generated files.

Example

ocpp generate --schema ./custom-schemas/station.json --name vendor-extensions --out ./src/types

Output

FileWhat it holds
<name>.tsThe request and response types of each action, the SEND messages (unconfirmed, as in OCPP 2.1), and the …Methods and …SendMethods maps. An object the schema leaves open (no additionalProperties: false) takes any JSON keys.
augment.d.tsDeclares the protocol in OCPPMethodMap, and in OCPPSendMethodMap when it has SEND messages, so clients, servers and routes configured with it are typed.
<name>.validator.tsThe strict-mode validator, createValidator("<protocol>", schemas), typed with the protocol.

Schema $ids name the actions: urn:<Action>.req and urn:<Action>.conf (as in OCPP 1.6 and 2.0.1), urn:<Action>Request and urn:<Action>Response (as in OCPP 2.1), and urn:<Message> for a SEND message.

import { OCPPServer } from "ocpp-ws-io";
import { vendorExtensionsValidator } from "./types/vendorextensions.validator.js";

const server = new OCPPServer({
  protocols: ["ocpp2.0.1", "vendor-extensions"],
  strictMode: true,
  strictModeValidators: [vendorExtensionsValidator],
});

Run ocpp generate again when the schemas change: it rewrites all three files together.


ocpp certs

A local TLS Certificate Authority (CA) manager. It helps you generate self-signed certificates for development and testing of secure WebSocket connections (WSS).

Usage

ocpp certs [options]

Options

OptionAliasDefaultDescription
--type-tserverType of certificate to generate: ca, server, or client.
--identity-i-Common Name (CN) for the certificate (e.g., CP-001, localhost).
--out-o./certsOutput directory for generated certificates and keys.

Workflow Example

  1. Generate a Root CA:

    ocpp certs --type ca

    This creates ca.key and ca.crt.

  2. Generate a Server Certificate (signed by CA):

    ocpp certs --type server --identity localhost

    This creates server.key and server.crt.

  3. Generate a Client Certificate (for a Charge Point):

    ocpp certs --type client --identity CP-001

    This creates client.key and client.crt.

On this page