【问题标题】:Javascript get nearby Bluetooth devices Mac AddressJavascript获取附近的蓝牙设备Mac地址
【发布时间】:2021-06-17 15:40:07
【问题描述】:

我需要我的网络项目来获取附近的蓝牙设备 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);
});

当我运行这个函数时,得到这个标签:picture

对于不受支持的设备,将显示蓝牙 Mac 地址。但它的 name 属性将为 null。

但是,对于已识别的设备,它会打印名称选项。 我可以从名称选项中过滤 Mac 地址吗?

可能还有其他查询Mac地址的方法?

【问题讨论】:

    标签: javascript web bluetooth progressive-web-apps


    【解决方案1】:

    Web 蓝牙的可用过滤器是“服务”、“名称”、“名称前缀”和“制造商数据”,如 https://web.dev/bluetooth/#request 所述。

    您可以在https://googlechrome.github.io/samples/web-bluetooth/device-info.htmlhttps://googlechrome.github.io/samples/web-bluetooth/manufacturer-data-filter.html 尝试一些组合

    关于 MAC 地址,取决于蓝牙设备。有些设备会广播一个用于隐私的临时设备、一个“静态”设备、一个用于“device.name”的名称,而不是 MAC 地址。

    您要访问哪个设备?查看about:bluetooth-internals#devices 并尝试找出一件让它与众不同的东西。

    【讨论】:

      猜你喜欢
      • 2020-01-29
      • 1970-01-01
      • 1970-01-01
      • 2022-06-13
      • 2020-10-27
      • 2012-03-14
      • 2015-12-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多