forked from google/uribeacon
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
42 lines (36 loc) · 1.04 KB
/
index.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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Requires bluetooth module on port 'A'
require('tesselate')(['ble-ble113a'], function(tessel, m) {
var ad = buildAdvertisement('vsco');
m.ble.setAdvertisingData(ad, function() {
m.ble.startAdvertising(function() {
console.log('Now advertising', ad);
});
});
});
/**
* Builds an ad buffer using the domain name with a .com
* @param {String} domain
* @return {Buffer}
*/
function buildAdvertisement(domain) {
var prefix = new Buffer([
0x03, // Length
0x03, // Parameter: Service List
0xD8, // URI Beacon ID
0xFE // URI Beacon ID
], 'hex');
var suffix = new Buffer([
0x16, // Service Data
0xD8, // URI Beacon ID
0xFE, // URI Beacon ID
0x00, // Flags
0x20 // Power
], 'hex');
var message = Buffer.concat([
new Buffer([ 0x00 ], 'hex'), // Shortcut for http://www.
new Buffer(domain),
new Buffer([ 0x07 ], 'hex'), // Shortcut for .com
]);
var messageLength = new Buffer([ suffix.length + message.length ]);
return Buffer.concat([prefix, messageLength, suffix, message]);
}