From 4e425a39f1e4128ab3619f97c4c06dc12100f343 Mon Sep 17 00:00:00 2001 From: Jakob-Gliwa Date: Tue, 1 Nov 2022 21:26:51 +0100 Subject: [PATCH] Fix flooding Log/Debug tab with error messages when Host is not reachable * 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 --- eiscp-controller.js | 3 --- eiscp-in.js | 18 +++++++++++++++++- eiscp-out.js | 21 ++++++++++++++++++++- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/eiscp-controller.js b/eiscp-controller.js index 570bf8c..22950b7 100644 --- a/eiscp-controller.js +++ b/eiscp-controller.js @@ -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, diff --git a/eiscp-in.js b/eiscp-in.js index 49566a9..cbdab65 100644 --- a/eiscp-in.js +++ b/eiscp-in.js @@ -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 ===== */ @@ -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) { @@ -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); + }); }); } diff --git a/eiscp-out.js b/eiscp-out.js index 041f5c0..94171af 100644 --- a/eiscp-out.js +++ b/eiscp-out.js @@ -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; @@ -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 + ']'); @@ -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));