Arduino nodes, reconnect on partial deploys

This commit is contained in:
Dave Conway-Jones 2016-07-15 14:45:32 +01:00
parent 0bfeb13abc
commit 4f4d2de45f
2 changed files with 22 additions and 12 deletions

View File

@ -70,7 +70,7 @@ module.exports = function(RED) {
this.board = this.serverConfig.board; this.board = this.serverConfig.board;
var node = this; var node = this;
node.status({fill:"red",shape:"ring",text:"node-red:common.status.connecting"}); node.status({fill:"red",shape:"ring",text:"node-red:common.status.connecting"});
node.board.on('ready', function() { var doit = function() {
node.status({fill:"green",shape:"dot",text:"node-red:common.status.connected"}); node.status({fill:"green",shape:"dot",text:"node-red:common.status.connected"});
if (node.state === "ANALOG") { if (node.state === "ANALOG") {
node.board.pinMode(node.pin, 0x02); node.board.pinMode(node.pin, 0x02);
@ -89,10 +89,16 @@ module.exports = function(RED) {
node.send({payload:v, topic:"string"}); node.send({payload:v, topic:"string"});
}); });
} }
node.board.on('close', function() { // node.board.on('close', function() {
node.status({fill:"grey",shape:"ring",text:"node-red:common.status.not-connected"}); // node.board.removeAllListeners();
}); // node.status({fill:"grey",shape:"ring",text:"node-red:common.status.not-connected"});
}); // });
}
if (node.board.isReady) { doit(); }
else { node.board.on("ready", function() { doit(); }); }
node.on("close", function() {
if (node.tout) { clearTimeout(node.tout); }
})
} }
else { else {
this.warn(RED._("arduino.errors.portnotconf")); this.warn(RED._("arduino.errors.portnotconf"));
@ -113,8 +119,7 @@ module.exports = function(RED) {
this.board = this.serverConfig.board; this.board = this.serverConfig.board;
var node = this; var node = this;
node.status({fill:"red",shape:"ring",text:"node-red:common.status.connecting"}); node.status({fill:"red",shape:"ring",text:"node-red:common.status.connecting"});
var doit = function() {
node.board.on('ready', function() {
node.status({fill:"green",shape:"dot",text:"node-red:common.status.connected"}); node.status({fill:"green",shape:"dot",text:"node-red:common.status.connected"});
node.on("input", function(msg) { node.on("input", function(msg) {
if (node.state === "OUTPUT") { if (node.state === "OUTPUT") {
@ -147,10 +152,15 @@ module.exports = function(RED) {
node.board.sendString(msg.payload.toString()); node.board.sendString(msg.payload.toString());
} }
}); });
node.board.on('close', function() { // node.board.on('close', function() {
node.status({fill:"grey",shape:"ring",text:"node-red:common.status.not-connected"}); // node.status({fill:"grey",shape:"ring",text:"node-red:common.status.not-connected"});
}); // });
}); }
if (node.board.isReady) { doit(); }
else { node.board.on("ready", function() { doit(); }); }
node.on("close", function() {
if (node.tout) { clearTimeout(node.tout); }
})
} }
else { else {
this.warn(RED._("arduino.errors.portnotconf")); this.warn(RED._("arduino.errors.portnotconf"));

View File

@ -1,6 +1,6 @@
{ {
"name" : "node-red-node-arduino", "name" : "node-red-node-arduino",
"version" : "0.0.8", "version" : "0.0.9",
"description" : "A Node-RED node to talk to an Arduino running firmata", "description" : "A Node-RED node to talk to an Arduino running firmata",
"dependencies" : { "dependencies" : {
"firmata" : "~0.13.0" "firmata" : "~0.13.0"