Add better sensehat error handling

This commit is contained in:
Nick O'Leary 2016-03-08 15:28:20 +00:00
parent c9faed7876
commit 471840b868
2 changed files with 6 additions and 2 deletions

View File

@ -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",

View File

@ -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);