forked from tommythorsen/uribeacon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flexibleBeacon.js
24 lines (20 loc) · 890 Bytes
/
flexibleBeacon.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// use uri-beacon library to encode the URI
// manually create the advertising data
var uriBeacon = require('uri-beacon'),
bleno = require('bleno');
var template = new Buffer(10); // maximum 31 bytes
template[0] = 0x03; // Length
template[1] = 0x03; // Parameter: Service List
template[2] = 0xD8; // URI Beacon ID
template[3] = 0xFE; // URI Beacon ID
template[4] = 0x00; // Length <-- must be updated
template[5] = 0x16; // Service Data
template[6] = 0xD8; // URI Beacon ID
template[7] = 0xFE; // URI Beacon ID
template[8] = 0x00; // Flags
template[9] = 0xEC; // Power -20 dBm
var scanData = new Buffer(0); // maximum 31 bytes
var encoded = uriBeacon.encode("http://example.com");
var advertisementData = Buffer.concat([template, encoded], template.length + encoded.length);
advertisementData[4] = encoded.length + 5;
bleno.startAdvertisingWithEIRData(advertisementData, scanData);