gpt4 book ai didi

javascript - 如何使用 Chrome 网络蓝牙 API 启动新设备配对?

转载 作者:行者123 更新时间:2023-11-30 08:31:39 24 4
gpt4 key购买 nike

使用 navigator.bluetooth.requestDevice(),我可以访问我已经使用 native OSX 蓝牙配对设置配对的蓝牙设备,但没有出现以前未配对的设备,即使它们已配对属性匹配我的通用查询。可用设备显示在 Chrome 模式中,请求用户同意配对,但唯一显示的设备是我已经配对的设备。

我是不是误解了这里的预期用例,还是有其他方法可以通过 Chrome 与附近的(之前未配对的)设备建立连接?

文档:https://webbluetoothcg.github.io/web-bluetooth/(见例二)

function bluetoothConnect() {
navigator.bluetooth.requestDevice({filters: [{services: ['generic_access']}]})
.then(device => {console.log(`Connected to: ${device.name}`)})
.catch(console.error);
}

最佳答案

首先,就目前而言,Mac OS X 尚未完全实现。目前只有发现和 GATT 服务器连接/断开连接可用。在 https://github.com/WebBluetoothCG/web-bluetooth/blob/gh-pages/implementation-status.md 查看 Chrome 实现状态.查看 Chrome OS、Linux 和 Android M(Android Lollipop 解决方法)。

关于您的具体问题,我认为 generic_access 不是由附近的 BLE 设备广播的,而是被发现的,因为您已经配对(缓存)了该设备。例如,如果您的设备名为“foo”,您可以转到 https://googlechrome.github.io/samples/web-bluetooth/device-info.html并填写“foo”作为设备名称并点击“获取蓝牙设备信息”按钮。

我建议您尝试一下 https://googlechrome.github.io/samples/web-bluetooth/index.html 上的所有 Web 蓝牙示例

关于javascript - 如何使用 Chrome 网络蓝牙 API 启动新设备配对?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37082334/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com