node-red-contrib-noble.html 6.28 KB
Newer Older
Donald Chen's avatar
Donald Chen committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<!--
 Copyright (c) 2014. Knowledge Media Institute - The Open University

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->

<!--
 NodeRed node with support for BLE interaction

 @author <a href="mailto:carlos.pedrinaci@open.ac.uk">Carlos Pedrinaci</a> (KMi - The Open University)
-->

<script type="text/x-red" data-template-name="scan ble">
   <!-- 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 Twitter Bootstrap glyphicons  -->

    <!-- Limit to list of UUIDs -->
    <div class="form-row">
        <label for="node-input-uuids"><i class="fa fa-tasks"></i> Restrict by Service UUID</label>
        <input type="text" id="node-input-uuids" placeholder="Comma separated list">
    </div>
    <div class="form-tips">Leave empty for scanning all devices offering any service.</div>

    <!-- Allow duplicates -->
    <div class="form-row">
        <label>&nbsp;</label>
        <input type="checkbox" id="node-input-duplicates" style="display: inline-block; width: auto; vertical-align: top;">
        <label for="node-input-duplicates" style="width: 70%;">Allow duplicates?</label>
    </div>

    <!-- By convention, most nodes have a 'name' property. The following div -->
    <!-- provides the necessary field. Should always be the last option      -->

    <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>

</script>


<!-- Next, some simple help text is provided for the node.                   -->
<script type="text/x-red" data-help-name="scan ble">
    <p>This node allows scanning for BLE devices, restricted if necessary by the services they offer.</p>
    <p>This node will generate one message per BLE device detected according to the node configuration.</p>
    <p>The node will also generate events according to the status of the bluetooth interface when it changes. Those status messages include:</p>
     <ul>
        <li>Whether there was an <b>msg.error</b></li>
        <li>Whether there was a <b>msg.stateChange</b></li>
        <li>The current <b>msg.state</b> of the interface</li>
        <li>The <b>msg.payload</b> will be empty in this case to prevent mistreating status messages as BLE detection messages.</li>
    </ul>

    <p>The node will begin scanning after it is deployed, and will not stop until it is deployed again.  It can be useful to turn on and off scanning to conserve energy and force scan requests to be sent triggering devices to respond.  To control scanning, you may send a message containing <code>msg.payload.scan=false</code> to turn off scanning, and <code>msg.payload.scan=true</code> to turn it on.</p>

    <p>The output will contain in <b>msg.payload</b> the <i>peripheral uuid</i> and the <i>local name</i> of the BLE device detected.</p>
    <p>Additionally the node will set the following values:</p>
    <ul>
        <li>Sets the <b>msg.peripheralUuid</b> to the <i>peripheral uuid</i> of the BLE device detected.</li>
        <li>Sets the <b>msg.rssi</b> to the <i>received signal strength indicator (RSSI)</i> of the BLE device detected.</li>
        <li>Sets <b>msg.localName</b> to the name of the device if any.</li>
        <li>Sets <b>msg.detectedAt</b> to the moment the device was detected on milliseconds since 1 Jan 1970.</li>
        <li>Sets <b>msg.detectedBy</b> to the name of the machine that detected the BLE device.</li>
        <li>Sets <b>msg.advertisement</b> to the full advertisement of the BLE device (see Noble documentation).</li>
    </ul>
    <p>If the device follows the iBeacon specification, the message will also contain the following properties</p>
    <ul>
        <li>Sets the <b>msg.manufacturerUuid</b> to the <i>uuid</i> of the manufacturer of the BLE device detected.</li>
        <li>Sets the <b>msg.major</b> to the <i>major number</i> of the manufacturer of the BLE device detected.</li>
        <li>Sets the <b>msg.minor</b> to the <i>minor number</i> of the manufacturer of the BLE device detected.</li>
        <li>Sets the <b>msg.measuredPower</b> to the <i>measured power at one meter</i> of the BLE device detected.</li>
        <li>Sets the <b>msg.accuracy</b> to the <i>accuracy</i> estimated for this measurement.</li>
        <li>Sets the <b>msg.proximity</b> to the <i>proximity</i> guessed for this device. The value will be one of: 'unknown', 'immediate', 'near', 'far' </li>
    </ul>
</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('scan ble',{
98
99
        category: "Vesta DemoKit",      // the palette category
        color:"#A6BBCF",
Donald Chen's avatar
Donald Chen committed
100
101
102
103
104
105
106
107
108
109
110
111
112
        defaults: {             // defines the editable properties of the node
            uuids: {value:"", validate:RED.validators.regex(/^([a-fA-F0-9]{32}){0,1}(?:,[a-fA-F0-9]{32})*$/)},
            duplicates: {value:false},
            name: {value:""}
        },
        inputs:1,               // set the number of inputs - only 0 or 1
        outputs:1,              // set the number of outputs - 0 to n
        // set the icon (held in icons dir below where you save the node)
        icon: "bluetooth.png",     // saved in  icons/myicon.png
        label: function() {     // sets the default label contents
            if (this.name) {
                return this.name;
            } else {
113
                return "noble-scan";
Donald Chen's avatar
Donald Chen committed
114
115
116
117
            }
        }
    });
</script>