使用 PWA 的蓝牙连接
Bluetooth connectivity using PWA
根据 PWA Web Bluetooth documentation,它支持 "either a BR/EDR or LE connection"。
我正在尝试在 Chrome devtools 的控制台使用以下代码进行测试:
navigator.bluetooth.requestDevice({
acceptAllDevices: true,
})
.then(device => {
// Human-readable name of the device.
console.log(device.name);
console.log(device.id);
// Attempts to connect to remote GATT Server.
return device.gatt.connect();
})
.then(server => { /* ... */ })
.catch(error => { console.error(error); });
我正在使用蓝牙音乐盒进行测试。识别为"XTREME"如下:
当我 select "XTREME" 设备并单击 "PAIR" 时,我在控制台收到 "Unsupported device" 错误,如下所示:
我已经尝试过很多其他蓝牙设备并收到相同的 "Unsupported device" 消息。
到底是怎么回事?不应该支持吗?我如何知道支持哪种设备?理想情况下,我该怎么做才能知道我的特定目标设备是否受支持?
请帮忙!
谢谢!
看来问题是 Web Bluetooth 只实现了几个蓝牙协议(GATT 和 LE)。
可在此处找到有关蓝牙协议的更多信息:https://en.wikipedia.org/wiki/List_of_Bluetooth_protocols
可以使用 App 检查设备协议,看看它是否实现了 GATT 或 LE 来检查 Web 蓝牙兼容性。示例:https://play.google.com/store/apps/details?id=com.sanji.jasper_hsieh.sdpscanner&hl=en
根据 PWA Web Bluetooth documentation,它支持 "either a BR/EDR or LE connection"。
我正在尝试在 Chrome devtools 的控制台使用以下代码进行测试:
navigator.bluetooth.requestDevice({
acceptAllDevices: true,
})
.then(device => {
// Human-readable name of the device.
console.log(device.name);
console.log(device.id);
// Attempts to connect to remote GATT Server.
return device.gatt.connect();
})
.then(server => { /* ... */ })
.catch(error => { console.error(error); });
我正在使用蓝牙音乐盒进行测试。识别为"XTREME"如下:
当我 select "XTREME" 设备并单击 "PAIR" 时,我在控制台收到 "Unsupported device" 错误,如下所示:
我已经尝试过很多其他蓝牙设备并收到相同的 "Unsupported device" 消息。 到底是怎么回事?不应该支持吗?我如何知道支持哪种设备?理想情况下,我该怎么做才能知道我的特定目标设备是否受支持?
请帮忙!
谢谢!
看来问题是 Web Bluetooth 只实现了几个蓝牙协议(GATT 和 LE)。
可在此处找到有关蓝牙协议的更多信息:https://en.wikipedia.org/wiki/List_of_Bluetooth_protocols
可以使用 App 检查设备协议,看看它是否实现了 GATT 或 LE 来检查 Web 蓝牙兼容性。示例:https://play.google.com/store/apps/details?id=com.sanji.jasper_hsieh.sdpscanner&hl=en