diff --git a/hardware/sensehat/package.json b/hardware/sensehat/package.json index 5f91bdf9..4e470d9a 100644 --- a/hardware/sensehat/package.json +++ b/hardware/sensehat/package.json @@ -1,6 +1,6 @@ { "name" : "node-red-node-pi-sense-hat", - "version" : "0.0.7", + "version" : "0.0.8", "description" : "A Node-RED node to interact with a Raspberry Pi Sense HAT", "repository" : { "type":"git", diff --git a/hardware/sensehat/sensehat.js b/hardware/sensehat/sensehat.js index 92607312..eee0b8a5 100644 --- a/hardware/sensehat/sensehat.js +++ b/hardware/sensehat/sensehat.js @@ -53,6 +53,7 @@ module.exports = function(RED) { var reconnectTimer = null; var connect = function() { + reconnectTimer = null; var buffer = ""; hat = spawn(hatCommand); hat.stdout.on('data', function (data) { @@ -115,7 +116,10 @@ module.exports = function(RED) { } }); hat.stderr.on('data', function (data) { + // Any data on stderr means a bad thing has happened. + // Best to kill it and let it reconnect. if (RED.settings.verbose) { RED.log.error("err: "+data+" :"); } + hat.kill('SIGKILL'); }); hat.stderr.on('error', function(err) { }); hat.stdin.on('error', function(err) { }); @@ -129,7 +133,7 @@ module.exports = function(RED) { if (onclose) { onclose(); onclose = null; - } else { + } else if (!reconnectTimer) { reconnectTimer = setTimeout(function() { connect(); },5000);