From 7efd866ff0892b874aefaa53af1f1295e8f37d51 Mon Sep 17 00:00:00 2001 From: Ben Hardill Date: Tue, 25 Feb 2014 11:18:45 +0000 Subject: [PATCH 1/2] Cleaned up the code a little and added some more comments to the info section --- hardware/sensorTag/79-sensorTag.html | 5 ++ hardware/sensorTag/79-sensorTag.js | 86 ++++++++++++++-------------- 2 files changed, 47 insertions(+), 44 deletions(-) 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); From 7c1e57046533e8db921b9d9213bfd2111b968c98 Mon Sep 17 00:00:00 2001 From: Ben Hardill Date: Tue, 25 Feb 2014 11:22:10 +0000 Subject: [PATCH 2/2] Add bit I'd missed in the sidebar doc --- hardware/sensorTag/79-sensorTag.html | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/hardware/sensorTag/79-sensorTag.html b/hardware/sensorTag/79-sensorTag.html index 6b9bd14a..6e065d94 100644 --- a/hardware/sensorTag/79-sensorTag.html +++ b/hardware/sensorTag/79-sensorTag.html @@ -78,10 +78,14 @@

Input node for the Ti SensorTag

+

For this node to work correctly Node-Red needs to be run as root, this + due to how Bluetooth 4.0 support is currently implemented in Linux

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)

+ active in range at the same time. (note you can only have one SensorTag + per node-red instance at the moment)

+

The topic setting is a prefix that will be pre-pended to name of the + sensor that creates the reading. e.g. sensorTag/temperature