Update SensorTag to include Luxo and cleanup layout

This commit is contained in:
dceejay 2015-07-01 23:45:34 +01:00
parent a8cb187321
commit 91dc58d2b0
4 changed files with 199 additions and 210 deletions

View File

@ -1,5 +1,5 @@
<!--
Copyright 2013 IBM Corp.
Copyright 2014.2015 IBM Corp.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@ -14,69 +14,40 @@
limitations under the License.
-->
<!-- First, the content of the edit dialog is defined. -->
<script type="text/x-red" data-template-name="sensorTag">
<!-- data-template-name identifies the node type this is for -->
<!-- Each of the following divs creates a field in the edit dialog. -->
<!-- Generally, there should be an input for each property of the node. -->
<!-- The for and id attributes identify the corresponding property -->
<!-- (with the 'node-input-' prefix). -->
<!-- The available icon classes are defined in Twitter Bootstrap -->
<!-- By convention, most nodes have a 'name' property. The following div -->
<!-- provides the necessary field. -->
<div class="form-row">
<label for="node-input-uuid"><i class="fa fa-ellipsis-h"></i> UUID</label>
<input type="text" id="node-input-uuid" placeholder="optional device bluetooth id">
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-external-link"></i> Outputs</label>
<input type="checkbox" id="node-input-humidity" style="display: inline-block; width: auto; vertical-align: top;"> Temperature and Humidity<br/>
<label>&nbsp;</label>
<input type="checkbox" id="node-input-temperature" style="display: inline-block; width: auto; vertical-align: top;"> IR Temperature<br/>
<label>&nbsp;</label>
<input type="checkbox" id="node-input-pressure" style="display: inline-block; width: auto; vertical-align: top;"> Pressure<br/>
<label>&nbsp;</label>
<input type="checkbox" id="node-input-magnetometer" style="display: inline-block; width: auto; vertical-align: top;"> Magnetometer<br/>
<label>&nbsp;</label>
<input type="checkbox" id="node-input-accelerometer" style="display: inline-block; width: auto; vertical-align: top;"> Accelerometer<br/>
<label>&nbsp;</label>
<input type="checkbox" id="node-input-gyroscope" style="display: inline-block; width: auto; vertical-align: top;"> Gyroscope<br/>
<label>&nbsp;</label>
<input type="checkbox" id="node-input-luxometer" style="display: inline-block; width: auto; vertical-align: top;"> Luminosity (CC2650 only)<br/>
<label>&nbsp;</label>
<input type="checkbox" id="node-input-keys" style="display: inline-block; width: auto; vertical-align: top;"> Button press<br/>
</div>
<div class="form-row">
<label for="node-input-topic"><i class="fa fa-tasks"></i> Topic</label>
<input type="text" id="node-input-topic" placeholder="optional topic prefix - defaults to device id">
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-topic"><i class="fa fa-tag"></i> Topic</label>
<input type="text" id="node-input-topic" >
</div>
<div class="form-row">
<label for="node-input-uuid"><i class="fa fa-tag"></i> UUID</label>
<input type="text" id="node-input-uuid" >
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Temperature</label>
<input type="checkbox" id="node-input-temperature" placeholder="">
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Humidity</label>
<input type="checkbox" id="node-input-humidity" >
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Pressure</label>
<input type="checkbox" id="node-input-pressure" >
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Magnetometer</label>
<input type="checkbox" id="node-input-magnetometer" >
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Accelerometer</label>
<input type="checkbox" id="node-input-accelerometer" >
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Gyroscope</label>
<input type="checkbox" id="node-input-gyroscope" >
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Keys</label>
<input type="checkbox" id="node-input-keys" >
</div>
</script>
<!-- Next, some simple help text is provided for the node. -->
<script type="text/x-red" data-help-name="sensorTag">
<!-- data-help-name identifies the node type this help is for -->
<!-- This content appears in the Info sidebar when a node is selected -->
<!-- The first <p> is used as the pop-up tool tip when hovering over a -->
<!-- node in the palette. -->
<p>Input node for the Ti SensorTag</p>
<p>For this node to work correctly Node-Red needs to be run as <i>root</i>
, this due to how Bluetooth 4.0 support is currently implemented in
@ -86,20 +57,19 @@
active in range at the same time. (note you can only have one SensorTag
per node-red instance at the moment)</p>
<p>The topic setting is a prefix that will be pre-pended to name of the
sensor that creates the reading. e.g. <i>sensorTag/temperature</i></p>
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,
if you add more than one to the canvas then only the first to connect
will work.</p>
</script>
<!-- Finally, the node type is registered along with all of its properties -->
<!-- The example below shows a small subset of the properties that can be set-->
<script type="text/javascript">
RED.nodes.registerType('sensorTag',{
category: 'advanced-function', // the palette category
category: 'advanced-function',
color:"GoldenRod",
defaults: { // defines the editable properties of the node
name: {value:"sensorTag"}, // along with default values.
defaults: {
name: {value:"sensorTag"},
topic: {value:"sensorTag"},
uuid: {value:undefined},
temperature: {value:true},
@ -108,21 +78,22 @@
magnetometer: {value:true},
accelerometer: {value:true},
gyroscope: {value:true},
keys: {value:true}
keys: {value:true},
luxometer: {value:false}
},
inputs:0, // set the number of inputs - only 0 or 1
outputs:1, // set the number of outputs - 0 to n
icon: "bluetooth.png", // set the icon (held in public/icons)
label: function() { // sets the default label contents
inputs:0,
outputs:1,
icon: "bluetooth.png",
label: function() {
return this.name||this.topic||"sensorTag";
},
labelStyle: function() { // sets the class to apply to the label
labelStyle: function() {
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
// nasty hack as I can't get global replace to work
mac = mac.replace(/:/gi,'');
mac = mac.replace(/:/gi,'');
mac = mac.replace(/:/gi,'');

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013 IBM Corp.
* Copyright 2014,2015 IBM Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -14,12 +14,11 @@
* limitations under the License.
**/
// Require main module
var RED = require(process.env.NODE_RED_HOME+"/red/red");
var SensorTag = require('sensortag');
module.exports = function(RED) {
"use strict";
var SensorTag = require('sensortag');
// The main node definition - most things happen in here
function sensorTagNode(n) {
function sensorTagNode(n) {
RED.nodes.createNode(this,n);
this.name = n.name;
this.topic = n.topic;
@ -30,19 +29,17 @@ function sensorTagNode(n) {
this.accelerometer = n.accelerometer;
this.magnetometer = n.magnetometer;
this.gyroscope = n.gyroscope;
this.luxometer = n.luxometer;
this.keys = n.keys;
if (this.uuid === "") { this.uuid = undefined; }
var node = this;
if (this.uuid === "") {
this.uuid = undefined;
}
//console.log(this.uuid);
var node=this;
if ( typeof node.stag == "undefined") {
//console.log("starting");
if ( typeof node.stag === "undefined") {
SensorTag.discover(function(sensorTag) {
node.stag = sensorTag;
//console.log(sensorTag);
node.log("connected " + sensorTag._peripheral.uuid);
node.topic = node.topic || sensorTag._peripheral.uuid;
sensorTag.connect(function() {
//console.log("connected");
sensorTag.discoverServicesAndCharacteristics(function() {
@ -50,41 +47,41 @@ function sensorTagNode(n) {
sensorTag.on('irTemperatureChange',
function(objectTemperature, ambientTemperature) {
var msg = {'topic': node.topic + '/temperature'};
msg.payload = {'object': objectTemperature.toFixed(1),
'ambient':ambientTemperature.toFixed(1)
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 = {'pres': pressure.toFixed(1)};
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 = {'temp': temp.toFixed(1),
'humidity': humidity.toFixed(1)
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, 'y': y, 'z': z};
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, 'y': y, 'z': z};
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, 'y': y, 'z': z};
msg.payload = {'x': +x.toFixed(2), 'y': +y.toFixed(2), 'z': +z.toFixed(2)};
node.send(msg);
});
sensorTag.on('simpleKeyChange', function(left, right) {
@ -92,17 +89,29 @@ function sensorTagNode(n) {
msg.payload = {'left': left, 'right': right};
node.send(msg);
});
sensorTag.enableLuxometer(function() {});
sensorTag.on('luxometerChange', function(lux) {
var msg = {'topic': node.topic + '/luxometer'};
msg.payload = {'lux': parseInt(lux)};
node.send(msg);
});
enable(node);
});
});
},node.uuid);
} else {
//console.log("reconfig");
console.log("reconfig",node.uuid);
enable(node);
}
}
function enable(node) {
this.on("close", function() {
if (node.stag) {
node.stag.disconnect(function() { node.log("disconnected ",node.uuid); });
}
});
}
function enable(node) {
if (node.temperature) {
node.stag.notifyIrTemperature(function() {});
} else {
@ -133,10 +142,16 @@ function enable(node) {
} else {
node.stag.unnotifyGyroscope(function() {});
}
if (node.luxometer) {
node.stag.notifyLuxometer(function() {});
} else {
node.stag.unnotifyLuxometer(function() {});
}
if (node.keys) {
node.stag.notifySimpleKey(function() {});
} else {
node.stag.unnotifySimpleKey(function() {});
}
}
RED.nodes.registerType("sensorTag",sensorTagNode);
}
RED.nodes.registerType("sensorTag",sensorTagNode);

View File

@ -4,25 +4,28 @@ node-red-node-sensortag
This node adds support to Node-RED to read from the Texas Instruments SensorTag.
The SensorTag is a Bluetooth LE device hosting the following sensors:
* Ambient & ir Temperature
* Humidity and Temperature
* Ambient & IR Temperatures
* Barometric Pressure
* Humidity
* 3 axis Accelerometer
* 3 axis Magnetometer
* 3 axis Gyroscope
* 3 axis Magnetometer
* 2 push Buttons
* 1 Luxometer (CC2650 version only)
The config node allows the user to enable/disable any of the sensors listed above. The readings from
these sensors will be sent as a JSON object payload with the sensor name appended to the topic provided:
* Temperature - { topic: [topic_prefix]/temperature, payload: { ambient: 21.2, object: 33.0 } }
* Barometric Pressure - { topic: [topic_prefix]/pressure, payload: { pres: 1000.1 } }
* Humidity - { topic: [topic_prefix]/humidity , payload: { temp: 21.2, humidity: 88} }
* Accelerometer - { topic: [topic_prefix]/ , payload: { x:0.0, y:9.8, z:0.0 } }
* Magnetometer - { topic: [topic_prefix]/ , payload: { x:0.0, y:0.0, z:0.0 } }
* Gyroscope - { topic: [topic_prefix]/ , payload: { x:0.0, y:0.0, z:0.0 } }
* Buttons - { topic: [topic_prefix]/ , payload: { left: "down", right: "up"} }
* Temperature - { topic: [topic_prefix]/temperature, payload: { ambient: 21.2, object: 33.0 } }
* Barometric Pressure - { topic: [topic_prefix]/pressure, payload: { pres: 1000 } }
* Accelerometer - { topic: [topic_prefix]/accelerometer , payload: { x:0.0, y:9.8, z:0.0 } }
* Magnetometer - { topic: [topic_prefix]/magnetometer , payload: { x:0.0, y:0.0, z:0.0 } }
* Gyroscope - { topic: [topic_prefix]/gyroscope , payload: { x:0.0, y:0.0, z:0.0 } }
* Luxometer - { topic: [topic_prefix]/luxometer , payload: { lux: 212 } }
* Buttons - { topic: [topic_prefix]/keys , payload: { left: true, right: false} }
The sensorTag library used by this node only supports using 1 SensorTag at once.
The sensorTag library used by this node only supports using 1 SensorTag at a time.
**NOTE:** Node-RED needs to be run as root inorder or access the Linux Bluetooth 4.0 system calls
**NOTE:** On Linux Node-RED needs to be run as root in order or access the Linux Bluetooth 4.0 system calls

View File

@ -1,10 +1,10 @@
{
"name": "node-red-node-sensortag",
"description": "A Node-RED node to read data from a TI SensorTag",
"version": "0.0.4",
"version": "0.0.5",
"keywords" : ["node-red","sensortag"],
"dependencies": {
"sensortag" : "~1.0.1"
"sensortag": "~1.0.1"
},
"license": "Apache-2.0",
"repository" : {