let pi keyboard to retry connection

This commit is contained in:
Dave Conway-Jones 2020-12-04 13:47:29 +00:00
parent 91217d6e62
commit 8c7409d041
No known key found for this signature in database
GPG Key ID: 88BA2B8A411BE9FF
2 changed files with 10 additions and 3 deletions

View File

@ -271,7 +271,7 @@ module.exports = function(RED) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
var node = this; var node = this;
if (allOK === true) { var doConnect = function() {
node.child = spawn(gpioCommand+".py", ["kbd","0"]); node.child = spawn(gpioCommand+".py", ["kbd","0"]);
node.status({fill:"green",shape:"dot",text:"rpi-gpio.status.ok"}); node.status({fill:"green",shape:"dot",text:"rpi-gpio.status.ok"});
@ -300,7 +300,10 @@ module.exports = function(RED) {
node.status({fill:"grey",shape:"ring",text:"rpi-gpio.status.closed"}); node.status({fill:"grey",shape:"ring",text:"rpi-gpio.status.closed"});
node.finished(); node.finished();
} }
else { node.status({fill:"red",shape:"ring",text:"rpi-gpio.status.stopped"}); } else {
node.status({fill:"red",shape:"ring",text:"rpi-gpio.status.stopped"});
setTimeout(function() { doConnect(); },2000)
}
}); });
node.child.on('error', function (err) { node.child.on('error', function (err) {
@ -308,6 +311,10 @@ module.exports = function(RED) {
else if (err.errno === "EACCES") { node.error(RED._("rpi-gpio.errors.commandnotexecutable")); } else if (err.errno === "EACCES") { node.error(RED._("rpi-gpio.errors.commandnotexecutable")); }
else { node.error(RED._("rpi-gpio.errors.error")+': ' + err.errno); } else { node.error(RED._("rpi-gpio.errors.error")+': ' + err.errno); }
}); });
}
if (allOK === true) {
doConnect();
node.on("close", function(done) { node.on("close", function(done) {
node.status({}); node.status({});

View File

@ -1,6 +1,6 @@
{ {
"name": "node-red-node-pi-gpio", "name": "node-red-node-pi-gpio",
"version": "1.2.1", "version": "1.2.2",
"description": "The basic Node-RED node for Pi GPIO", "description": "The basic Node-RED node for Pi GPIO",
"dependencies" : { "dependencies" : {
}, },