forked from LynxyssCZ/node-xiaomi-gap-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
29 lines (24 loc) · 702 Bytes
/
example.js
File metadata and controls
29 lines (24 loc) · 702 Bytes
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
const noble = require('noble');
const XiaomiServiceReader = require('./index');
noble.on('stateChange', function(state) {
if (state === 'poweredOn') {
noble.startScanning([], true);
} else {
noble.stopScanning();
}
});
noble.on('discover', function(peripheral) {
const {advertisement, id, rssi, address} = peripheral;
const {localName, serviceData, serviceUuids} = advertisement;
let xiaomiData = null;
for (let i in serviceData) {
if (serviceData[i].uuid.toString('hex') === 'fe95') {
xiaomiData = serviceData[i].data;
}
}
if (!xiaomiData) return;
console.log({
id, address, localName, rssi,
data: JSON.stringify(XiaomiServiceReader.readServiceData(xiaomiData)),
})
});