Skip to content

Instantly share code, notes, and snippets.

@oflarcade
Last active October 30, 2019 10:30
Show Gist options
  • Save oflarcade/624c5d977310b665a399931dcddb3cd1 to your computer and use it in GitHub Desktop.
Save oflarcade/624c5d977310b665a399931dcddb3cd1 to your computer and use it in GitHub Desktop.
handleUpdateValueForCharacteristic(data) {
//let dataBuffer = Buffer.Buffer.from(data);
console.log(
'Received data from ' +
data.peripheral +
' characteristic ' +
data.characteristic,
data.value[1],
);
console.log(data.characteristic,UUID_BASE_2('2a37'))
console.log(_.isEqual(data.characteristic,UUID_BASE_2('2a37')));
let val = data.characteristic;
if( _.isEqual(val, UUID_BASE('0007'))) {
let res = Buffer.Buffer.from(data.value);
//console.log('Heart rate : ' + res.readUInt16BE(0));
console.log('Read !! Steps Count:', res.readUInt16LE(1));
this.setState({steps: res.readUInt16LE(1)});
if (res.length >= 8) {
console.log('Read !! Distance:', res.readUInt32LE(5));
this.setState({distance: res.readUInt32LE(5)});
}
if (res.length >= 12) {
console.log('Read !! Calories:', res.readUInt32LE(9));
this.setState({calory: res.readUInt32LE(9)});
}
}else if( _.isEqual(val,UUID_BASE_2('2a37'))) {
let res = Buffer.Buffer.from(data.value);
this.setState({heartbeat: data.value[1]});
console.log('Heart rate : ' + data.value[1]);
}
this.persist(this.state.peripheral);
}
....
handlePedometerStats(peripheral) {
setTimeout(() => {
BleManager.retrieveServices(peripheral.id)
.then(() => {
BleManager.startNotification(peripheral.id, 'fee0', UUID_BASE('0007'))
.then(() => {
console.log(
'Notification started for Services of Pedometer stats',
);
})
.catch(error => {
console.log('Read Steps Error', error);
});
})
.catch(error => {
console.log('Error ', error);
});
}, 6000);
}
...
getHeartRate(peripheral) {
setTimeout(() => {
BleManager.retrieveServices(peripheral.id).then(() => {
BleManager.startNotification(peripheral.id, '180d', '2a37') //Starts heartBeat data fetching from miband device.
.then(() => {
console.log('Heart Rate notification started');
});
});
}, 7000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment