网络蓝牙通知只有很少的回应
问题描述:
我正在学习使用网络蓝牙api来编写web应用程序,并使用铬/铬运行它。 但通知只响应几次,我不知道为什么以及如何调试它(看看发生了什么)。网络蓝牙通知只有很少的回应
蓝牙外设是血氧仪,使用BLE发送实时血氧饱和度,心率等。我的浏览器使用基于Debian 9.1(基于Debian 9.1(64位))运行的Chromium 60.0.3112.78。
下面是我的javascript:
铬显示var serviceUuid = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
characteristicUuid = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" ;
// Sorry, I hide the UUID.
document.querySelector('#button').addEventListener('click', function(event) {
onStartButtonClick();
}});
async function onStartButtonClick(){
let options = {};
options.acceptAllDevices = true;
options.optionalServices = [serviceUuid];
try{
const device = await navigator.bluetooth.requestDevice(options);
device.addEventListener('gattserverdisconnected', onDisconnected);
console.log('Got device:', device.name);
console.log('id:', device.id);
console.log('Connecting to GATT Server...');
const server = await device.gatt.connect();
console.log('Getting Service...');
const service = await server.getPrimaryService(serviceUuid);
console.log('Getting Characteristic...');
myCharacteristic = await service.getCharacteristic(characteristicUuid);
myCharacteristic.addEventListener('characteristicvaluechanged',
handleNotifications);
await myCharacteristic.startNotifications();
console.log('> Notifications started');
} catch(error) {
console.log('Argh! ' + error);
}
}
async function disconnect(){
await myCharacteristic.stopNotifications();
onDisconnected();
}
function onDisconnected(event) {
// Object event.target is Bluetooth Device getting disconnected.
console.log('> Bluetooth Device disconnected');
}
var tmp_count=0;
async function handleNotifications(event) {
// I will read data by Uint8Array.
// var databuf = new Uint8Array(event.target.value.buffer);
tmp_count++;
console.log(tmp_count);
}
控制台:
03:41:49.893 (index):192 Connecting to GATT Server...
03:41:50.378 (index):195 Getting Service...
03:41:51.237 (index):198 Getting Characteristic...
03:41:51.359 (index):204 > Notifications started
03:41:51.781 (index):228 1
03:41:51.782 (index):228 2
03:42:22.573 (index):217 > Bluetooth Device disconnected
这03:41:51.782 (index):228 2
后没有任何反应,所以我把关闭血氧仪。
什么问题?我能做什么? 谢谢。
答
首先,请注意Chrome supports Android, Chrome OS, macOS在这个时候。
尝试使用一些技巧上https://www.chromium.org/developers/how-tos/file-web-bluetooth-bugs如chrome://bluetooth-internals
, nRF Connect for Android或nRF Connect for iOS
如果你能在这些应用程序不断接受通知,但无法在Chrome中,有一个错误。请详细说明如何复制它,您收集的日志,有:https://crbug.com/new