javascript - Javascript获取附近的蓝牙设备Mac地址
问题描述
我需要我的网络项目来获取附近的蓝牙设备 Mac 地址。我使用这段代码:
navigator.bluetooth.requestDevice(acceptAllDevices)
.then(device => {
console.log(device)
console.log('> Name: ' + device.name);
console.log('> Id: ' + device.id);
console.log('> Connected: ' + device.gatt.connected);
})
.catch(error => {
console.log('Argh! ' + error);
});
当我运行这个函数得到这个选项卡:图片
对于不受支持的设备,将显示蓝牙 Mac 地址。但它的 name 属性将为空。
但是,对于已识别的设备,它会打印名称选项。我可以从名称选项中过滤 Mac 地址吗?
可能还有其他查询Mac地址的方法吗?
解决方案
Web 蓝牙的可用过滤器是“服务”、“名称”、“名称前缀”和“制造商数据”,如https://web.dev/bluetooth/#request中所述。
您可以在https://googlechrome.github.io/samples/web-bluetooth/device-info.html和https://googlechrome.github.io/samples/web-bluetooth/manufacturer-data-filter尝试一些组合。 html
关于 MAC 地址,取决于蓝牙设备。一些设备广播一个用于隐私的临时设备,一个“静态”设备,一个用于“device.name”的名称,而不是 MAC 地址。
您要访问哪个设备?检查about:bluetooth-internals#devices
并尝试确定使其独特的一件事。
推荐阅读
- c# - 非 WCF TCP 服务器的 WCF 绑定
- javascript - 从 Java 客户端服务器应用程序打开本地 Internet Explorer
- sql - 循环遍历 SSIS 包中的多行
- node.js - 规则“缩进”的配置无效:值“[object Object]”不应具有其他属性
- python - 为标题栏设置自定义颜色
- c# - 转换为新的 csproj 后,Roslyn 分析器无法工作
- django - django 2 在传递 url 时没有反向 macth
- c# - 如何在一次 AJAX 调用中返回两个部分
- java - JLabel 不显示,除非与 mouselistener 一起使用
- c# - 在 Sharepoint 环境中使用 Microsoft.Office.Interop.Word