1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00

Added tag selection

This commit is contained in:
Ben Hardill 2013-11-22 13:58:41 +00:00
parent 0e370c9bbc
commit 8fbbd4d1fd
2 changed files with 19 additions and 16 deletions

View File

@ -33,9 +33,13 @@
<input type="text" id="node-input-name" placeholder="Name"> <input type="text" id="node-input-name" placeholder="Name">
</div> </div>
<div class="form-row"> <div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Topic</label> <label for="node-input-topic"><i class="icon-tag"></i> Topic</label>
<input type="text" id="node-input-topic" > <input type="text" id="node-input-topic" >
</div> </div>
<div class="form-row">
<label for="node-input-uuid"><i class="icon-tag"></i> UUID</label>
<input type="text" id="node-input-uuid" >
</div>
<div class="form-row"> <div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Temperature</label> <label for="node-input-name"><i class="icon-tag"></i> Temperature</label>
<input type="checkbox" id="node-input-temperature" placeholder=""> <input type="checkbox" id="node-input-temperature" placeholder="">
@ -85,6 +89,7 @@
defaults: { // defines the editable properties of the node defaults: { // defines the editable properties of the node
name: {value:"sensorTag"}, // along with default values. name: {value:"sensorTag"}, // along with default values.
topic: {value:"sensorTag"}, topic: {value:"sensorTag"},
uuid: {value:undefined},
temperature: {value:true}, temperature: {value:true},
humidity: {value:true}, humidity: {value:true},
pressure: {value:true}, pressure: {value:true},

View File

@ -14,20 +14,18 @@
* limitations under the License. * limitations under the License.
**/ **/
// Sample Node-RED node file
// Require main module // Require main module
var RED = require("../../red/red"); var RED = require(process.env.NODE_RED_HOME+"/red/red");
var SensorTag = require('sensortag'); var SensorTag = require('sensortag');
var stag; var stag;
var node; var node;
// The main node definition - most things happen in here // The main node definition - most things happen in here
function sensorTagNode(n) { function sensorTagNode(n) {
// Create a RED node
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.name = n.name; this.name = n.name;
this.topic = n.topic; this.topic = n.topic;
this.uuid = n.uuid;
this.temperature = n.temperature; this.temperature = n.temperature;
this.pressure = n.pressure; this.pressure = n.pressure;
this.humidity = n.humidity; this.humidity = n.humidity;
@ -35,19 +33,25 @@ function sensorTagNode(n) {
this.magnetometer = n.magnetometer; this.magnetometer = n.magnetometer;
this.gyroscope = n.gyroscope; this.gyroscope = n.gyroscope;
this.keys = n.keys; this.keys = n.keys;
if (this.uuid === "") {
this.uuid = undefined;
}
console.log(this.uuid);
node=this; node=this;
if ( typeof stag == "undefined") { if ( typeof stag == "undefined") {
//console.log("starting"); //console.log("starting");
SensorTag.discover(function(sensorTag){ SensorTag.discover(function(sensorTag){
stag = sensorTag; stag = sensorTag;
sensorTag.connect(function(){ sensorTag.connect(function(){
//console.log("connected"); //console.log("connected");
sensorTag.discoverServicesAndCharacteristics(function(){ sensorTag.discoverServicesAndCharacteristics(function(){
sensorTag.enableIrTemperature(function(){}); sensorTag.enableIrTemperature(function(){});
sensorTag.on('irTemperatureChange', sensorTag.on('irTemperatureChange',
function(objectTemperature, ambientTemperature){ function(objectTemperature, ambientTemperature){
var msg = {'topic': node.topic + '/temperature'}; var msg = {'topic': node.topic + '/tempature'};
msg.payload = {'object': objectTemperature.toFixed(1), msg.payload = {'object': objectTemperature.toFixed(1),
'ambient':ambientTemperature.toFixed(1) 'ambient':ambientTemperature.toFixed(1)
}; };
@ -93,13 +97,11 @@ function sensorTagNode(n) {
enable(); enable();
}); });
}); });
}); },node.uuid);
} else { } else {
//console.log("reconfig"); //console.log("reconfig");
enable(); enable();
} }
} }
function enable() { function enable() {
@ -139,8 +141,4 @@ function enable() {
stag.unnotifySimpleKey(function() {}); stag.unnotifySimpleKey(function() {});
} }
} }
// Register the node by name. This must be called before overriding any of the
// Node functions.
RED.nodes.registerType("sensorTag",sensorTagNode); RED.nodes.registerType("sensorTag",sensorTagNode);