1

我想使用 requestLEScan 方法扫描 ble 外围设备,但我找不到 requestLEScan 方法。我在下面这个文档之后写了

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<title></title>
</head>

<body>
<button id="test" onclick="onButtonClick()">test</button>

<script>
function onButtonClick() {
  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;

    });
  })
}

</script>
</body>
</html>

但它会导致这样的错误。

index_html_ _index_html_-_web_bluetooth_-____play_ground_web_bluetooth_

另外,我检查了对象,它只有 requestDevice() 方法

index_html

4

1 回答 1

3

根据WebBluetooth 实施状态页面显示,Chrome 目前还没有实施requestLEScan。根据您的设备,您可能可以改用常规requestDevice

于 2018-02-13T09:14:25.827 回答