Skip to Content
OCPP WS IOocpp-ws-io

Upgrading to 3.1

What changes from ocpp-ws-io 3.0.x to 3.1.0 — the wildcard handler's one-argument signature, empty OCPP 1.6 payloads, and the protocol proxy, smart charge engine and CLI moving into the package.

3.1.0 is on npm's beta tag until it is released:

npm install ocpp-ws-io

Requirements are those of 3.0: Node.js 20 or later, and TypeScript 5.4 or later to type-check against the package's types.

Breaking changes

ChangeAffects you ifWhat to do
A wildcard handler receives one argument, the context. client.handle((method, ctx) => …) becomes client.handle((ctx) => …), and the action is ctx.method. The same for the browser client and for a route's wildcard handler, whose context still has ctx.client. A handler for a named action is unchangedYou register a wildcard handler with two parametersDrop the first parameter and read ctx.method. TypeScript flags every such handler. In JavaScript, a two-parameter handler gets the context as its first argument and undefined as its second, so code that reads the second fails: look for .handle( calls whose function takes two parameters
client.protocol is undefined when no subprotocol was negotiated (was ""), on a server's clients and on OCPPClient, as the type says and as BrowserOCPPClient already did. This happens only on a server without a protocols list, or for a client that offers noneYou compare client.protocol with ""Compare with undefined, or test !client.protocol
A thrown RPC error's own message and details reach the peer (was the code's standard text, and details only with respondWithDetailedErrors), as in ocpp-rpc. Any other error is still answered InternalError with that code's standard textYour handlers or middleware throw RPC errors whose messages are not meant for the peer, or your peers match on the standard textsThrow with a message written for the peer, or createRPCError(code) without one to send the standard text
OCPP 1.6: a frame whose message ID cannot be read is answered with GenericError, still under message ID "-1" (was RpcFrameworkError, which the 1.6 error-code table does not have). This covers invalid JSON, a frame that is not an array, a message type that is not a number, and a message ID that is not a string. 2.0.1 and 2.1 still answer RpcFrameworkError1.6 peers or tests match RpcFrameworkError on these repliesMatch GenericError on 1.6
Empty OCPP 1.6 payloads must be objects (types only). HeartbeatRequest, StatusNotificationResponse and the other empty 1.6 interfaces extend Record<string, never>You pass or return something other than {} for an empty 1.6 payload: a number, a string, an array, or extra fieldsUse {}. An async handler that returns {}, and NOREPLY, still work
A client sends its password on every security profile (was only on profiles 1 and 2), as Basic Auth with the identity as the username. A Buffer is sent as its bytesA client with a password on profile 0 or 3, or with no profile, connects to a server that must not get an Authorization headerLeave out password where no Basic Auth is wanted
A thrown format violation goes out under the version's name. On OCPP 1.6, FormatViolation is sent as FormationViolation, as the 1.6-J errata (§5.2) keep it. On 2.0.1 and 2.1, FormationViolation is sent as FormatViolationYour 1.6 handlers or middleware throw FormatViolation, and peers or tests match that codeMatch FormationViolation on 1.6
Strict mode: a handler's own answer that breaks the schema is answered InternalError, with the code's standard text (was the validation code and the schema error). strictValidationFailure still reports the schema error, and handlerError gets it as the causePeers or tests match the validation code on these repliesMatch InternalError, and read the schema error from strictValidationFailure or handlerError
close() waits for the answers that handlers are working on, at most callTimeoutMs, as well as for its own calls. This is with awaitPending, the default, so server.close() waits tooYour shutdown has to finish quickly while handlers can be slowclose({ awaitPending: false }) or close({ force: true }) closes at once
A handler's ctx.signal aborts when its connection closes before the handler settles (it never aborted)A handler passes ctx.signal to work that has to finish after the charger disconnects, such as a database writeDon't pass the signal to that work

Before:

client.handle((method, ctx) => {
  console.log(`Unhandled ${method}`, ctx.params);
  return {};
});

After:

client.handle((ctx) => {
  console.log(`Unhandled ${ctx.method}`, ctx.params);
  return {};
});

Moved into ocpp-ws-io

The protocol proxy, the smart charge engine and the CLI ship in ocpp-ws-io from 3.1.0. Their separate packages are deprecated; their last releases only re-export or run ocpp-ws-io.

BeforeNow
ocpp-protocol-proxy, /presets, /adaptersocpp-ws-io/proxy, /proxy/presets, /proxy/adapters — see Moving from ocpp-protocol-proxy
ocpp-smart-charge-engine, /strategies, /buildersocpp-ws-io/smart-charge, /smart-charge/strategies, /smart-charge/builders — see Moving from ocpp-smart-charge-engine
ocpp-ws-cli (the ocpp and ocpp-ws-cli commands)the ocpp command of ocpp-ws-io, or npx ocpp-ws-io; a script that runs ocpp-ws-cli runs ocpp — see the CLI

The full list is in the CHANGELOG.

On this page