diff --git a/hardware/Arduino/35-arduino.js b/hardware/Arduino/35-arduino.js index b3169106..1a43637b 100644 --- a/hardware/Arduino/35-arduino.js +++ b/hardware/Arduino/35-arduino.js @@ -9,21 +9,21 @@ module.exports = function(RED) { function ArduinoNode(n) { RED.nodes.createNode(this,n); this.device = n.device || null; + this.running = false; + this.reported = false; var node = this; - var running = false; - var reported = false; var startup = function() { node.board = new Board(node.device, function(e) { if ((e !== undefined) && (e.toString().indexOf("cannot open") !== -1) ) { - if (!reported) { + if (node.reported === false) { node.error(RED._("arduino.errors.portnotfound",{device:node.device})); - reported = true; + node.reported = true; } } else if (e === undefined) { - running = true; - reported = false; + node.running = true; + node.reported = false; node.board.once('ready', function() { node.log(RED._("arduino.status.connected",{device:node.board.sp.path})); if (RED.settings.verbose) { @@ -34,16 +34,16 @@ module.exports = function(RED) { node.error(RED._("arduino.status.portclosed")); }); node.board.once('disconnect', function() { - if (running) { setTimeout(function() { running = false; startup(); }, 5000); } + if (node.running === true) { setTimeout(function() { node.running = false; startup(); }, 5000); } }); } }); - setTimeout(function() { if (!running) { startup(); } }, 5000); + setTimeout(function() { if (node.running === false) { startup(); } }, 5000); }; startup(); node.on('close', function(done) { - running = false; + node.running = false; if (node.board) { try { node.board.transport.close(function() { @@ -185,12 +185,12 @@ module.exports = function(RED) { }); node.board.once('disconnect', function() { node.status({fill:"red",shape:"ring",text:"node-red:common.status.not-connected"}); - if (node.running) { setTimeout(function() { node.running = false; startup(); }, 5500); } + if (node.running === true) { setTimeout(function() { node.running = false; startup(); }, 5500); } }); } if (node.board.isReady) { doit(); } else { node.board.once("ready", function() { doit(); }); } - setTimeout(function() { if (!node.running) { startup(); } }, 4500); + setTimeout(function() { if (node.running === false) { startup(); } }, 4500); } startup(); } diff --git a/hardware/Arduino/package.json b/hardware/Arduino/package.json index 77d1dd66..c919cabb 100644 --- a/hardware/Arduino/package.json +++ b/hardware/Arduino/package.json @@ -1,6 +1,6 @@ { "name" : "node-red-node-arduino", - "version" : "0.2.2", + "version" : "0.2.3", "description" : "A Node-RED node to talk to an Arduino running firmata", "dependencies" : { "firmata" : "^2.0.0"