Comments (2)
Sorry I've not been able to reproduce the error. Perhaps you can share your code?
I have just tested the following using Node.js v18.9.0
const { RPCServer, createRPCError, RPCClient } = require('ocpp-rpc');
async function main() {
const server = new RPCServer({
protocols: ['ocpp1.6'], // server accepts ocpp1.6 subprotocol
strictMode: true, // enable strict validation of requests & responses
});
server.auth((accept, reject, handshake) => {
// accept the incoming client
accept({
// anything passed to accept() will be attached as a 'session' property of the client.
sessionId: 'XYZ123'
});
});
server.on('client', async (client) => {
console.log(`${client.session.sessionId} connected!`); // `XYZ123 connected!`
// create a specific handler for handling BootNotification requests
client.handle('BootNotification', ({params}) => {
console.log(`Server got BootNotification from ${client.identity}:`, params);
// respond to accept the client
return {
status: "Accepted",
interval: 300,
currentTime: new Date().toISOString()
};
});
// create a specific handler for handling Heartbeat requests
client.handle('Heartbeat', ({params}) => {
console.log(`Server got Heartbeat from ${client.identity}:`, params);
// respond with the server's current time.
return {
currentTime: new Date().toISOString()
};
});
// create a specific handler for handling StatusNotification requests
client.handle('StatusNotification', ({params}) => {
console.log(`Server got StatusNotification from ${client.identity}:`, params);
return {};
});
// create a wildcard handler to handle any RPC method
client.handle(({method, params}) => {
// This handler will be called if the incoming method cannot be handled elsewhere.
console.log(`Server got ${method} from ${client.identity}:`, params);
// throw an RPC error to inform the server that we don't understand the request.
throw createRPCError("NotImplemented");
});
});
await server.listen(3000);
const cli = new RPCClient({
endpoint: 'ws://localhost:3000', // the OCPP endpoint URL
identity: 'EXAMPLE', // the OCPP identity
protocols: ['ocpp1.6'], // client understands ocpp1.6 subprotocol
strictMode: true, // enable strict validation of requests & responses
});
// connect to the OCPP server
await cli.connect();
// send a BootNotification request and await the response
const bootResponse = await cli.call('BootNotification', {
chargePointVendor: "ocpp-rpc",
chargePointModel: "ocpp-rpc",
});
// check that the server accepted the client
if (bootResponse.status === 'Accepted') {
// send a Heartbeat request and await the response
const heartbeatResponse = await cli.call('Heartbeat', {});
// read the current server time from the response
console.log('Server time is:', heartbeatResponse.currentTime);
// send a StatusNotification request for the controller
await cli.call('StatusNotification', {
connectorId: 0,
errorCode: "NoError",
status: "Available",
});
}
}
main().catch(console.error);
from ocpp-rpc.
Closing due to inactivity.
from ocpp-rpc.
Related Issues (20)
- Fail to run README samples HOT 4
- Feat: Add option to prevent queueing of calls while in CONNECTING state
- Reserved word "package" is used as a variable name in util.js
- client.call() listens to 'abort' event from passed signal, but does not unregister after call complete
- Feat: RPCClient should take an AbortSignal as a constructor option to close() on abort
- Wildcard handler HOT 2
- Module Not Found HOT 4
- Handshake with the same Charging point keeps on happening again and again. HOT 14
- How do StartTransactions work HOT 2
- Correct way to send a handshake or connect HOT 3
- Difficulty Setting Charging Profile After Clearing an Existing Profile for Dynamic Load Balancing HOT 2
- Issues with events HOT 3
- RPCServer 'upgradeAborted' event can fire after websocket upgrade is successful HOT 1
- Central system microservice HOT 7
- Backend to OCPP server communication via WebSocket (sendRaw) HOT 7
- Example for using this package in a project that uses ESM module HOT 4
- Correct way to set the maximum watt a charger can charge in a RemoteStartTransaction. HOT 28
- Disconnects after 30 sec HOT 3
- Error While Disconnecting from Webscoket Client HOT 5
- WebSockerPingInterval HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ocpp-rpc.