mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Add better sensehat error handling
This commit is contained in:
parent
c9faed7876
commit
471840b868
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name" : "node-red-node-pi-sense-hat",
|
"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",
|
"description" : "A Node-RED node to interact with a Raspberry Pi Sense HAT",
|
||||||
"repository" : {
|
"repository" : {
|
||||||
"type":"git",
|
"type":"git",
|
||||||
|
@ -53,6 +53,7 @@ module.exports = function(RED) {
|
|||||||
var reconnectTimer = null;
|
var reconnectTimer = null;
|
||||||
|
|
||||||
var connect = function() {
|
var connect = function() {
|
||||||
|
reconnectTimer = null;
|
||||||
var buffer = "";
|
var buffer = "";
|
||||||
hat = spawn(hatCommand);
|
hat = spawn(hatCommand);
|
||||||
hat.stdout.on('data', function (data) {
|
hat.stdout.on('data', function (data) {
|
||||||
@ -115,7 +116,10 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
hat.stderr.on('data', function (data) {
|
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+" :"); }
|
if (RED.settings.verbose) { RED.log.error("err: "+data+" :"); }
|
||||||
|
hat.kill('SIGKILL');
|
||||||
});
|
});
|
||||||
hat.stderr.on('error', function(err) { });
|
hat.stderr.on('error', function(err) { });
|
||||||
hat.stdin.on('error', function(err) { });
|
hat.stdin.on('error', function(err) { });
|
||||||
@ -129,7 +133,7 @@ module.exports = function(RED) {
|
|||||||
if (onclose) {
|
if (onclose) {
|
||||||
onclose();
|
onclose();
|
||||||
onclose = null;
|
onclose = null;
|
||||||
} else {
|
} else if (!reconnectTimer) {
|
||||||
reconnectTimer = setTimeout(function() {
|
reconnectTimer = setTimeout(function() {
|
||||||
connect();
|
connect();
|
||||||
},5000);
|
},5000);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user