Skip to content

Commit 473678a

Browse files
author
Daisuke Baba
committed
Merge branch 'develop' of https://github.com/CANDY-LINE/node-red-contrib-generic-ble into develop
* 'develop' of https://github.com/CANDY-LINE/node-red-contrib-generic-ble: Add scanStart/scanStop/scanRestart commands
2 parents d5346c8 + d4c583c commit 473678a

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ The node should still work on macOS and Windows as nothing is modified for these
1111

1212
Supported operations are as follows:
1313

14+
- Start BLE Scanning
15+
- Stop BLE Scanning
16+
- Restart BLE Scanning (Stop then start BLE Scanning again)
17+
- Connect to a peripheral device
18+
- Disonnect from a peripheral device
1419
- Read
1520
- Write
1621
- Write without Response

src/generic-ble.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ function startBLEScanning(RED) {
183183
noble.addListener('error', handlers.onError);
184184

185185
if (noble.state === 'poweredOn') {
186+
RED.log.info(`[GenericBLE] Start BLE scanning`);
186187
noble.startScanning([], true);
187188
genericBleState.scanning = true;
188189
} else {
@@ -802,7 +803,19 @@ module.exports = function (RED) {
802803
// ignore
803804
}
804805
try {
805-
if (msg.topic === 'connect') {
806+
if (msg.topic === 'scanStart') {
807+
startBLEScanning(RED);
808+
return;
809+
} else if (msg.topic === 'scanStop') {
810+
stopBLEScanning(RED);
811+
return;
812+
} else if (msg.topic === 'scanRestart') {
813+
stopBLEScanning(RED);
814+
setTimeout(() => {
815+
startBLEScanning(RED);
816+
}, 1000);
817+
return;
818+
} else if (msg.topic === 'connect') {
806819
await this.genericBleNode.connectPeripheral();
807820
} else if (msg.topic === 'disconnect') {
808821
await this.genericBleNode.disconnectPeripheral();

src/locales/en-US/generic-ble.html

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,28 @@ <h3>Inputs</h3>
2222
<p>
2323
Expects a message used for peripheral connecting/disconnecting operation, triggering <code>Read</code> operation, or subscribing <code>Notify</code> events.
2424
<dl>
25-
<dt>For <code>Connect</code> operation:</dt>
25+
<dt>For <code>scanStart</code> operation:</dt>
26+
<dd>
27+
In order to start BLE scanning to discover peripheral devices, set <code>msg.topic</code> to <code>scanStart</code>.
28+
<code>msg.payload</code> is always ignored. This operation doesn't emit anything from the Output port.
29+
</dd>
30+
<dt>For <code>scanStop</code> operation:</dt>
31+
<dd>
32+
In order to stop BLE scanning, set <code>msg.topic</code> to <code>scanStop</code>.
33+
<code>msg.payload</code> is always ignored. This operation doesn't emit anything from the Output port.
34+
</dd>
35+
<dt>For <code>scanRestart</code> operation:</dt>
36+
<dd>
37+
In order to restart BLE scanning, set <code>msg.topic</code> to <code>scanRestart</code>.
38+
This operation performs <code>ScanStop</code> then <code>ScanStart</code>.
39+
<code>msg.payload</code> is always ignored. This operation doesn't emit anything from the Output port.
40+
</dd>
41+
<dt>For <code>connect</code> operation:</dt>
2642
<dd>
2743
In order to connect a peripheral device, set <code>msg.topic</code> to <code>connect</code>.
2844
<code>msg.payload</code> is always ignored. This operation doesn't emit anything from the Output port.
2945
</dd>
30-
<dt>For <code>Disonnect</code> operation:</dt>
46+
<dt>For <code>disconnect</code> operation:</dt>
3147
<dd>
3248
In order to disconnect a peripheral device, set <code>msg.topic</code> to <code>disconnect</code>.
3349
<code>msg.payload</code> is always ignored. This operation doesn't emit anything from the Output port.

0 commit comments

Comments
 (0)