1 | # ble-ad-parser
|
2 |
|
3 | ## Description
|
4 | This package will parse BLE slave advertisement packets into human readable/manipulatable objects. Based off of the BLE specification [data types](https://www.bluetooth.org/en-us/specification/assigned-numbers/generic-access-profile).
|
5 | ## Install
|
6 | ```
|
7 | npm install ble-ad-parser
|
8 | ```
|
9 |
|
10 | ## Usage
|
11 |
|
12 | ```
|
13 | var parser = require('ble-ad-parser');
|
14 |
|
15 | // Payload from your BLE device (make it into a buffer, if not already)
|
16 |
|
17 | var payload = new Buffer([27, 2, 1, 6, 17, 6, 186, 86, 137, 166, 250, 191, 162, 189, 1, 70, 125, 110, 56, 88, 171, 173, 5, 22, 10, 24, 7, 4]);
|
18 |
|
19 | // Parse (little-endian by default)
|
20 | var packets = parser.parse(payload);
|
21 |
|
22 | //
|
23 |
|
24 | console.log(packets.length); // 3
|
25 | console.log(packets[0].type); // Flags
|
26 | console.log(packets[0].data); // [ 'LE Limited Discoverable Mode' ]
|
27 |
|
28 | console.log(packets[1].type); // 'Incomplete List of 128-bit Service Class UUIDs'
|
29 | console.log(packets[1].data); // [ '0xba5689a6fabfa2bd01467d6e3858abad' ]
|
30 | ```
|
31 |
|
32 | ## Packet Structure
|
33 | The returned packets in the packet array have the following structure:
|
34 |
|
35 | *packet*.type -> A string describing type of data (eg. "Flags", "Complete List of 16-bit UUIDs", etc.)
|
36 |
|
37 | *packet*.data -> The data parsed into appropriate data type (eg. String, Array of Octet Strings, unsigned int, etc.)
|
38 |
|
39 | *packet*.typeFlag -> the type flag parsed from packet
|
40 |
|
41 | *packet*.raw -> The raw buffer that was parsed
|
42 |
|
43 | ## Endianness
|
44 |
|
45 | You can specify the endianess that you want the buffers parsed with by using these functions:
|
46 | ```
|
47 | parser.parseLE(buffer);
|
48 | parse.parseBE(buffer);
|
49 | ```
|
50 |
|
51 | ## License
|
52 | MIT
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|