【问题标题】:Web Bluetooth: Want to filter on manufacturer data when using navigator.bluetooth.requestDevice网络蓝牙:想要在使用 navigator.bluetooth.requestDevice 时过滤制造商数据
【发布时间】:2021-07-05 07:17:48
【问题描述】:

我看到谷歌浏览器没有对制造商数据实施过滤。问题707635,好像没有任何进展。

Web 蓝牙规范有一个(不稳定的)规范,用于在使用 navigator.bluetooth.requestDevice 时过滤制造商数据 (https://webbluetoothcg.github.io/web-bluetooth/#example-filter-by-manufacturer-service-data

有谁知道这方面是否有任何进展或进行了这种过滤工作?

【问题讨论】:

    标签: bluetooth bluetooth-lowenergy web-bluetooth


    【解决方案1】:

    根据我们的讨论,我在 Chrome 92 的网络蓝牙中添加了对制造商数据过滤器的支持。请参阅 https://crbug.com/707635

    这是一个例子:

    // Filter Bluetooth devices from Google company with manufacturer data bytes
    // that start with [0x01, 0x02].
    navigator.bluetooth.requestDevice({
      filters: [{
        manufacturerData: [{
          companyIdentifier: 0x00e0,
          dataPrefix: new Uint8Array([0x01, 0x02])
        }]
      }],
      optionalServices: ['battery_service'] // Required to access service later.
    })
    .then(device => { /* … */ })
    .catch(error => { console.error(error); });
    

    您可以在https://googlechrome.github.io/samples/web-bluetooth/manufacturer-data-filter.html 找到一个示例,在https://web.dev/bluetooth/#manufacturer-data-filter 找到一些开发者文档

    让我知道这是否适合你;)

    【讨论】:

    • 谢谢。该解决方案非常适合我们的使用。
    • 您是否有机会分享您正在开发的网站?我只是好奇;)
    • 我是一名嵌入式开发人员,所以我们公司的其他人在做网络应用程序。目前我们还没有具体的网站在进行中,但添加的新功能将增加我们在生产中使用网络蓝牙技术的可能性。当我们有这样的网站时,我一定会通知您。
    • 期待您的回音!
    • 您对这样的网站有什么新鲜事吗?
    【解决方案2】:

    简答:

    1. “星号”问题707635 接收更新和表示兴趣。
    2. 如果您有明确的示例/业务案例要分享,请考虑添加评论以帮助开发人员了解如何确定这项工作的优先级。
    3. Chromium 是开源的,请考虑贡献或寻找开发人员来完成这项工作。

    【讨论】:

    • '为该问题加注星标。谢谢。
    【解决方案3】:

    正如您所指出的,Chrome 团队尚未在这方面取得进展。同时,按设备名称、设备名称前缀或 GATT 服务进行过滤对您有用吗?

    你可以试试https://googlechrome.github.io/samples/web-bluetooth/device-info.html

    【讨论】:

    • 谢谢。我已经尝试过这些例子。按设备名称或前缀过滤对我们不起作用,因为我们的用户可以重命名我们的设备(并且经常这样做)。此外,我们的大部分服务都是自定义的,因此需要 128 位 UUID。广告 128 位 UUID 将占用我们想要广告的重要数据的空间。如果我们至少可以过滤制造商/供应商 ID 会有所帮助
    • IIUC 你不需要dataPrefixmask,只有制造商供应商代码ID 对吗?见webbluetoothcg.github.io/web-bluetooth/…
    • 仅供参考,我已在 github.com/WebBluetoothCG/web-bluetooth/issues/544 提交了规范问题,以添加简单的制造商 ID 支持。
    • 再次感谢您。过滤制造商 ID 会有很大帮助,同时等待未来可能过滤制造商数据。
    • 出于好奇,您将如何过滤制造商数据?
    猜你喜欢
    • 2021-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多