update path to red.js to use environmnet variable

This commit is contained in:
Dave C-J 2013-10-26 22:19:43 +01:00
parent 50025428a5
commit 75aaaab1a9
3 changed files with 35 additions and 44 deletions

View File

@ -17,7 +17,7 @@
// Sample Node-RED node file
// Require main module
var RED = require("../../red/red");
var RED = require(process.env.NODE_RED_HOME+"/red/red");
var HID = require('node-hid');
var device;
var node;

View File

@ -19,15 +19,15 @@
**/
//might need to modify accordingly
var RED = require("../../red/red");
var RED = require(process.env.NODE_RED_HOME+"/red/red");
//import noble
var noble = require('noble');
// The main node definition - most things happen in here
function BleScan(n) {
// Create a RED node
RED.nodes.createNode(this,n);
// Create a RED node
RED.nodes.createNode(this,n);
var msg = {};
var ble_name;
@ -38,33 +38,33 @@ function BleScan(n) {
this.ble_uuid = n.ble_uuid;
this.on("input", function(msg){
noble.startScanning();
noble.startScanning();
});
noble.on('scanStart', function(msg) {
var msg = {};
msg.topic = node.topic;
msg.payload = "Scanning initiated..." //debugging
//console.log('scanning initiated...');
node.send(msg);
var msg = {};
msg.topic = node.topic;
msg.payload = "Scanning initiated..." //debugging
//console.log('scanning initiated...');
node.send(msg);
});
noble.on('discover', function(peripheral) {
var msg = {};
msg.topic = node.topic;
msg.payload = "not found";
var msg = {};
msg.topic = node.topic;
msg.payload = "not found";
//check for the device name and the UUID (first one from the UUID list)
if(peripheral.advertisement.localName==node.ble_name && peripheral.advertisement.serviceUuids[0]==node.ble_uuid) {
msg.payload=peripheral.advertisement.localName;
noble.stopScanning(); }
node.send(msg);
//check for the device name and the UUID (first one from the UUID list)
if(peripheral.advertisement.localName==node.ble_name && peripheral.advertisement.serviceUuids[0]==node.ble_uuid) {
msg.payload=peripheral.advertisement.localName;
noble.stopScanning(); }
node.send(msg);
});
this.on("close", function() {
try { noble.stopScanning(); }
catch (err) { console.log(err); }
});
this.on("close", function() {
try { noble.stopScanning(); }
catch (err) { console.log(err); }
});
}
// Register the node by name. This must be called before overriding any of the

View File

@ -14,17 +14,14 @@
* limitations under the License.
**/
// Sample Node-RED node file
// Require main module
var RED = require("../../red/red");
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) {
// Create a RED node
RED.nodes.createNode(this,n);
this.name = n.name;
this.topic = n.topic;
@ -98,8 +95,6 @@ function sensorTagNode(n) {
//console.log("reconfig");
enable();
}
}
function enable() {
@ -139,8 +134,4 @@ function enable() {
stag.unnotifySimpleKey(function() {});
}
}
// Register the node by name. This must be called before overriding any of the
// Node functions.
RED.nodes.registerType("sensorTag",sensorTagNode);