gpt4 book ai didi

javascript - JavaScript 中的 BLE 广告扫描

转载 作者:行者123 更新时间:2023-11-30 20:18:01 24 4
gpt4 key购买 nike

从附近的低功耗蓝牙设备扫描广告是我的首要任务。我试过的代码请求了设备(它想配对以获得特性)。但我的用例是听他们的广告。为此我找到了这段代码

function recordNearbyBeacon(major, minor, pathLossVs1m) { ... }
navigator.bluetooth.requestLEScan({
filters: [{manufacturerData: {0x004C: {dataPrefix: new Uint8Array([
0x02, 0x15, // iBeacon identifier.
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 // My beacon UUID.
])}}}],
options: {
keepRepeatedDevices: true,
}
}).then(() => {
navigator.bluetooth.addEventListener('advertisementreceived', event => {
let appleData = event.manufacturerData.get(0x004C);
if (appleData.byteLength != 23) {
// Isn’t an iBeacon.
return;
}
let major = appleData.getUint16(18, false);
let minor = appleData.getUint16(20, false);
let txPowerAt1m = -appleData.getInt8(22);
let pathLossVs1m = txPowerAt1m - event.rssi;

recordNearbyBeacon(major, minor, pathLossVs1m);
});
})

我试过官方站点中的某些 uuid,但似乎都不起作用。我想从广告数据中获取特征值。如何在 Javascript 中获取数据?提前致谢。

最佳答案

根据implementation status来自 Web Bluetooth GitHub 的文档,Web Bluetooth Scanning API (它提供了 requestLEScan 方法)尚未在任何浏览器中实现。

关于javascript - JavaScript 中的 BLE 广告扫描,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51720920/

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