【问题标题】:WebBluetooth GATT Characteric Notification Setup too slow - How to improve Setup time?Web 蓝牙 GATT 特征通知设置太慢 - 如何提高设置时间?
【发布时间】:2020-09-05 19:10:29
【问题描述】:

我尝试使用 WebBluetooth 连接到 BLE 设备(LEGO Powered UP 设备)。我已经在同一个笔记本上使用了 .NET/WinRT(运行良好),现在我尝试编写一个适配器以在 Blazor 中使用它。 LEGO PoweredUp 设备使用带有通知和 WriteValue 的 BLE GATT 特性实现communication protocol。

设备连接后,它会立即发送一系列通知(作为对之前连接的响应),公开我需要的信息。我能够使用 WinRT 在 .NET 中足够快地设置通知接收器。但是,使用 Chrome 的 WebBluetooth,我只收到 - 取决于时间/迭代 - 在最后 3 和 9 条消息之间(预计 9 条消息)。我想这只是一个常规的比赛条件。

我的问题:这是预期的吗?我可以做点什么吗?

低于最小可行测试(连接到 LEGO Technic Control+ Hub 时应返回 9 条消息)。

function writeToLog(x) {
    console.log(x.target.value.buffer);
}
async function connectToLwpDevice() {
    const serviceUuid = "00001623-1212-EFDE-1623-785FEABCD123".toLowerCase();
    const characteristicUuid = "00001624-1212-EFDE-1623-785FEABCD123".toLowerCase();
    const device = await navigator.bluetooth.requestDevice({ filters: [{ services: [serviceUuid] }] });
    const connectedDevice = await device.gatt.connect();
    const service = await connectedDevice.getPrimaryService(serviceUuid);
    const characteristic = await service.getCharacteristic(characteristicUuid);
    characteristic.addEventListener('characteristicvaluechanged', writeToLog);
    await characteristic.startNotifications();
}

【问题讨论】:

    标签: google-chrome lego web-bluetooth


    【解决方案1】:

    我认为目前对此无能为力。我已针对 Web 蓝牙规范提交了 an issue 以跟踪我认为为接收这些通知所必需的更改。

    【讨论】:

    • 感谢您提交该文件。我将此回复作为答案,因为您似乎有足够的洞察力来证实我的怀疑:)
    猜你喜欢
    • 1970-01-01
    • 2021-12-26
    • 2022-11-01
    • 1970-01-01
    • 2014-07-27
    • 1970-01-01
    • 2023-03-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多