I want to create OCPP JSON central system in Node.js. For OCPP 1.6 implementation, there are packages with good examples. But for OCPP2.0 I’ve found only ocpp-rpc and faced huge memory leaks on high number of connections. Is there any others packages? Thanks
That’s what i’ve tried:
const server = new RPCServer({
protocols: ['ocpp2.0.1'],
strictMode: true,
});
server.auth((accept, reject, handshake) => {
accept({
sessionId: 'XYZ123'
});
});
server.on('client', async (client) => {
client.handle('BootNotification', ({params}) => {
return {
status: "Accepted",
interval: 300,
currentTime: new Date().toISOString()
};
});
});
await server.listen(3000);
>Solution :
Try @extrawest/node-ts-ocpp
Your implementation will look like
const centralSystemSimple = new OcppServer();
centralSystemSimple.listen(parseInt(process.env.PORT) || 3000);
centralSystemSimple.on('connection', (client: OcppClientConnection) => {
client.on('BootNotification', (request: BootNotificationRequest, cb: (response: BootNotificationResponse) => void) => {
const response: BootNotificationResponse = {
status: 'Accepted',
currentTime: new Date().toISOString(),
interval: parseInt(process.env.HEARTBEAT_INTERVAL),
};
cb(response);
});
});