let ti sensor tag try to reconnect

to close #196
This commit is contained in:
Dave Conway-Jones 2016-04-01 16:02:49 +01:00
parent 68bd4cc036
commit 98d44004c9
3 changed files with 90 additions and 86 deletions

View File

@ -51,12 +51,11 @@
<p>Node to read from the Ti SensorTag</p>
<p>The UUID field is the bluetooth mac address of the sensor tag, this is optional
and can be used to bind to a specific SensorTag if you have more than one
active in range at the same time. <b>Note</b>:you can only have one SensorTag
per Node-RED instance at the moment.</p>
active in range at the same time.
<p>The <i>topic</i> setting is a prefix that will be pre-pended to the name of the
sensor that creates the reading. e.g. <i>sensorTag/temperature</i>. If
blank it will be set to the UUID of the sensor tag.</p>
<p><strong>NOTE:</strong> Only 1 sensorTag can be read from at a time,
<p><strong>Note:</strong> Currently the node can only read from 1 sensorTag at a time,
if you add more than one to the canvas then only the first to connect
will work.</p>
<p>Linux users should <a href="https://github.com/sandeepmistry/bleno#running-on-linux" target="_new">READ THIS</a>.</p>
@ -67,7 +66,7 @@
category:'advanced-function',
color:"GoldenRod",
defaults:{
name:{value:"sensorTag"},
name:{value:""},
topic:{value:"sensorTag"},
uuid:{value:undefined},
temperature:{value:true},

View File

@ -33,10 +33,13 @@ module.exports = function(RED) {
this.keys = n.keys;
if (this.uuid === "") { this.uuid = undefined; }
var node = this;
node.discovering = false;
if (typeof node.stag === "undefined") {
node.loop = setInterval(function() {
if (!node.discovering) {
node.status({fill:"blue", shape:"dot", text:"discovering..."});
node.discovering = true;
SensorTag.discover(function(sensorTag) {
node.status({fill:"blue", shape:"dot", text:"connecting"});
node.stag = sensorTag;
@ -47,6 +50,7 @@ module.exports = function(RED) {
node.status({fill:"green", shape:"dot", text:"connected"});
sensorTag.on('disconnect', function() {
node.discovering = false;
node.status({fill:"red", shape:"ring", text:"disconnected"});
node.log("disconnected ",node.uuid);
});
@ -108,15 +112,16 @@ module.exports = function(RED) {
});
});
},node.uuid);
}
},15000);
} else {
console.log("reconfig",node.uuid);
enable(node);
}
this.on("close", function() {
if (node.stag) {
node.stag.disconnect(function() {});
}
if (node.loop) { clearInterval(node.loop); }
if (node.stag) { node.stag.disconnect(function() {}); }
});
}

View File

@ -1,7 +1,7 @@
{
"name": "node-red-node-sensortag",
"description": "A Node-RED node to read data from a TI SensorTag",
"version": "0.0.12",
"version": "0.0.13",
"keywords": [
"node-red",
"sensortag",