Skip to content

Commit

Permalink
Merge pull request #61 from Argonne-National-Laboratory/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
bnystrom authored Jul 19, 2023
2 parents 4ada022 + 321fe08 commit f42d4c5
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 35 deletions.
3 changes: 2 additions & 1 deletion ocpp/ocpp-cp-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const url = require('node:url');
const path = require('node:path');

let ee = new EventEmitter();
let NetStatus = 'OFFLINE';

const WSTOMIN_DEF = 5;
const WSTOMAX_DEF = 360;
Expand Down Expand Up @@ -71,6 +70,7 @@ module.exports = function(RED) {
let wstocur = parseInt(node.wstomin);
let conto;
let wsnoreconn = false;
let NetStatus = 'OFFLINE';

function reconn_debug() {
debug(`wstomin: ${node.wstomin}`);
Expand Down Expand Up @@ -457,6 +457,7 @@ module.exports = function(RED) {
node.send(msg);//send update
NetStatus = msg.ocpp.websocket;
}
wsnoreconn = true;
ws.close();
});

Expand Down
73 changes: 48 additions & 25 deletions ocpp/ocpp-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,38 +223,39 @@ module.exports = function(RED) {
let wsrequest;

x.on('connection', function connection(ws,req) {
debug_csserver(`Got a connection from ${req.params.cbid}...`);
const cbid = req.params.cbid;
let connname = cbid + CBIDCONPOSTFIX;
cb_map.set(cbid,ws);
if (req.params){
debug_csserver(`Got a connection from ${req.params.cbid}...`);
const cbid = req.params.cbid;
let connname = cbid + CBIDCONPOSTFIX;
cb_map.set(cbid,ws);

node.status({
fill: 'green',
shape: 'dot',
text: `Connection from ${cbid}`,
});
node.status({
fill: 'green',
shape: 'dot',
text: `Connection from ${cbid}`,
});

// Announce connection
// Announce connection

ee.emit(connname,"connected");
ee.emit(connname,"connected");


// Remove cbid from map when it closes and emit a message
ws.on('close', function () {
cb_map.delete(cbid);
node.status({
fill: 'gray',
shape: 'dot',
text: `Disconnected from ${cbid}`,
// Remove cbid from map when it closes and emit a message
ws.on('close', function () {
cb_map.delete(cbid);
node.status({
fill: 'gray',
shape: 'dot',
text: `Disconnected from ${cbid}`,
});
ee.emit(connname,"disconnected");
debug_csserver(`Lost connection to ${cbid}`);
});
ee.emit(connname,"disconnected");
debug_csserver(`Lost connection to ${cbid}`);
});

ws.on('message', function(msgIn) {
debug_csserver(msgIn);
});

ws.on('message', function(msgIn) {
debug_csserver(msgIn);
});
}
});

let soapServer15, soapServer16;
Expand Down Expand Up @@ -436,6 +437,28 @@ module.exports = function(RED) {

debug_csserver(`Websocket connection to : ${localcbid}`);


msg = {
ocpp : {
websocket : 'ONLINE',
chargeBoxIdentity : localcbid
}
};
node.send(msg);

ws.on('close', function ws_close(code, reason) {
msg = {
ocpp : {
websocket : 'OFFLINE',
chargeBoxIdentity : localcbid,
code : code,
reason : reason,
}
};

node.send(msg);
});

ws.on('message', function(msgIn) {
let response = [];

Expand Down
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-red-contrib-ocpp",
"version": "1.3.5",
"version": "1.3.6",
"description": "A set of nodes to communicate via OCPP to a compatible charge box or central system",
"main": "ocpp-req.js",
"scripts": {
Expand Down

0 comments on commit f42d4c5

Please sign in to comment.