-
StackOverflow 文档
-
bluetooth 教程
-
在网上开始使用蓝牙
-
重置从附近的蓝牙设备(writeValue)消耗的能量
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);
});
}