-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
42 lines (37 loc) · 1.06 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
var bleno = require('bleno');
var locationStation = require('./LocationStation');
var LocationStationService = require('./LocationStationService');
var bleName = 'LocationStation';
var locationStationService = new LocationStationService(new locationStation.LocationStation())
//
// Wait until the BLE radio powers on before attempting to advertise.
// If you don't have a BLE radio, then it will never power on!
//
bleno.on('stateChange', function(state) {
if (state === 'poweredOn') {
//
// We will also advertise the service ID in the advertising packet,
// so it's easier to find.
//
bleno.startAdvertising(bleName, [locationStationService.uuid], function(err) {
if (err) {
console.log(err);
}
});
}
else {
bleno.stopAdvertising();
}
});
bleno.on('advertisingStart', function(err) {
if (!err) {
console.log('advertising...');
//
// Once we are advertising, it's time to set up our services,
// along with our characteristics.
//
bleno.setServices([
locationStationService
]);
}
});