Created
October 30, 2019 10:06
-
-
Save oflarcade/35b50fed4e6fa05350d90905eaf02308 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
test(peripheral) { | |
if (peripheral) { | |
if (peripheral.connected) { | |
BleManager.disconnect(peripheral.id); | |
} else { | |
BleManager.connect(peripheral.id) | |
.then(() => { | |
let peripherals = this.state.peripherals; | |
let p = peripherals.get(peripheral.id); | |
this.setState({connectedTo: peripheral.name}); | |
if (p) { | |
p.connected = true; | |
this.setState({peripheral}); | |
peripherals.set(peripheral.id, p); | |
this.setState({peripherals}); | |
} | |
console.log('Connected to ' + peripheral.id); | |
console.log('Starting to retreive all services'); | |
BleManager.retrieveServices(peripheral.id).then(() => { | |
BleManager.readRSSI(peripheral.id).then(rssi => { | |
console.log('Retrieved actual RSSI value', rssi); | |
this.setState({rssi: rssi}); | |
}); | |
}); | |
BleManager.createBond(peripheral.id) | |
.then(() => { | |
console.log( | |
'createBond success or there is already an existing one', | |
); | |
}) | |
.catch(() => { | |
console.log('fail to bond'); | |
}); | |
this.handleBattery(peripheral); | |
this.handleDeviceInfo(peripheral); | |
this.handlePedometerStats(peripheral); | |
this.getHeartRate(peripheral); | |
}) | |
.catch(error => { | |
console.log('Connection error', error); | |
}); | |
} | |
} | |
} | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment