-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
69 lines (60 loc) · 2.14 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import ocpp from 'ocpp-eliftech';
const server = new ocpp.CentralSystem();
server.listen(9220);
server.onRequest = async function(client, command) {
const connection = client.connection;
// console.log(command);
// console.info(`New command from ${connection.url}`);
// Handle different commands
switch (true) {
case command instanceof ocpp.OCPPCommands.BootNotification:
console.log({ message: 'BootNotification', chargeBoxIdentity, payload: command });
return {
status: 'Accepted',
currentTime: new Date().toISOString(),
interval: 60
};
case command instanceof ocpp.OCPPCommands.Authorize:
return {
idTagInfo: {
status: 'Accepted'
}
};
case command instanceof ocpp.OCPPCommands.StartTransaction:
return {
transactionId: 1,
idTagInfo: {
status: 'Accepted'
}
};
case command instanceof ocpp.OCPPCommands.StopTransaction:
return {
transactionId: 1,
idTagInfo: {
status: 'Accepted'
}
};
case command instanceof ocpp.OCPPCommands.Heartbeat:
console.log({ message: 'Heartbeat', chargeBoxIdentity, payload: command });
return {
currentTime: new Date().toISOString()
};
case command instanceof ocpp.OCPPCommands.StatusNotification:
// client.info = client.info || {};
// client.info.connectors = client.info.connectors || [];
const connectorIndex = client.info.connectors.findIndex(item => command.connectorId === item.connectorId);
if (connectorIndex === -1) {
client.info.connectors.push({
...command
});
} else {
client.info.connectors[connectorIndex] = {
...command
};
}
await cSystem.onStatusUpdate();
return {};
default:
throw new ocpp.OCPPError(ERROR_NOTIMPLEMENTED, 'Unknown command');
}
}