使用PWA的蓝牙连接 [英] Bluetooth connectivity using PWA

查看:210
本文介绍了使用PWA的蓝牙连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据PWA Web蓝牙文档,它支持"BR/EDR或LE连接".

According to PWA Web Bluetooth documentation, it supports "either a BR/EDR or LE connection".

我正在尝试在Chrome devtools的控制台上使用以下代码进行测试:

I am trying to test using the following code at the console of the 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",如下所示:

I am using a Bluetooth music box to test it. It is recognized as "XTREME" as follows:

当我选择"XTREME"设备并单击对"时,在控制台上出现不受支持的设备"错误,如下所示:

When I select the "XTREME" device and click "PAIR", I get an "Unsupported device" error at the console as shown below:

我尝试了许多其他蓝牙设备,并收到相同的不支持的设备"消息. 到底是怎么回事?它不应该受到支持吗?我如何知道支持哪种设备?理想情况下,我该怎么做才能知道我的特定目标设备是否受支持?

I've tried many other Bluetooth devices and got the same "Unsupported device" message. What is going on? Isn't it supposed to be supported? How do I know which device is supported? Ideally, what do I do to know if my specific target device will be supported?

请帮助!

谢谢!

推荐答案

问题似乎在于Web蓝牙仅实现了很少的蓝牙协议(GATT和LE).

It seems that the problem is that Web Bluetooth only implement few Bluetooth protocols (GATT and LE).

有关蓝牙协议的更多信息,请参见: https://en.wikipedia.org/wiki/List_of_Bluetooth_protocols

More about Bluetooth protocols can be found here: 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=zh_CN

One can use and App to inspect the device protocol and see if it implements GATT or LE to check for Web Bluetooth compatibility. Example: https://play.google.com/store/apps/details?id=com.sanji.jasper_hsieh.sdpscanner&hl=en

这篇关于使用PWA的蓝牙连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆