diff --git a/hardware/sensorTag/79-sensorTag.html b/hardware/sensorTag/79-sensorTag.html index ce2ec638..e72a2660 100644 --- a/hardware/sensorTag/79-sensorTag.html +++ b/hardware/sensorTag/79-sensorTag.html @@ -51,12 +51,11 @@
Node to read from the Ti SensorTag
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. Note:you can only have one SensorTag - per Node-RED instance at the moment.
+ active in range at the same time.The topic setting is a prefix that will be pre-pended to the name of the sensor that creates the reading. e.g. sensorTag/temperature. If blank it will be set to the UUID of the sensor tag.
-NOTE: Only 1 sensorTag can be read from at a time, +
Note: 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.
Linux users should READ THIS.
@@ -67,7 +66,7 @@ category:'advanced-function', color:"GoldenRod", defaults:{ - name:{value:"sensorTag"}, + name:{value:""}, topic:{value:"sensorTag"}, uuid:{value:undefined}, temperature:{value:true}, @@ -89,15 +88,15 @@ return this.name?"node_label_italic":""; }, oneditsave:function() { - var mac = $("#node-input-uuid").val(); - mac = mac.toLowerCase(); - // nasty hack as I can't get global replace to work - mac = mac.replace(/:/gi,''); - mac = mac.replace(/:/gi,''); - mac = mac.replace(/:/gi,''); - mac = mac.replace(/:/gi,''); - mac = mac.toLowerCase(); - $("#node-input-uuid").val(mac); + var mac = $("#node-input-uuid").val(); + mac = mac.toLowerCase(); + // nasty hack as I can't get global replace to work + mac = mac.replace(/:/gi,''); + mac = mac.replace(/:/gi,''); + mac = mac.replace(/:/gi,''); + mac = mac.replace(/:/gi,''); + mac = mac.toLowerCase(); + $("#node-input-uuid").val(mac); } }); diff --git a/hardware/sensorTag/79-sensorTag.js b/hardware/sensorTag/79-sensorTag.js index 85947325..42e127b7 100644 --- a/hardware/sensorTag/79-sensorTag.js +++ b/hardware/sensorTag/79-sensorTag.js @@ -33,90 +33,95 @@ 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.status({fill:"blue", shape:"dot", text:"discovering..."}); + 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; + node.log("found sensor tag: " + sensorTag._peripheral.uuid); + node.topic = node.topic || sensorTag._peripheral.uuid; + sensorTag.connect(function() { + node.log("connected to sensor tag: " + sensorTag._peripheral.uuid); + node.status({fill:"green", shape:"dot", text:"connected"}); - SensorTag.discover(function(sensorTag) { - node.status({fill:"blue", shape:"dot", text:"connecting"}); - node.stag = sensorTag; - node.log("found sensor tag: " + sensorTag._peripheral.uuid); - node.topic = node.topic || sensorTag._peripheral.uuid; - sensorTag.connect(function() { - node.log("connected to sensor tag: " + sensorTag._peripheral.uuid); - 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); + }); - sensorTag.on('disconnect', function() { - node.status({fill:"red", shape:"ring", text:"disconnected"}); - node.log("disconnected ",node.uuid); - }); + sensorTag.discoverServicesAndCharacteristics(function() { + sensorTag.enableIrTemperature(function() {}); + sensorTag.on('irTemperatureChange', + function(objectTemperature, ambientTemperature) { + var msg = {'topic': node.topic + '/temperature'}; + msg.payload = {'object': +objectTemperature.toFixed(1), + 'ambient': +ambientTemperature.toFixed(1) + }; + node.send(msg); + }); + sensorTag.enableBarometricPressure(function() {}); + sensorTag.on('barometricPressureChange', function(pressure) { + var msg = {'topic': node.topic + '/pressure'}; + msg.payload = {'pressure': parseInt(pressure)}; + node.send(msg); + }); + sensorTag.enableHumidity(function() {}); + sensorTag.on('humidityChange', function(temp, humidity) { + var msg = {'topic': node.topic + '/humidity'}; + msg.payload = {'temperature': +temp.toFixed(1), + 'humidity': +humidity.toFixed(1) + }; + node.send(msg); + }); + sensorTag.enableAccelerometer(function() {}); + sensorTag.on('accelerometerChange', function(x,y,z) { + var msg = {'topic': node.topic + '/accelerometer'}; + msg.payload = {'x': +x.toFixed(2), 'y': +y.toFixed(2), 'z': +z.toFixed(2)}; + node.send(msg); + }); + sensorTag.enableMagnetometer(function() {}); + sensorTag.on('magnetometerChange', function(x,y,z) { + var msg = {'topic': node.topic + '/magnetometer'}; + msg.payload = {'x': +x.toFixed(2), 'y': +y.toFixed(2), 'z': +z.toFixed(2)}; + node.send(msg); + }); + sensorTag.enableGyroscope(function() {}); + sensorTag.on('gyroscopeChange', function(x,y,z) { + var msg = {'topic': node.topic + '/gyroscope'}; + msg.payload = {'x': +x.toFixed(2), 'y': +y.toFixed(2), 'z': +z.toFixed(2)}; + node.send(msg); + }); + sensorTag.on('simpleKeyChange', function(left, right, mag) { + var msg = {'topic': node.topic + '/keys'}; + msg.payload = {'left': left, 'right': right, 'magnet': mag}; + node.send(msg); + }); - sensorTag.discoverServicesAndCharacteristics(function() { - sensorTag.enableIrTemperature(function() {}); - sensorTag.on('irTemperatureChange', - function(objectTemperature, ambientTemperature) { - var msg = {'topic': node.topic + '/temperature'}; - msg.payload = {'object': +objectTemperature.toFixed(1), - 'ambient': +ambientTemperature.toFixed(1) - }; - node.send(msg); + sensorTag.on('luxometerChange', function(lux) { + var msg = {'topic': node.topic + '/luxometer'}; + msg.payload = {'lux': parseInt(lux)}; + node.send(msg); + }); + enable(node); + }); }); - sensorTag.enableBarometricPressure(function() {}); - sensorTag.on('barometricPressureChange', function(pressure) { - var msg = {'topic': node.topic + '/pressure'}; - msg.payload = {'pressure': parseInt(pressure)}; - node.send(msg); - }); - sensorTag.enableHumidity(function() {}); - sensorTag.on('humidityChange', function(temp, humidity) { - var msg = {'topic': node.topic + '/humidity'}; - msg.payload = {'temperature': +temp.toFixed(1), - 'humidity': +humidity.toFixed(1) - }; - node.send(msg); - }); - sensorTag.enableAccelerometer(function() {}); - sensorTag.on('accelerometerChange', function(x,y,z) { - var msg = {'topic': node.topic + '/accelerometer'}; - msg.payload = {'x': +x.toFixed(2), 'y': +y.toFixed(2), 'z': +z.toFixed(2)}; - node.send(msg); - }); - sensorTag.enableMagnetometer(function() {}); - sensorTag.on('magnetometerChange', function(x,y,z) { - var msg = {'topic': node.topic + '/magnetometer'}; - msg.payload = {'x': +x.toFixed(2), 'y': +y.toFixed(2), 'z': +z.toFixed(2)}; - node.send(msg); - }); - sensorTag.enableGyroscope(function() {}); - sensorTag.on('gyroscopeChange', function(x,y,z) { - var msg = {'topic': node.topic + '/gyroscope'}; - msg.payload = {'x': +x.toFixed(2), 'y': +y.toFixed(2), 'z': +z.toFixed(2)}; - node.send(msg); - }); - sensorTag.on('simpleKeyChange', function(left, right, mag) { - var msg = {'topic': node.topic + '/keys'}; - msg.payload = {'left': left, 'right': right, 'magnet': mag}; - node.send(msg); - }); - - sensorTag.on('luxometerChange', function(lux) { - var msg = {'topic': node.topic + '/luxometer'}; - msg.payload = {'lux': parseInt(lux)}; - node.send(msg); - }); - enable(node); - }); - }); - },node.uuid); + },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() {}); } }); } diff --git a/hardware/sensorTag/package.json b/hardware/sensorTag/package.json index 4a762e87..5659143c 100644 --- a/hardware/sensorTag/package.json +++ b/hardware/sensorTag/package.json @@ -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",