I'm trying to create an OCPP Server to handle the Electronic Vehicle actions. I'll use the NodeJS and websocket for the communication between server and client(charger).
Here are the technologies I use:
NodeJS Version: 18.13.0
OCPP Version: 1.6.10
Charger Brand: Teltonika
I've tried one file JavaScript script to handle this purpose. Here are my code:
const moment = require("moment");
const WebSocket = require("ws");
const connectivity = {
ip: "192.168.1.17",
port: 8080,
};;
const url = `ws://${connectivity.ip}:${connectivity.port}`;
const wss = new WebSocket.Server({ port: connectivity.port });
console.log(`Server running on ${url}`);
wss.on("connection", function connection(ws) {
ws.on("message", function incoming(message) {
try {
var msg = JSON.parse(message);
console.log("Incoming message", msg);
if (msg[2] === "BootNotification") {
const acceptJSON = {
"MessageTypeId": "3",
"UniqueId": "12345",
"Payload": {
"currentTime": "2019-01-01T00:00:00Z",
"interval":10,
"status":"Accepted",
"heartbeatInterval":30
}
}
ws.send(JSON.stringify(acceptJSON));
console.log("send", JSON.stringify(acceptJSON));
const authorizeJSON = {
"Action": "Authorize",
"IdTag": "TEST123",
"MessageId": moment().unix().toString(),
"Payload": null
}
ws.send(JSON.stringify(authorizeJSON));
console.log("send", JSON.stringify(authorizeJSON));
const heartbeat = () => {
const heartbeatJSON = {
"MessageTypeId": "2",
"UniqueId": "123",
"Action": "Heartbeat",
"Payload": {}
};
ws.send(JSON.stringify(heartbeatJSON));
console.log("HEARTBEAT sent");
};
heartbeat();
setInterval(heartbeat, 10000);
} else if (msg[2] === "Heartbeat") {
console.log("Heartbeat");
ws.send('{"1":2,"2":3,"3":{"currentTime":"2019-01-01T00:00:00Z"}}');
}
} catch (error) {
console.log("Error", error);
}
});
ws.on("close", function() {
console.log("disconnected");
});
ws.on("error", function(error) {
console.log(error);
});
});
192.168.1.17 is my local IP address. I have connected my device to wifi. Then I set the client(charger)'s target OCPP URL to ws://192.168.1.17:8080/
and Charge Point Identity to "TEST123" on the mobile application of the device. I can get this message from the device:
[
2,
'35',
'BootNotification',
{
chargePointModel: 'TeltoCharge_EVC1201P',
chargePointVendor: 'Teltonika Energy',
chargePointSerialNumber: '6000XXXXXX',
firmwareVersion: 'v1.6.10'
}
]
So I understand client(charger) can connect to the websocket. But it shows OCPP UNRESPONSIVE error on the mobile app. I made a research about it and they mention that the authorization can not be made.
I'm new to OCPP protocol. How can I successfully authorize the device? Thanks