-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
api.md
527 lines (377 loc) · 17.9 KB
/
api.md
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
<!-------------------------------------------------------------------->
<!-- WARNING! -->
<!-------------------------------------------------------------------->
<!-- -->
<!-- THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -->
<!-- but run the following script $ npm run build -->
<!-- -->
<!-------------------------------------------------------------------->
<!-------------------------------------------------------------------->
# Node BLE APIs
## Classes
<dl>
<dt><a href="#Adapter">Adapter</a></dt>
<dd><p>Adapter class interacts with the local bluetooth adapter</p>
</dd>
<dt><a href="#Bluetooth">Bluetooth</a></dt>
<dd><p>Top level object that represent a bluetooth session</p>
</dd>
<dt><a href="#Device">Device</a> ⇐ <code>EventEmitter</code></dt>
<dd><p>Device class interacts with a remote device.</p>
</dd>
<dt><a href="#GattCharacteristic">GattCharacteristic</a> ⇐ <code>EventEmitter</code></dt>
<dd><p>GattCharacteristic class interacts with a GATT characteristic.</p>
</dd>
<dt><a href="#GattServer">GattServer</a></dt>
<dd><p>GattServer class that provides interaction with device GATT profile.</p>
</dd>
<dt><a href="#GattService">GattService</a></dt>
<dd><p>GattService class interacts with a remote GATT service.</p>
</dd>
</dl>
## Functions
<dl>
<dt><a href="#createBluetooth">createBluetooth()</a> ⇒ <code>NodeBleInit</code></dt>
<dd><p>Init bluetooth session and return</p>
</dd>
</dl>
## Typedefs
<dl>
<dt><a href="#WritingMode">WritingMode</a></dt>
<dd></dd>
<dt><a href="#NodeBleSession">NodeBleSession</a> : <code>Object</code></dt>
<dd></dd>
</dl>
# Specs
<a name="Adapter"></a>
## Adapter
Adapter class interacts with the local bluetooth adapter
**Kind**: global class
**See**: You can construct an Adapter session via [getAdapter](#Bluetooth+getAdapter) method
* [Adapter](#Adapter)
* [.getAddress()](#Adapter+getAddress) ⇒ <code>string</code>
* [.getAddressType()](#Adapter+getAddressType) ⇒ <code>string</code>
* [.getName()](#Adapter+getName) ⇒ <code>string</code>
* [.getAlias()](#Adapter+getAlias) ⇒ <code>string</code>
* [.isPowered()](#Adapter+isPowered) ⇒ <code>boolean</code>
* [.isDiscovering()](#Adapter+isDiscovering) ⇒ <code>boolean</code>
* [.startDiscovery()](#Adapter+startDiscovery)
* [.stopDiscovery()](#Adapter+stopDiscovery)
* [.devices()](#Adapter+devices) ⇒ <code>Array.<string></code>
* [.getDevice(uuid)](#Adapter+getDevice) ⇒ [<code>Device</code>](#Device)
* [.waitDevice(uuid, [timeout], [discoveryInterval])](#Adapter+waitDevice) ⇒ [<code>Device</code>](#Device)
* [.toString()](#Adapter+toString) ⇒ <code>string</code>
<a name="Adapter+getAddress"></a>
### adapter.getAddress() ⇒ <code>string</code>
The Bluetooth device address.
**Kind**: instance method of [<code>Adapter</code>](#Adapter)
<a name="Adapter+getAddressType"></a>
### adapter.getAddressType() ⇒ <code>string</code>
The Bluetooth device Address Type. (public, random)
**Kind**: instance method of [<code>Adapter</code>](#Adapter)
<a name="Adapter+getName"></a>
### adapter.getName() ⇒ <code>string</code>
The Bluetooth system name
**Kind**: instance method of [<code>Adapter</code>](#Adapter)
<a name="Adapter+getAlias"></a>
### adapter.getAlias() ⇒ <code>string</code>
The Bluetooth friendly name.
**Kind**: instance method of [<code>Adapter</code>](#Adapter)
<a name="Adapter+isPowered"></a>
### adapter.isPowered() ⇒ <code>boolean</code>
Current adapter state.
**Kind**: instance method of [<code>Adapter</code>](#Adapter)
<a name="Adapter+isDiscovering"></a>
### adapter.isDiscovering() ⇒ <code>boolean</code>
Indicates that a device discovery procedure is active.
**Kind**: instance method of [<code>Adapter</code>](#Adapter)
<a name="Adapter+startDiscovery"></a>
### adapter.startDiscovery()
This method starts the device discovery session.
**Kind**: instance method of [<code>Adapter</code>](#Adapter)
<a name="Adapter+stopDiscovery"></a>
### adapter.stopDiscovery()
This method will cancel any previous StartDiscovery transaction.
**Kind**: instance method of [<code>Adapter</code>](#Adapter)
<a name="Adapter+devices"></a>
### adapter.devices() ⇒ <code>Array.<string></code>
List of found device names (uuid).
**Kind**: instance method of [<code>Adapter</code>](#Adapter)
<a name="Adapter+getDevice"></a>
### adapter.getDevice(uuid) ⇒ [<code>Device</code>](#Device)
Init a device instance and returns it.
**Kind**: instance method of [<code>Adapter</code>](#Adapter)
| Param | Type | Description |
| --- | --- | --- |
| uuid | <code>string</code> | Device Name. |
<a name="Adapter+waitDevice"></a>
### adapter.waitDevice(uuid, [timeout], [discoveryInterval]) ⇒ [<code>Device</code>](#Device)
Wait that a specific device is found, then init a device instance and returns it.
**Kind**: instance method of [<code>Adapter</code>](#Adapter)
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| uuid | <code>string</code> | | Device Name. |
| [timeout] | <code>number</code> | <code>120000</code> | Time (ms) to wait before throwing a timeout expection. |
| [discoveryInterval] | <code>number</code> | <code>1000</code> | Interval (ms) frequency that verifies device availability. |
<a name="Adapter+toString"></a>
### adapter.toString() ⇒ <code>string</code>
Human readable class identifier.
**Kind**: instance method of [<code>Adapter</code>](#Adapter)
<a name="Bluetooth"></a>
## Bluetooth
Top level object that represent a bluetooth session
**Kind**: global class
**See**: You can construct a Bluetooth session via [createBluetooth](#createBluetooth) function
* [Bluetooth](#Bluetooth)
* [.adapters()](#Bluetooth+adapters) ⇒ <code>Array.<string></code>
* [.defaultAdapter()](#Bluetooth+defaultAdapter) ⇒ [<code>Adapter</code>](#Adapter)
* [.getAdapter(adapter)](#Bluetooth+getAdapter) ⇒ [<code>Adapter</code>](#Adapter)
<a name="Bluetooth+adapters"></a>
### bluetooth.adapters() ⇒ <code>Array.<string></code>
List of available adapter names
**Kind**: instance method of [<code>Bluetooth</code>](#Bluetooth)
<a name="Bluetooth+defaultAdapter"></a>
### bluetooth.defaultAdapter() ⇒ [<code>Adapter</code>](#Adapter)
Get first available adapter
**Kind**: instance method of [<code>Bluetooth</code>](#Bluetooth)
**Throws**:
- Will throw an error if there aren't available adapters.
<a name="Bluetooth+getAdapter"></a>
### bluetooth.getAdapter(adapter) ⇒ [<code>Adapter</code>](#Adapter)
Init an adapter instance and returns it
**Kind**: instance method of [<code>Bluetooth</code>](#Bluetooth)
**Throw**: Will throw adapter not found if provided name isn't valid.
| Param | Type | Description |
| --- | --- | --- |
| adapter | <code>string</code> | Name of an adapter |
<a name="Device"></a>
## Device ⇐ <code>EventEmitter</code>
Device class interacts with a remote device.
**Kind**: global class
**Extends**: <code>EventEmitter</code>
**See**: You can construct a Device object via [getDevice](#Adapter+getDevice) method
* [Device](#Device) ⇐ <code>EventEmitter</code>
* [.getName()](#Device+getName) ⇒ <code>string</code>
* [.getAddress()](#Device+getAddress) ⇒ <code>string</code>
* [.getAddressType()](#Device+getAddressType) ⇒ <code>string</code>
* [.getAlias()](#Device+getAlias) ⇒ <code>string</code>
* [.getRSSI()](#Device+getRSSI) ⇒ <code>number</code>
* [.getTXPower()](#Device+getTXPower) ⇒ <code>number</code>
* [.isPaired()](#Device+isPaired) ⇒ <code>boolean</code>
* [.isConnected()](#Device+isConnected) ⇒ <code>boolean</code>
* [.pair()](#Device+pair)
* [.cancelPair()](#Device+cancelPair)
* [.connect()](#Device+connect)
* [.disconnect()](#Device+disconnect)
* [.gatt()](#Device+gatt) ⇒ [<code>GattServer</code>](#GattServer)
* [.toString()](#Device+toString) ⇒ <code>string</code>
* ["connect"](#Device+event_connect)
* ["disconnect"](#Device+event_disconnect)
<a name="Device+getName"></a>
### device.getName() ⇒ <code>string</code>
The Bluetooth remote name.
**Kind**: instance method of [<code>Device</code>](#Device)
<a name="Device+getAddress"></a>
### device.getAddress() ⇒ <code>string</code>
The Bluetooth device address of the remote device.
**Kind**: instance method of [<code>Device</code>](#Device)
<a name="Device+getAddressType"></a>
### device.getAddressType() ⇒ <code>string</code>
The Bluetooth device Address Type (public, random).
**Kind**: instance method of [<code>Device</code>](#Device)
<a name="Device+getAlias"></a>
### device.getAlias() ⇒ <code>string</code>
The name alias for the remote device.
**Kind**: instance method of [<code>Device</code>](#Device)
<a name="Device+getRSSI"></a>
### device.getRSSI() ⇒ <code>number</code>
Received Signal Strength Indicator of the remote device
**Kind**: instance method of [<code>Device</code>](#Device)
<a name="Device+getTXPower"></a>
### device.getTXPower() ⇒ <code>number</code>
Advertised transmitted power level.
**Kind**: instance method of [<code>Device</code>](#Device)
<a name="Device+isPaired"></a>
### device.isPaired() ⇒ <code>boolean</code>
Indicates if the remote device is paired.
**Kind**: instance method of [<code>Device</code>](#Device)
<a name="Device+isConnected"></a>
### device.isConnected() ⇒ <code>boolean</code>
Indicates if the remote device is currently connected.
**Kind**: instance method of [<code>Device</code>](#Device)
<a name="Device+pair"></a>
### device.pair()
This method will connect to the remote device
**Kind**: instance method of [<code>Device</code>](#Device)
<a name="Device+cancelPair"></a>
### device.cancelPair()
This method can be used to cancel a pairing operation initiated by the Pair method.
**Kind**: instance method of [<code>Device</code>](#Device)
<a name="Device+connect"></a>
### device.connect()
Connect to remote device
**Kind**: instance method of [<code>Device</code>](#Device)
<a name="Device+disconnect"></a>
### device.disconnect()
Disconnect remote device
**Kind**: instance method of [<code>Device</code>](#Device)
<a name="Device+gatt"></a>
### device.gatt() ⇒ [<code>GattServer</code>](#GattServer)
Init a GattServer instance and return it
**Kind**: instance method of [<code>Device</code>](#Device)
<a name="Device+toString"></a>
### device.toString() ⇒ <code>string</code>
Human readable class identifier.
**Kind**: instance method of [<code>Device</code>](#Device)
<a name="Device+event_connect"></a>
### "connect"
Connection event
**Kind**: event emitted by [<code>Device</code>](#Device)
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| connected | <code>boolean</code> | Indicates current connection status. |
<a name="Device+event_disconnect"></a>
### "disconnect"
Disconection event
**Kind**: event emitted by [<code>Device</code>](#Device)
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| connected | <code>boolean</code> | Indicates current connection status. |
<a name="GattCharacteristic"></a>
## GattCharacteristic ⇐ <code>EventEmitter</code>
GattCharacteristic class interacts with a GATT characteristic.
**Kind**: global class
**Extends**: <code>EventEmitter</code>
**See**: You can construct a GattCharacteristic object via [getCharacteristic](#GattService+getCharacteristic) method.
* [GattCharacteristic](#GattCharacteristic) ⇐ <code>EventEmitter</code>
* [.getUUID()](#GattCharacteristic+getUUID) ⇒ <code>string</code>
* [.getFlags()](#GattCharacteristic+getFlags) ⇒ <code>Array.<string></code>
* [.isNotifying()](#GattCharacteristic+isNotifying) ⇒ <code>boolean</code>
* [.readValue([offset])](#GattCharacteristic+readValue) ⇒ <code>Buffer</code>
* [.writeValue(value, [optionsOrOffset])](#GattCharacteristic+writeValue)
* [.startNotifications()](#GattCharacteristic+startNotifications)
* ["valuechanged"](#GattCharacteristic+event_valuechanged)
<a name="GattCharacteristic+getUUID"></a>
### gattCharacteristic.getUUID() ⇒ <code>string</code>
128-bit characteristic UUID.
**Kind**: instance method of [<code>GattCharacteristic</code>](#GattCharacteristic)
<a name="GattCharacteristic+getFlags"></a>
### gattCharacteristic.getFlags() ⇒ <code>Array.<string></code>
Defines how the characteristic value can be used.
**Kind**: instance method of [<code>GattCharacteristic</code>](#GattCharacteristic)
<a name="GattCharacteristic+isNotifying"></a>
### gattCharacteristic.isNotifying() ⇒ <code>boolean</code>
True, if notifications or indications on this characteristic are currently enabled.
**Kind**: instance method of [<code>GattCharacteristic</code>](#GattCharacteristic)
<a name="GattCharacteristic+readValue"></a>
### gattCharacteristic.readValue([offset]) ⇒ <code>Buffer</code>
Read the value of the characteristic
**Kind**: instance method of [<code>GattCharacteristic</code>](#GattCharacteristic)
| Param | Type | Default |
| --- | --- | --- |
| [offset] | <code>number</code> | <code>0</code> |
<a name="GattCharacteristic+writeValue"></a>
### gattCharacteristic.writeValue(value, [optionsOrOffset])
Write the value of the characteristic.
**Kind**: instance method of [<code>GattCharacteristic</code>](#GattCharacteristic)
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| value | <code>Buffer</code> | | Buffer containing the characteristic value. |
| [optionsOrOffset] | <code>number</code> \| <code>Object</code> | <code>0</code> | Starting offset or writing options. |
| [optionsOrOffset.offset] | <code>number</code> | <code>0</code> | Starting offset. |
| [optionsOrOffset.type] | [<code>WritingMode</code>](#WritingMode) | <code>reliable</code> | Writing mode |
<a name="GattCharacteristic+startNotifications"></a>
### gattCharacteristic.startNotifications()
Starts a notification session from this characteristic.
It emits valuechanged event when receives a notification.
**Kind**: instance method of [<code>GattCharacteristic</code>](#GattCharacteristic)
<a name="GattCharacteristic+event_valuechanged"></a>
### "valuechanged"
Notification event
**Kind**: event emitted by [<code>GattCharacteristic</code>](#GattCharacteristic)
<a name="GattServer"></a>
## GattServer
GattServer class that provides interaction with device GATT profile.
**Kind**: global class
**See**: You can construct a Device object via [gatt](#Device+gatt) method
* [GattServer](#GattServer)
* [.services()](#GattServer+services) ⇒ <code>Array.<string></code>
* [.getPrimaryService(uuid)](#GattServer+getPrimaryService) ⇒ [<code>GattService</code>](#GattService)
<a name="GattServer+services"></a>
### gattServer.services() ⇒ <code>Array.<string></code>
List of available services
**Kind**: instance method of [<code>GattServer</code>](#GattServer)
<a name="GattServer+getPrimaryService"></a>
### gattServer.getPrimaryService(uuid) ⇒ [<code>GattService</code>](#GattService)
Init a GattService instance and return it
**Kind**: instance method of [<code>GattServer</code>](#GattServer)
| Param | Type |
| --- | --- |
| uuid | <code>string</code> |
<a name="GattService"></a>
## GattService
GattService class interacts with a remote GATT service.
**Kind**: global class
**See**: You can construct a GattService object via [getPrimaryService](#GattServer+getPrimaryService) method.
* [GattService](#GattService)
* [.isPrimary()](#GattService+isPrimary) ⇒ <code>boolean</code>
* [.getUUID()](#GattService+getUUID) ⇒ <code>string</code>
* [.characteristics()](#GattService+characteristics) ⇒ <code>Array.<string></code>
* [.getCharacteristic(uuid)](#GattService+getCharacteristic) ⇒ [<code>GattCharacteristic</code>](#GattCharacteristic)
* [.toString()](#GattService+toString) ⇒ <code>string</code>
<a name="GattService+isPrimary"></a>
### gattService.isPrimary() ⇒ <code>boolean</code>
Indicates whether or not this GATT service is a primary service.
**Kind**: instance method of [<code>GattService</code>](#GattService)
<a name="GattService+getUUID"></a>
### gattService.getUUID() ⇒ <code>string</code>
128-bit service UUID.
**Kind**: instance method of [<code>GattService</code>](#GattService)
<a name="GattService+characteristics"></a>
### gattService.characteristics() ⇒ <code>Array.<string></code>
List of available characteristic names.
**Kind**: instance method of [<code>GattService</code>](#GattService)
<a name="GattService+getCharacteristic"></a>
### gattService.getCharacteristic(uuid) ⇒ [<code>GattCharacteristic</code>](#GattCharacteristic)
Init a GattCharacteristic instance and return it
**Kind**: instance method of [<code>GattService</code>](#GattService)
| Param | Type | Description |
| --- | --- | --- |
| uuid | <code>string</code> | Characteristic UUID. |
<a name="GattService+toString"></a>
### gattService.toString() ⇒ <code>string</code>
Human readable class identifier.
**Kind**: instance method of [<code>GattService</code>](#GattService)
<a name="createBluetooth"></a>
## createBluetooth() ⇒ <code>NodeBleInit</code>
Init bluetooth session and return
**Kind**: global function
**Example**
```js
const { createBluetooth } = require('node-ble')
async function main () {
const { bluetooth, destroy } = createBluetooth()
const adapter = await bluetooth.defaultAdapter()
// do here your staff
destroy()
}
```
<a name="WritingMode"></a>
## WritingMode
**Kind**: global typedef
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| command | <code>string</code> | Write without response |
| request | <code>string</code> | Write with response |
| reliable | <code>string</code> | Reliable Write |
<a name="NodeBleSession"></a>
## NodeBleSession : <code>Object</code>
**Kind**: global typedef
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| bluetooth | [<code>Bluetooth</code>](#Bluetooth) | Bluetooth session |
| destroy | <code>func</code> | Close bluetooth session |