Example
function onButtonClick() {
navigator.bluetooth.requestDevice({filters: [{services: ['heart_rate']}]})
.then(device => {
// Connecting to GATT Server...
return device.gatt.connect();
})
.then(server => {
// Getting Heart Rate Service...
return server.getPrimaryService('heart_rate');
})
.then(service => {
// Getting Heart Rate Control Point Characteristic...
return service.getCharacteristic('heart_rate_control_point');
})
.then(characteristic => {
// Writing 1 is the signal to reset energy expended.
let resetEnergyExpended = new Uint8Array([1]);
return characteristic.writeValue(resetEnergyExpended);
})
.then(_ => {
console.log('> Energy expended has been reset.');
})
.catch(error => {
console.log('Argh! ' + error);
});
}