@stoprocent/noble 1.19.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +393 -650
- package/examples/advertisement-discovery.js +57 -48
- package/examples/connect-address.js +59 -34
- package/examples/echo.js +59 -69
- package/examples/enter-exit.js +55 -49
- package/examples/multiple-bindings.js +53 -0
- package/examples/peripheral-explorer-async.js +39 -21
- package/examples/peripheral-explorer.ts +52 -0
- package/index.d.ts +249 -209
- package/index.js +4 -1
- package/jest.config.js +4 -0
- package/lib/characteristic.js +153 -127
- package/lib/{win/src/callbacks.h → common/include/Emit.h} +17 -14
- package/lib/common/include/Peripheral.h +31 -0
- package/lib/common/include/ThreadSafeCallback.h +95 -0
- package/lib/{win/src/callbacks.cc → common/src/Emit.cc} +111 -68
- package/lib/descriptor.js +57 -54
- package/lib/hci-socket/acl-stream.js +2 -4
- package/lib/hci-socket/bindings.js +96 -73
- package/lib/hci-socket/gap.js +2 -3
- package/lib/hci-socket/gatt.js +2 -5
- package/lib/hci-socket/hci.js +19 -7
- package/lib/hci-socket/signaling.js +2 -3
- package/lib/hci-socket/smp.js +2 -3
- package/lib/hci-socket/vs.js +1 -0
- package/lib/mac/binding.gyp +5 -7
- package/lib/mac/bindings.js +1 -3
- package/lib/mac/src/ble_manager.h +1 -8
- package/lib/mac/src/ble_manager.mm +87 -44
- package/lib/mac/src/napi_objc.h +1 -0
- package/lib/mac/src/napi_objc.mm +0 -6
- package/lib/mac/src/noble_mac.h +5 -3
- package/lib/mac/src/noble_mac.mm +99 -57
- package/lib/mac/src/objc_cpp.h +3 -2
- package/lib/mac/src/objc_cpp.mm +0 -6
- package/lib/noble.js +579 -488
- package/lib/peripheral.js +171 -174
- package/lib/resolve-bindings.js +37 -30
- package/lib/service.js +58 -55
- package/lib/win/binding.gyp +4 -11
- package/lib/win/bindings.js +1 -3
- package/lib/win/src/ble_manager.cc +291 -166
- package/lib/win/src/ble_manager.h +11 -13
- package/lib/win/src/napi_winrt.cc +1 -7
- package/lib/win/src/napi_winrt.h +1 -1
- package/lib/win/src/noble_winrt.cc +88 -61
- package/lib/win/src/noble_winrt.h +5 -3
- package/lib/win/src/notify_map.cc +0 -7
- package/lib/win/src/notify_map.h +1 -8
- package/lib/win/src/peripheral_winrt.cc +29 -11
- package/lib/win/src/peripheral_winrt.h +1 -1
- package/lib/win/src/radio_watcher.cc +79 -69
- package/lib/win/src/radio_watcher.h +30 -11
- package/lib/win/src/winrt_cpp.cc +1 -1
- package/lib/win/src/winrt_cpp.h +3 -0
- package/package.json +14 -17
- package/prebuilds/darwin-x64+arm64/@stoprocent+noble.node +0 -0
- package/prebuilds/win32-ia32/@stoprocent+noble.node +0 -0
- package/prebuilds/win32-x64/@stoprocent+noble.node +0 -0
- package/test/lib/characteristic.test.js +202 -322
- package/test/lib/descriptor.test.js +62 -95
- package/test/lib/hci-socket/acl-stream.test.js +112 -108
- package/test/lib/hci-socket/bindings.test.js +576 -365
- package/test/lib/hci-socket/hci.test.js +442 -473
- package/test/lib/hci-socket/signaling.test.js +45 -48
- package/test/lib/hci-socket/smp.test.js +144 -142
- package/test/lib/hci-socket/vs.test.js +193 -18
- package/test/lib/peripheral.test.js +492 -322
- package/test/lib/resolve-bindings.test.js +207 -82
- package/test/lib/service.test.js +79 -88
- package/test/noble.test.js +381 -1085
- package/.editorconfig +0 -11
- package/.nycrc.json +0 -4
- package/codecov.yml +0 -5
- package/examples/cache-gatt-discovery.js +0 -198
- package/examples/cache-gatt-reconnect.js +0 -164
- package/examples/ext-advertisement-discovery.js +0 -65
- package/examples/peripheral-explorer.js +0 -225
- package/examples/pizza/central.js +0 -194
- package/examples/pizza/pizza.js +0 -60
- package/examples/test/test.custom.js +0 -131
- package/examples/uart-bind-params.js +0 -28
- package/lib/distributed/bindings.js +0 -326
- package/lib/mac/src/callbacks.cc +0 -222
- package/lib/mac/src/callbacks.h +0 -84
- package/lib/mac/src/peripheral.h +0 -23
- package/lib/resolve-bindings-web.js +0 -9
- package/lib/webbluetooth/bindings.js +0 -368
- package/lib/websocket/bindings.js +0 -321
- package/lib/win/src/peripheral.h +0 -23
- package/test/lib/distributed/bindings.test.js +0 -918
- package/test/lib/webbluetooth/bindings.test.js +0 -190
- package/test/lib/websocket/bindings.test.js +0 -456
- package/test/mocha.setup.js +0 -0
- package/with-bindings.js +0 -5
- package/with-custom-binding.js +0 -6
- package/ws-slave.js +0 -404
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
/* eslint-disable handle-callback-err */
|
|
2
|
-
const noble = require('../..');
|
|
3
|
-
const pizza = require('./pizza');
|
|
4
|
-
|
|
5
|
-
const pizzaServiceUuid = '13333333333333333333333333333337';
|
|
6
|
-
const pizzaCrustCharacteristicUuid = '13333333333333333333333333330001';
|
|
7
|
-
const pizzaToppingsCharacteristicUuid = '13333333333333333333333333330002';
|
|
8
|
-
const pizzaBakeCharacteristicUuid = '13333333333333333333333333330003';
|
|
9
|
-
|
|
10
|
-
noble.on('stateChange', function (state) {
|
|
11
|
-
if (state === 'poweredOn') {
|
|
12
|
-
//
|
|
13
|
-
// Once the BLE radio has been powered on, it is possible
|
|
14
|
-
// to begin scanning for services. Pass an empty array to
|
|
15
|
-
// scan for all services (uses more time and power).
|
|
16
|
-
//
|
|
17
|
-
console.log('scanning...');
|
|
18
|
-
noble.startScanning([pizzaServiceUuid], false);
|
|
19
|
-
} else {
|
|
20
|
-
noble.stopScanning();
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
let pizzaCrustCharacteristic = null;
|
|
25
|
-
let pizzaToppingsCharacteristic = null;
|
|
26
|
-
let pizzaBakeCharacteristic = null;
|
|
27
|
-
|
|
28
|
-
noble.on('discover', function (peripheral) {
|
|
29
|
-
// we found a peripheral, stop scanning
|
|
30
|
-
noble.stopScanning();
|
|
31
|
-
|
|
32
|
-
//
|
|
33
|
-
// The advertisment data contains a name, power level (if available),
|
|
34
|
-
// certain advertised service uuids, as well as manufacturer data,
|
|
35
|
-
// which could be formatted as an iBeacon.
|
|
36
|
-
//
|
|
37
|
-
console.log('found peripheral:', peripheral.advertisement);
|
|
38
|
-
//
|
|
39
|
-
// Once the peripheral has been discovered, then connect to it.
|
|
40
|
-
//
|
|
41
|
-
peripheral.connect(function (error) {
|
|
42
|
-
if (error) {
|
|
43
|
-
console.error(error);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
//
|
|
47
|
-
// Once the peripheral has been connected, then discover the
|
|
48
|
-
// services and characteristics of interest.
|
|
49
|
-
//
|
|
50
|
-
peripheral.discoverServices([pizzaServiceUuid], function (error, services) {
|
|
51
|
-
if (error) {
|
|
52
|
-
console.error(error);
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
services.forEach(function (service) {
|
|
57
|
-
//
|
|
58
|
-
// This must be the service we were looking for.
|
|
59
|
-
//
|
|
60
|
-
console.log('found service:', service.uuid);
|
|
61
|
-
|
|
62
|
-
//
|
|
63
|
-
// So, discover its characteristics.
|
|
64
|
-
//
|
|
65
|
-
service.discoverCharacteristics([], function (error, characteristics) {
|
|
66
|
-
if (error) {
|
|
67
|
-
console.error(error);
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
characteristics.forEach(function (characteristic) {
|
|
72
|
-
//
|
|
73
|
-
// Loop through each characteristic and match them to the
|
|
74
|
-
// UUIDs that we know about.
|
|
75
|
-
//
|
|
76
|
-
console.log('found characteristic:', characteristic.uuid);
|
|
77
|
-
|
|
78
|
-
if (pizzaCrustCharacteristicUuid === characteristic.uuid) {
|
|
79
|
-
pizzaCrustCharacteristic = characteristic;
|
|
80
|
-
} else if (
|
|
81
|
-
pizzaToppingsCharacteristicUuid === characteristic.uuid
|
|
82
|
-
) {
|
|
83
|
-
pizzaToppingsCharacteristic = characteristic;
|
|
84
|
-
} else if (pizzaBakeCharacteristicUuid === characteristic.uuid) {
|
|
85
|
-
pizzaBakeCharacteristic = characteristic;
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
//
|
|
90
|
-
// Check to see if we found all of our characteristics.
|
|
91
|
-
//
|
|
92
|
-
if (
|
|
93
|
-
pizzaCrustCharacteristic &&
|
|
94
|
-
pizzaToppingsCharacteristic &&
|
|
95
|
-
pizzaBakeCharacteristic
|
|
96
|
-
) {
|
|
97
|
-
//
|
|
98
|
-
// We did, so bake a pizza!
|
|
99
|
-
//
|
|
100
|
-
bakePizza();
|
|
101
|
-
} else {
|
|
102
|
-
console.log('missing characteristics');
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
function bakePizza () {
|
|
111
|
-
//
|
|
112
|
-
// Pick the crust.
|
|
113
|
-
//
|
|
114
|
-
const crust = Buffer.alloc(1);
|
|
115
|
-
crust.writeUInt8(pizza.PizzaCrust.THIN, 0);
|
|
116
|
-
pizzaCrustCharacteristic.write(crust, false, function (err) {
|
|
117
|
-
if (!err) {
|
|
118
|
-
//
|
|
119
|
-
// Pick the toppings.
|
|
120
|
-
//
|
|
121
|
-
const toppings = Buffer.alloc(2);
|
|
122
|
-
toppings.writeUInt16BE(
|
|
123
|
-
pizza.PizzaToppings.EXTRA_CHEESE |
|
|
124
|
-
pizza.PizzaToppings.CANADIAN_BACON |
|
|
125
|
-
pizza.PizzaToppings.PINEAPPLE,
|
|
126
|
-
0
|
|
127
|
-
);
|
|
128
|
-
pizzaToppingsCharacteristic.write(toppings, false, function (err) {
|
|
129
|
-
if (!err) {
|
|
130
|
-
//
|
|
131
|
-
// Subscribe to the bake notification, so we know when
|
|
132
|
-
// our pizza will be ready.
|
|
133
|
-
//
|
|
134
|
-
pizzaBakeCharacteristic.on('read', function (data, isNotification) {
|
|
135
|
-
console.log('Our pizza is ready!');
|
|
136
|
-
if (data.length === 1) {
|
|
137
|
-
const result = data.readUInt8(0);
|
|
138
|
-
console.log('The result is',
|
|
139
|
-
result === pizza.PizzaBakeResult.HALF_BAKED
|
|
140
|
-
? 'half baked.'
|
|
141
|
-
: result === pizza.PizzaBakeResult.BAKED
|
|
142
|
-
? 'baked.'
|
|
143
|
-
: result === pizza.PizzaBakeResult.CRISPY
|
|
144
|
-
? 'crispy.'
|
|
145
|
-
: result === pizza.PizzaBakeResult.BURNT
|
|
146
|
-
? 'burnt.'
|
|
147
|
-
: result === pizza.PizzaBakeResult.ON_FIRE
|
|
148
|
-
? 'on fire!'
|
|
149
|
-
: 'unknown?');
|
|
150
|
-
} else {
|
|
151
|
-
console.log('result length incorrect');
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
pizzaBakeCharacteristic.subscribe(function (error) {
|
|
155
|
-
if (error) {
|
|
156
|
-
console.error(error);
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
//
|
|
161
|
-
// Bake at 450 degrees!
|
|
162
|
-
//
|
|
163
|
-
const temperature = Buffer.alloc(2);
|
|
164
|
-
temperature.writeUInt16BE(450, 0);
|
|
165
|
-
pizzaBakeCharacteristic.write(temperature, false, function (err) {
|
|
166
|
-
if (err) {
|
|
167
|
-
console.log('bake error');
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
} else {
|
|
172
|
-
console.log('toppings error');
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
} else {
|
|
176
|
-
console.log('crust error');
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
process.on('SIGINT', function () {
|
|
182
|
-
console.log('Caught interrupt signal');
|
|
183
|
-
noble.stopScanning(() => process.exit());
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
process.on('SIGQUIT', function () {
|
|
187
|
-
console.log('Caught interrupt signal');
|
|
188
|
-
noble.stopScanning(() => process.exit());
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
process.on('SIGTERM', function () {
|
|
192
|
-
console.log('Caught interrupt signal');
|
|
193
|
-
noble.stopScanning(() => process.exit());
|
|
194
|
-
});
|
package/examples/pizza/pizza.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
const util = require('util');
|
|
2
|
-
const events = require('events');
|
|
3
|
-
|
|
4
|
-
const PizzaCrust = {
|
|
5
|
-
NORMAL: 0,
|
|
6
|
-
DEEP_DISH: 1,
|
|
7
|
-
THIN: 2
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
const PizzaToppings = {
|
|
11
|
-
NONE: 0,
|
|
12
|
-
PEPPERONI: 1 << 0,
|
|
13
|
-
MUSHROOMS: 1 << 1,
|
|
14
|
-
EXTRA_CHEESE: 1 << 2,
|
|
15
|
-
BLACK_OLIVES: 1 << 3,
|
|
16
|
-
CANADIAN_BACON: 1 << 4,
|
|
17
|
-
PINEAPPLE: 1 << 5,
|
|
18
|
-
BELL_PEPPERS: 1 << 6,
|
|
19
|
-
SAUSAGE: 1 << 7
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const PizzaBakeResult = {
|
|
23
|
-
HALF_BAKED: 0,
|
|
24
|
-
BAKED: 1,
|
|
25
|
-
CRISPY: 2,
|
|
26
|
-
BURNT: 3,
|
|
27
|
-
ON_FIRE: 4
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
function Pizza () {
|
|
31
|
-
events.EventEmitter.call(this);
|
|
32
|
-
this.toppings = PizzaToppings.NONE;
|
|
33
|
-
this.crust = PizzaCrust.NORMAL;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
util.inherits(Pizza, events.EventEmitter);
|
|
37
|
-
|
|
38
|
-
Pizza.prototype.bake = function (temperature) {
|
|
39
|
-
const time = temperature * 10;
|
|
40
|
-
const self = this;
|
|
41
|
-
console.log('baking pizza at', temperature, 'degrees for', time, 'milliseconds');
|
|
42
|
-
setTimeout(function () {
|
|
43
|
-
const result =
|
|
44
|
-
(temperature < 350)
|
|
45
|
-
? PizzaBakeResult.HALF_BAKED
|
|
46
|
-
: (temperature < 450)
|
|
47
|
-
? PizzaBakeResult.BAKED
|
|
48
|
-
: (temperature < 500)
|
|
49
|
-
? PizzaBakeResult.CRISPY
|
|
50
|
-
: (temperature < 600)
|
|
51
|
-
? PizzaBakeResult.BURNT
|
|
52
|
-
: PizzaBakeResult.ON_FIRE;
|
|
53
|
-
self.emit('ready', result);
|
|
54
|
-
}, time);
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
module.exports.Pizza = Pizza;
|
|
58
|
-
module.exports.PizzaToppings = PizzaToppings;
|
|
59
|
-
module.exports.PizzaCrust = PizzaCrust;
|
|
60
|
-
module.exports.PizzaBakeResult = PizzaBakeResult;
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
const noble = require('../../with-custom-binding')({ extended: true });
|
|
2
|
-
|
|
3
|
-
console.log('noble');
|
|
4
|
-
|
|
5
|
-
noble.on('stateChange', function (state) {
|
|
6
|
-
console.log('on -> stateChange: ' + state);
|
|
7
|
-
|
|
8
|
-
if (state === 'poweredOn') {
|
|
9
|
-
noble.startScanning([], true);
|
|
10
|
-
} else {
|
|
11
|
-
noble.stopScanning();
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
noble.on('scanStart', function () {
|
|
16
|
-
console.log('on -> scanStart');
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
noble.on('scanStop', function () {
|
|
20
|
-
console.log('on -> scanStop');
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
noble.on('discover', function (peripheral) {
|
|
24
|
-
console.log('on -> discover: ' + peripheral);
|
|
25
|
-
|
|
26
|
-
noble.stopScanning();
|
|
27
|
-
|
|
28
|
-
peripheral.on('connect', function () {
|
|
29
|
-
console.log('on -> connect');
|
|
30
|
-
this.updateRssi();
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
peripheral.on('disconnect', function () {
|
|
34
|
-
console.log('on -> disconnect');
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
peripheral.on('rssiUpdate', function (rssi) {
|
|
38
|
-
console.log('on -> RSSI update ' + rssi);
|
|
39
|
-
this.discoverServices();
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
peripheral.on('servicesDiscover', function (services) {
|
|
43
|
-
console.log('on -> peripheral services discovered ' + services);
|
|
44
|
-
|
|
45
|
-
const serviceIndex = 0;
|
|
46
|
-
|
|
47
|
-
services[serviceIndex].on(
|
|
48
|
-
'includedServicesDiscover',
|
|
49
|
-
function (includedServiceUuids) {
|
|
50
|
-
console.log(
|
|
51
|
-
'on -> service included services discovered ' + includedServiceUuids
|
|
52
|
-
);
|
|
53
|
-
this.discoverCharacteristics();
|
|
54
|
-
}
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
services[serviceIndex].on(
|
|
58
|
-
'characteristicsDiscover',
|
|
59
|
-
function (characteristics) {
|
|
60
|
-
console.log(
|
|
61
|
-
'on -> service characteristics discovered ' + characteristics
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
const characteristicIndex = 0;
|
|
65
|
-
|
|
66
|
-
characteristics[characteristicIndex].on(
|
|
67
|
-
'read',
|
|
68
|
-
function (data, isNotification) {
|
|
69
|
-
console.log(
|
|
70
|
-
'on -> characteristic read ' + data + ' ' + isNotification
|
|
71
|
-
);
|
|
72
|
-
console.log(data);
|
|
73
|
-
|
|
74
|
-
peripheral.disconnect();
|
|
75
|
-
}
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
characteristics[characteristicIndex].on('write', function () {
|
|
79
|
-
console.log('on -> characteristic write ');
|
|
80
|
-
|
|
81
|
-
peripheral.disconnect();
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
characteristics[characteristicIndex].on('broadcast', function (state) {
|
|
85
|
-
console.log('on -> characteristic broadcast ' + state);
|
|
86
|
-
|
|
87
|
-
peripheral.disconnect();
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
characteristics[characteristicIndex].on('notify', function (state) {
|
|
91
|
-
console.log('on -> characteristic notify ' + state);
|
|
92
|
-
|
|
93
|
-
peripheral.disconnect();
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
characteristics[characteristicIndex].on(
|
|
97
|
-
'descriptorsDiscover',
|
|
98
|
-
function (descriptors) {
|
|
99
|
-
console.log('on -> descriptors discover ' + descriptors);
|
|
100
|
-
|
|
101
|
-
const descriptorIndex = 0;
|
|
102
|
-
|
|
103
|
-
descriptors[descriptorIndex].on('valueRead', function (data) {
|
|
104
|
-
console.log('on -> descriptor value read ' + data);
|
|
105
|
-
console.log(data);
|
|
106
|
-
peripheral.disconnect();
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
descriptors[descriptorIndex].on('valueWrite', function () {
|
|
110
|
-
console.log('on -> descriptor value write ');
|
|
111
|
-
peripheral.disconnect();
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
descriptors[descriptorIndex].readValue();
|
|
115
|
-
// descriptors[descriptorIndex].writeValue(new Buffer([0]));
|
|
116
|
-
}
|
|
117
|
-
);
|
|
118
|
-
|
|
119
|
-
characteristics[characteristicIndex].read();
|
|
120
|
-
// characteristics[characteristicIndex].write(new Buffer('hello'));
|
|
121
|
-
// characteristics[characteristicIndex].broadcast(true);
|
|
122
|
-
// characteristics[characteristicIndex].notify(true);
|
|
123
|
-
// characteristics[characteristicIndex].discoverDescriptors();
|
|
124
|
-
}
|
|
125
|
-
);
|
|
126
|
-
|
|
127
|
-
services[serviceIndex].discoverIncludedServices();
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
peripheral.connect();
|
|
131
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
const noble = require('../with-custom-binding');
|
|
2
|
-
|
|
3
|
-
// Needs to export env: BLUETOOTH_HCI_SOCKET_FORCE_UART=1
|
|
4
|
-
|
|
5
|
-
const nobleUartA = noble({ bindParams: { uart: { port: '/dev/tty.usbmodem1...' } } });
|
|
6
|
-
const nobleUartB = noble({ bindParams: { uart: { port: '/dev/tty.usbmodem2...' } } });
|
|
7
|
-
|
|
8
|
-
nobleUartA.on('discover', peripheral => {
|
|
9
|
-
console.log('UART A', peripheral.address);
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
nobleUartB.on('discover', peripheral => {
|
|
13
|
-
console.log('UART B', peripheral.address);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
nobleUartA.on('stateChange', state => {
|
|
17
|
-
if (state === 'poweredOn') {
|
|
18
|
-
nobleUartA.setAddress('00:11:22:33:44:01');
|
|
19
|
-
nobleUartA.startScanning();
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
nobleUartB.on('stateChange', state => {
|
|
24
|
-
if (state === 'poweredOn') {
|
|
25
|
-
nobleUartB.setAddress('00:11:22:33:44:02');
|
|
26
|
-
nobleUartB.startScanning();
|
|
27
|
-
}
|
|
28
|
-
});
|