UNPKG

1.57 kBMarkdownView Raw
1# ble-ad-parser
2
3## Description
4This 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```
7npm install ble-ad-parser
8```
9
10## Usage
11
12```
13var parser = require('ble-ad-parser');
14
15// Payload from your BLE device (make it into a buffer, if not already)
16
17var 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)
20var packets = parser.parse(payload);
21
22//
23
24console.log(packets.length); // 3
25console.log(packets[0].type); // Flags
26console.log(packets[0].data); // [ 'LE Limited Discoverable Mode' ]
27
28console.log(packets[1].type); // 'Incomplete List of 128-bit Service Class UUIDs'
29console.log(packets[1].data); // [ '0xba5689a6fabfa2bd01467d6e3858abad' ]
30```
31
32## Packet Structure
33The 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
45You can specify the endianess that you want the buffers parsed with by using these functions:
46```
47parser.parseLE(buffer);
48parse.parseBE(buffer);
49```
50
51## License
52MIT
53
54
55
56
57
58
59