diff --git a/hardware/sensorTag/79-sensorTag.html b/hardware/sensorTag/79-sensorTag.html index 19d21eb8..6b9bd14a 100644 --- a/hardware/sensorTag/79-sensorTag.html +++ b/hardware/sensorTag/79-sensorTag.html @@ -78,6 +78,10 @@
Input node for the Ti SensorTag
+The UUID field is the mac address of the sensor tag, this is optional + 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)
@@ -109,6 +113,7 @@ }, 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,''); diff --git a/hardware/sensorTag/79-sensorTag.js b/hardware/sensorTag/79-sensorTag.js index 91d40b07..b63a6eba 100644 --- a/hardware/sensorTag/79-sensorTag.js +++ b/hardware/sensorTag/79-sensorTag.js @@ -17,8 +17,6 @@ // Require main module var RED = require(process.env.NODE_RED_HOME+"/red/red"); var SensorTag = require('sensortag'); -var stag; -var node; // The main node definition - most things happen in here function sensorTagNode(n) { @@ -37,14 +35,14 @@ function sensorTagNode(n) { if (this.uuid === "") { this.uuid = undefined; } - console.log(this.uuid); + //console.log(this.uuid); - node=this; + var node=this; - if ( typeof stag == "undefined") { + if ( typeof node.stag == "undefined") { //console.log("starting"); SensorTag.discover(function(sensorTag){ - stag = sensorTag; + node.stag = sensorTag; sensorTag.connect(function(){ //console.log("connected"); sensorTag.discoverServicesAndCharacteristics(function(){ @@ -94,51 +92,51 @@ function sensorTagNode(n) { msg.payload = {'left': left, 'right': right}; node.send(msg); }); - enable(); + enable(node); }); }); },node.uuid); } else { //console.log("reconfig"); - enable(); + enable(node); } } -function enable() { - if (node.temperature) { - stag.notifyIrTemperature(function(){}); - } else { - stag.unnotifyIrTemperature(function(){}); - } - if (node.pressure) { - stag.notifyBarometricPressure(function(){}); - } else { - stag.unnotifyBarometricPressure(function(){}); - } - if (node.humidity) { - stag.notifyHumidity(function() {}); - } else { - stag.unnotifyHumidity(function() {}); - } - if (node.accelometer){ - stag.notifyAccelerometer(function() {}); - } else { - stag.unnotifyAccelerometer(function() {}); - } - if (node.magnetometer) { - stag.notifyMagnetometer(function() {}); - } else { - stag.unnotifyMagnetometer(function() {}); - } - if (node.gyroscope) { - stag.notifyGyroscope(function() {}); - } else { - stag.unnotifyGyroscope(function() {}); - } - if (node.keys) { - stag.notifySimpleKey(function() {}); - } else { - stag.unnotifySimpleKey(function() {}); - } +function enable(node) { + if (node.temperature) { + node.stag.notifyIrTemperature(function(){}); + } else { + node.stag.unnotifyIrTemperature(function(){}); + } + if (node.pressure) { + node.stag.notifyBarometricPressure(function(){}); + } else { + node.stag.unnotifyBarometricPressure(function(){}); + } + if (node.humidity) { + node.stag.notifyHumidity(function() {}); + } else { + node.stag.unnotifyHumidity(function() {}); + } + if (node.accelometer){ + node.stag.notifyAccelerometer(function() {}); + } else { + node.stag.unnotifyAccelerometer(function() {}); + } + if (node.magnetometer) { + node.stag.notifyMagnetometer(function() {}); + } else { + node.stag.unnotifyMagnetometer(function() {}); + } + if (node.gyroscope) { + node.stag.notifyGyroscope(function() {}); + } else { + node.stag.unnotifyGyroscope(function() {}); + } + if (node.keys) { + node.stag.notifySimpleKey(function() {}); + } else { + node.stag.unnotifySimpleKey(function() {}); + } } RED.nodes.registerType("sensorTag",sensorTagNode);