From 75aaaab1a9343a730157d8d4e0ca20230e352ef4 Mon Sep 17 00:00:00 2001 From: Dave C-J Date: Sat, 26 Oct 2013 22:19:43 +0100 Subject: [PATCH] update path to red.js to use environmnet variable --- hardware/digiRGB/78-digiRGB.js | 12 +++---- hardware/scanBLE/101-scanBLE.js | 50 +++++++++++++++--------------- hardware/sensorTag/79-sensorTag.js | 17 +++------- 3 files changed, 35 insertions(+), 44 deletions(-) diff --git a/hardware/digiRGB/78-digiRGB.js b/hardware/digiRGB/78-digiRGB.js index 717da0a3..226fc864 100644 --- a/hardware/digiRGB/78-digiRGB.js +++ b/hardware/digiRGB/78-digiRGB.js @@ -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; @@ -27,7 +27,7 @@ function DigiRGBNode(n) { // Create a RED node RED.nodes.createNode(this,n); node=this; - + var devices = HID.devices(0x16c0,0x05df); for (var i=0; i< devices.length; i++) { if (devices[i].product == 'DigiUSB') { @@ -39,13 +39,13 @@ function DigiRGBNode(n) { } catch (e) { node.log(e) } - } + } } - + var p1 = /^\#[A-Fa-f0-9]{6}$/ var p2 = /[0-9]+,[0-9]+,[0-9]+/ - - if (device) { + + if (device) { this.on("input", function(msg) { if (msg != null) { if (p1.test(msg.payload)) { diff --git a/hardware/scanBLE/101-scanBLE.js b/hardware/scanBLE/101-scanBLE.js index 04a308b5..24532e37 100644 --- a/hardware/scanBLE/101-scanBLE.js +++ b/hardware/scanBLE/101-scanBLE.js @@ -19,52 +19,52 @@ **/ //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; - var node = this; - + var ble_name; + var node = this; + //get name and uuid from user this.ble_name = n.ble_name; 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"; - - //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); + 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); }); - 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 diff --git a/hardware/sensorTag/79-sensorTag.js b/hardware/sensorTag/79-sensorTag.js index 92555099..c1252983 100644 --- a/hardware/sensorTag/79-sensorTag.js +++ b/hardware/sensorTag/79-sensorTag.js @@ -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; @@ -36,16 +33,16 @@ function sensorTagNode(n) { this.gyroscope = n.gyroscope; this.keys = n.keys; node=this; - + if ( typeof stag == "undefined") { //console.log("starting"); - SensorTag.discover(function(sensorTag){ + SensorTag.discover(function(sensorTag){ stag = sensorTag; sensorTag.connect(function(){ //console.log("connected"); sensorTag.discoverServicesAndCharacteristics(function(){ sensorTag.enableIrTemperature(function(){}); - sensorTag.on('irTemperatureChange', + sensorTag.on('irTemperatureChange', function(objectTemperature, ambientTemperature){ var msg = {'topic': node.topic + '/tempature'}; msg.payload = {'object': objectTemperature.toFixed(1), @@ -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); -