|
19 | 19 | **/ |
20 | 20 |
|
21 | 21 | //might need to modify accordingly |
22 | | -var RED = require("../../red/red"); |
| 22 | +var RED = require(process.env.NODE_RED_HOME+"/red/red"); |
23 | 23 |
|
24 | 24 | //import noble |
25 | 25 | var noble = require('noble'); |
26 | 26 |
|
27 | 27 | // The main node definition - most things happen in here |
28 | 28 | function BleScan(n) { |
29 | | - // Create a RED node |
30 | | - RED.nodes.createNode(this,n); |
| 29 | + // Create a RED node |
| 30 | + RED.nodes.createNode(this,n); |
31 | 31 |
|
32 | 32 | var msg = {}; |
33 | | - var ble_name; |
34 | | - var node = this; |
35 | | - |
| 33 | + var ble_name; |
| 34 | + var node = this; |
| 35 | + |
36 | 36 | //get name and uuid from user |
37 | 37 | this.ble_name = n.ble_name; |
38 | 38 | this.ble_uuid = n.ble_uuid; |
39 | 39 |
|
40 | 40 | this.on("input", function(msg){ |
41 | | - noble.startScanning(); |
| 41 | + noble.startScanning(); |
42 | 42 | }); |
43 | 43 | noble.on('scanStart', function(msg) { |
44 | | - var msg = {}; |
45 | | - msg.topic = node.topic; |
46 | | - msg.payload = "Scanning initiated..." //debugging |
47 | | - //console.log('scanning initiated...'); |
48 | | - node.send(msg); |
| 44 | + var msg = {}; |
| 45 | + msg.topic = node.topic; |
| 46 | + msg.payload = "Scanning initiated..." //debugging |
| 47 | + //console.log('scanning initiated...'); |
| 48 | + node.send(msg); |
49 | 49 | }); |
50 | 50 |
|
51 | 51 | noble.on('discover', function(peripheral) { |
52 | 52 |
|
53 | | - var msg = {}; |
54 | | - msg.topic = node.topic; |
55 | | - msg.payload = "not found"; |
56 | | - |
57 | | - //check for the device name and the UUID (first one from the UUID list) |
58 | | - if(peripheral.advertisement.localName==node.ble_name && peripheral.advertisement.serviceUuids[0]==node.ble_uuid) { |
59 | | - msg.payload=peripheral.advertisement.localName; |
60 | | - noble.stopScanning(); } |
61 | | - node.send(msg); |
| 53 | + var msg = {}; |
| 54 | + msg.topic = node.topic; |
| 55 | + msg.payload = "not found"; |
| 56 | + |
| 57 | + //check for the device name and the UUID (first one from the UUID list) |
| 58 | + if(peripheral.advertisement.localName==node.ble_name && peripheral.advertisement.serviceUuids[0]==node.ble_uuid) { |
| 59 | + msg.payload=peripheral.advertisement.localName; |
| 60 | + noble.stopScanning(); } |
| 61 | + node.send(msg); |
62 | 62 | }); |
63 | 63 |
|
64 | | - this.on("close", function() { |
65 | | - try { noble.stopScanning(); } |
66 | | - catch (err) { console.log(err); } |
67 | | - }); |
| 64 | + this.on("close", function() { |
| 65 | + try { noble.stopScanning(); } |
| 66 | + catch (err) { console.log(err); } |
| 67 | + }); |
68 | 68 | } |
69 | 69 |
|
70 | 70 | // Register the node by name. This must be called before overriding any of the |
|
0 commit comments