-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
39 lines (31 loc) · 908 Bytes
/
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
var Presence = require('ninja-presence-base');
module.exports = Presence;
Presence.prototype.G = 'bluetoothle';
Presence.prototype.V = 0;
Presence.prototype.D = 263;
Presence.prototype.name = 'Presence - Bluetooth LE';
Presence.prototype.scan = function() {
var self = this;
var noble = require('noble');
noble.on('stateChange', function(state) {
self._app.log.debug('State change', state);
if (state === 'poweredOn') {
noble.startScanning();
} else {
noble.stopScanning();
}
});
noble.on('scanStart', function() {
self._app.log.info('Starting scan');
});
noble.on('scanStop', function() {
self._app.log.info('Stopping scan');
});
noble.on('discover', function(peripheral) {
self.see({
name: peripheral.advertisement.localName,
id: peripheral.uuid,
distance: Math.abs(peripheral.rssi)
});
});
};