Registry / messaging / ocpp-rpc

ocpp-rpc

JSON →
library2.2.1jsnpmunverified

A client and server implementation of the WAMP-like RPC-over-WebSocket system defined in the OCPP-J protocols (OCPP1.6J, OCPP2.0.1J, OCPP2.1). Version 2.2.1 supports Node.js >=17.3.0, ships TypeScript types, and offers features like authentication, strict validation, automatic reconnection with exponential backoff, keep-alive pings, graceful shutdown, and support for OCPP security profiles 1-3. It is designed specifically for Node.js (not browser-compatible). Differentiates from generic WebSocket RPC libraries by being tailored to OCPP subprotocols, providing built-in schema validation, and handling OCPP-specific authentication flows.

npm install ocpp-rpc
INSTALL
IMPORT
SIG · OCPP-RPC
O
ocpp-rpc
messagingjavascriptv2.2.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

RPCServer
import { RPCServer } from 'ocpp-rpc'
const RPCServer = require('ocpp-rpc').RPCServer
ESM named import; CommonJS require works but does not destructure.
RPCClient
import { RPCClient } from 'ocpp-rpc'
const ocpp = require('ocpp-rpc'); const client = new ocpp.RPCClient({...});
Use named import for clarity, but CommonJS require works with destructuring.
createRPCError
import { createRPCError } from 'ocpp-rpc'
import createRPCError from 'ocpp-rpc'
Default export is the module itself; use named export.

Sets up a minimal OCPP1.6J server with authentication and a BootNotification handler.

import { RPCServer, createRPCError } from 'ocpp-rpc'; const server = new RPCServer({ protocols: ['ocpp1.6'], strictMode: true, }); server.auth((accept, reject, handshake) => { accept({ sessionId: 'XYZ123' }); }); server.on('client', async (client) => { console.log(`${client.session.sessionId} connected!`); client.on('request', async (request) => { if (request.action === 'BootNotification') { return { status: 'Accepted', currentTime: new Date().toISOString(), interval: 300, }; } throw createRPCError('NotImplemented'); }); client.on('error', (err) => { console.error('Client error:', err); }); client.on('disconnect', (code, reason) => { console.log(`Client disconnected: ${code} ${reason}`); }); }); server.listen(9220).then(() => { console.log('Server listening on port 9220'); });
Debug
Known issues
breakingIn version 2.0, the API was rewritten and is not backward-compatible with version 1.x. The import paths, class names, and methods changed (e.g., RPCServer instead of Server).
fix
Update code to use RPCServer, RPCClient, and new method signatures. See UPGRADING.md.
affects: >=2.0 <2.0? Actually >=2.0.0
deprecatedThe 'strictMode' option in RPCServer constructor will be removed in a future major version; use schema validation via 'ocpp-schemas' package instead.
fix
Migrate to external schema validation (see docs on strict validation).
affects: >=2.0.0
gotchaThe library requires Node.js >= 17.3.0 due to use of globalThis and other modern features. Older Node.js versions will throw errors.
fix
Upgrade Node.js to >=17.3.0 or consider using a polyfill.
affects: >=2.0.0
gotchaThe client's 'reconnect' option defaults to true; if the server closes unexpectedly, the client will keep reconnecting indefinitely. This may cause resource leaks if not configured correctly.
fix
Set reconnect: false if automatic reconnection is not desired, or configure maxReconnects option.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: Cannot destructure property 'RPCServer' of 'require(...)' as it is undefined.
Using CommonJS require with destructuring but importing incorrectly.
fix
Use const { RPCServer } = require('ocpp-rpc'); or use ESM import.
Error: subprotocol not supported
The client connected with a subprotocol not listed in the server's 'protocols' array.
fix
Ensure both client and server agree on the subprotocol string (e.g., 'ocpp1.6').
TypeError: createRPCError is not a function
Using default import instead of named import.
fix
Use import { createRPCError } from 'ocpp-rpc'.
Upgrade
Version history
2.2.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
22 hits · last 30 days
node
20
Amazon
1
OpenAI (training)
1
Resources
ocpp-rpc — npm install ocpp-rpc · libregistry