首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Web蓝牙通知仅有少量响应

Web蓝牙通知仅有少量响应
EN

Stack Overflow用户
提问于 2017-08-09 04:07:48
回答 1查看 570关注 0票数 1

我正在学习使用web蓝牙api来编写web应用程序,并使用铬/铬运行它。但是通知只响应了几次,我不知道为什么和如何调试它(看看发生了什么)。

蓝牙外设是血氧仪,使用蓝牙发送实时spo2、心率等。我的浏览器使用的是基于Debian9.1构建的Chromium 60.0.3112.78,运行在Debian9.1 (64位)上。

下面是我的javascript:

代码语言: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);
}

铬显示控制台:

代码语言:javascript
复制
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之后没有反应,所以我关闭了血氧计。

问题出在哪里?我能做些什么呢?谢谢。

EN

回答 1

Stack Overflow用户

发布于 2017-08-09 09:12:13

首先,请注意此时的Chrome supports Android, Chrome OS, macOS

尝试使用chrome://bluetooth-internalsnRF Connect for AndroidnRF Connect for iOShttps://www.chromium.org/developers/how-tos/file-web-bluetooth-bugs上的一些提示

如果你可以在这些应用程序中连续收到通知,但在Chrome中却不能,那一定是个bug。请将有关如何重现它的详细信息以及您收集的日志归档到以下位置:https://crbug.com/new

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45577219

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档