【问题标题】:React native simulated ibeacon detectionReact 原生模拟 ibeacon 检测
【发布时间】:2021-10-08 03:38:12
【问题描述】:

我正在尝试在 React Native 应用程序中扫描附近的信标。

为此,我使用了 react-native-ble-plx
https://github.com/dotintent/react-native-ble-plx

我使用这个 Windows 应用模拟了一个信标
https://www.microsoft.com/en-lk/p/beacon-simulator/9nblggh4xvd0?activetab=pivot:overviewtab

我使用 ble 扫描仪应用测试了我的模拟信标,并成功检测到了我的模拟信标。

但问题是我无法在我的 react native 应用程序中使用 react-native-ble-plx 来检测它。

它实际上显示了附近的几个设备,但没有显示 UUID 或名称。这些数据显示为空。

例如:

'device', { serviceUUIDs: null,
      isConnectable: null,
      overflowServiceUUIDs: null,
      txPowerLevel: null,
      serviceData: null,
      manufacturerData: 'TEACFCd6h5jcoxKqh9ACQqwTAAOBqZYcxQ==',
      name: null,
      mtu: 23,
      rssi: -47,
      solicitedServiceUUIDs: null,
      localName: null,
      id: '32:BD:32:6C:E9:C2',

但是当我使用蓝牙耳机或类似设备等真实设备时,它会通过显示其名称、uuid 等被正确检测到。

为什么我的模拟信标在扫描时无法显示在我的 react 本机应用程序中。

仅供参考:我正在使用真实设备进行扫描。 (三星 S10 - Android 11)

这是我的代码

我有一个按钮如下

<Button title="Scan devices" onPress={scanDevices} />

和我的功能

const scanDevices = () => {
    setIsLoading(true);

    // scan devices
    manager.startDeviceScan(null, null, (error, scannedDevice) => {
      if (error) {
        console.warn(error);
      }

      // if a device is detected add the device to the list by dispatching the action into the reducer
      if (scannedDevice) {
        console.log('device', scannedDevice);
        dispatch({ type: 'ADD_DEVICE', payload: scannedDevice });
      }
    });

    // stop scanning devices after 5 seconds
    setTimeout(() => {
      manager.stopDeviceScan();
      setIsLoading(false);
    }, 55000);
  };

请注意,我是 ble 技术的新手,想知道我是否在这里遗漏了什么。

【问题讨论】:

    标签: android react-native bluetooth-lowenergy ibeacon ibeacon-android


    【解决方案1】:

    对于 iBeacon 广告,信标字段将在manufacturerData 中编码,如我在此处的回答中所述:https://stackoverflow.com/a/69466133/1461050

    不要期望在 serviceUuIDs 字段或其他 UUID 字段中看到 iBeacon ProximityUUID 字段。这不是 iBeacon 的工作原理。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-13
      • 2017-12-29
      • 1970-01-01
      • 1970-01-01
      • 2017-08-26
      相关资源
      最近更新 更多