Skip to content

Instantly share code, notes, and snippets.

@oflarcade
Created October 30, 2019 10:06
Show Gist options
  • Save oflarcade/35b50fed4e6fa05350d90905eaf02308 to your computer and use it in GitHub Desktop.
Save oflarcade/35b50fed4e6fa05350d90905eaf02308 to your computer and use it in GitHub Desktop.
...
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