Skip to content

Commit

Permalink
Fix flooding Log/Debug tab with error messages when Host is not reach…
Browse files Browse the repository at this point in the history
…able

* Fix spamming of error messages in Log

* Fix spamming Errormessages when device is not reachable

* Update eiscp-out.js

* Update eiscp-in.js

* Update eiscp-out.js
  • Loading branch information
Jakob-Gliwa authored Nov 1, 2022
1 parent b871a42 commit 4e425a3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
3 changes: 0 additions & 3 deletions eiscp-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ module.exports = function (RED) {
}
node.log('configuring to EISCP device at ' + config.host + ':' + config.port + ' model[' + config.model + ']');
node.eiscpjsconn = eiscp;
node.eiscpjsconn.on('error', function (err) {
node.error('Error: ' + err.toString());
});
node.eiscpjsconn.connect({
host: config.host,
model: config.model,
Expand Down
18 changes: 17 additions & 1 deletion eiscp-in.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = function (RED) {
this.name = config.name;
this.connection = null;
var node = this;
this.currentError = null;
//node.log('new EISCPIn, config: %j', config);
var eiscpjsController = RED.nodes.getNode(config.controller);
/* ===== Node-Red events ===== */
Expand All @@ -37,11 +38,21 @@ module.exports = function (RED) {
}

function nodeStatusConnected() {
node.currentError = null;
node.status({fill: "green", shape: "dot", text: "connected"});
}

function nodeStatusDisconnected() {
node.status({fill: "red", shape: "dot", text: "disconnected"});
if(node.currentError == null){
node.status({fill: "red", shape: "dot", text: "disconnected"});
} else {
nodeStatusDisconnectedWithError(node.currentError);
}
}

function nodeStatusDisconnectedWithError(error) {
var statusText = "disconnected (" + error + ")";
node.status({fill: "red", shape: "dot", text: statusText});
}

node.receiveData = function (data) {
Expand Down Expand Up @@ -70,6 +81,11 @@ module.exports = function (RED) {
node.connection.on('connect', nodeStatusConnected);
node.connection.removeListener('close', nodeStatusDisconnected);
node.connection.on('close', nodeStatusDisconnected);
node.connection.removeListener('error', nodeStatusDisconnected);
node.connection.on('error', function (err) {
node.currentError = err;
nodeStatusDisconnectedWithError(err);
});
});
}

Expand Down
21 changes: 20 additions & 1 deletion eiscp-out.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = function (RED) {
this.name = config.name;
this.ctrl = RED.nodes.getNode(config.controller);
var node = this;
this.currentError = null;
this.on("input", function (msg) {
node.log('eiscpout.onInput msg[' + util.inspect(msg) + ']');
if (!(msg && (msg.hasOwnProperty('payload') || msg.hasOwnProperty('raw')))) return;
Expand Down Expand Up @@ -61,12 +62,26 @@ module.exports = function (RED) {
}

function nodeStatusDisconnected() {
node.status({fill: "red", shape: "dot", text: "disconnected"});
if(node.currentError == null){
node.status({fill: "red", shape: "dot", text: "disconnected"});
} else {
nodeStatusDisconnectedWithError(node.currentError);
}
}

function nodeStatusDisconnectedWithError(error) {
var statusText = "disconnected (" + error + ")";
node.status({fill: "red", shape: "dot", text: statusText});
}

function nodeStatusConnecting() {
node.status({fill: "green", shape: "ring", text: "connecting"});
}

function nodeStatusDisconnectedWithError(error) {
var statusText = "disconnected (" + error.code + ")";
node.status({fill: "red", shape: "dot", text: statusText});
}

this.send = function (data, sendRaw, callback) {
node.log('send data[' + data + ']');
Expand Down Expand Up @@ -95,6 +110,10 @@ module.exports = function (RED) {
connection.on('connect', nodeStatusConnected);
connection.removeListener('close', nodeStatusDisconnected);
connection.on('close', nodeStatusDisconnected);
connection.on('error', function (err) {
node.currentError = err;
nodeStatusDisconnectedWithError(err);
});

try {
node.log("send: " + JSON.stringify(data));
Expand Down

0 comments on commit 4e425a3

Please sign in to comment.