我想查找需要将此示例从battery_service更改为自行车速度传感器服务所需的服务。简单地执行navigator.bluetooth.requestDevice(acceptAllDevices=true)可以与自行车速度传感器设备配对,但它会出错,因为我没有为它提供正确的服务名称。
navigator.bluetooth.requestDevice({ filters: [{ services: ['battery_service'] }] })
.then(device => { /* … */ })
.catch(error => { console.error(error); });我通过猜测就知道心率是{filters:[{services:[ 'heart_rate' ]}]})。还没有弄清楚自行车的速度和节奏传感器的名称。既然文档已经关闭,有没有一种方法可以内省requestDevice来实现这一点?
https://webbluetoothcg.github.io/web-bluetooth/#biblio-bluetooth-assigned-services
给出了链接
https://developer.bluetooth.org/gatt/descriptors/Pages/DescriptorsHomePage.aspx
页面不再存在,403禁止错误

发布于 2021-04-12 13:13:35
发布于 2021-04-13 15:33:53
Chrome处理的所有标准化Bluetooth GATT UUID字符串都在这个文件中:https://chromium.googlesource.com/chromium/src/+/master/third_party/blink/renderer/modules/bluetooth/bluetooth_uuid.cc。我相信下面这行就是你要找的。
{"cycling_speed_and_cadence", 0x1816},这意味着您可以使用字符串名称或其UUID:
// This works.
navigator.bluetooth.requestDevice({ filters: [{ services: ['cycling_speed_and_cadence'] }] });
// And this works as well ;)
navigator.bluetooth.requestDevice({ filters: [{ services: [0x1816] }] });https://web.dev/bluetooth也是一个很好的起点。
https://stackoverflow.com/questions/67040637
复制相似问题