-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
36 lines (29 loc) · 955 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
const noble = require('noble')
const SERVICE_UUID = 'fee0'
const MiBand = require('./miband')
noble.on('stateChange', state => {
console.log(state)
if (state === 'poweredOn') {
console.log('scan...')
// noble.startScanning()
noble.startScanning([SERVICE_UUID], false)
} else {
noble.stopScanning()
}
})
noble.on('discover', peripheral => {
// console.log(`${peripheral}`)
console.log(`${peripheral.address} ${peripheral.advertisement.localName}`)
if (!(peripheral.advertisement.localName === 'MI Band 2')) {
return
}
peripheral.connect(error => {
console.log('connected to peripheral: ' + peripheral.uuid)
const miband = new MiBand(peripheral)
// console.log(miband.getInfo())
miband.getInfo()
// peripheral.disconnect(error => {
// console.log('disconnected from peripheral: ' + peripheral.uuid)
// })
})
})