【问题标题】:get Distance from Device to iBeacon LE in Android Devices在 Android 设备中获取从设备到 iBeacon LE 的距离
【发布时间】:2016-01-01 05:49:15
【问题描述】:

我正在尝试将我的移动设备 (s6-android 5.1) 与硬件 IBeacon 保持正确的距离。

首先以这种形式开始:

  protected void onCreate(Bundle savedInstanceState) {
  ...
  beaconManager = BeaconManager.getInstanceForApplication(this);
    beaconManager
            .getBeaconParsers()
            .add(new BeaconParser()
                    .setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25"));
  beaconManager.bind(this);
  ...
 }

然后覆盖这个:

  @Override
public void onBeaconServiceConnect() {
    beaconManager.setRangeNotifier(new RangeNotifier() {
        @Override
        public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {

            Log.i(TAG + "region", region.toString());
            Log.i(TAG + " Size ", String.valueOf(beacons.size()));

            for (Beacon beacon : beacons) {
                Log.i(TAG, " Distance :" + beacon.getId1() + ", " + beacon.getId2() + ", " + beacon.getId3());
            }

            if (beacons.size() > 0) {
                Beacon firstBeacon = beacons.iterator().next();
                logToDisplay("The first beacon " + firstBeacon.toString() + " is about " + firstBeacon.getDistance() + " meters away.");
                Log.i(TAG + " Distance ", beacons.iterator().next().getDistance() + "");
            }
        }
    });

    try {
        beaconManager.startRangingBeaconsInRegion(new Region("RadBeacon",
                Identifier.parse("2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6"),
                Identifier.parse("1"), Identifier.parse("1")));


    } catch (RemoteException e) {
        Log.i(TAG + "Error", e.toString());
    }
}

在顶级方法中,我可以登录 region 正确返回:

  id1: 2f234454-cf6d-4a0f-adf2-f4911ba9ffa6 id2: 1 id3: 1

Log中的其他信息:

   onScanResult() - ScanResult{mDevice=....., mScanRecord=ScanRecord [mAdvertiseFlags=6, mServiceUuids=null, mManufacturerSpecificData={76=[2, 21, -30, -59, 109, -75, -33, -5, 72, -46, -80, 96, -48, -11, -89, 16, -106, -32, 0, 2, 0, 6, -59]}, mServiceData={00005153-0000-1000-8000-00805f9b34fb=[67]}, mTxPowerLevel=0, mDeviceName=null], mRssi=-60, mTimestampNanos=431625881888515}

但我的问题是Collection&lt;Beacon&gt; beacons,这总是返回 0

我也可以通过Monitor进入/退出区域:

  beaconManager.setMonitorNotifier(new MonitorNotifier() {...}

但仍无法获取移动设备和 Beacon 硬件之间的距离;

所以在更多搜索之后找到一种方法并尝试:

  protected static double calculateAccuracy(int txPower, double rssi) {
    if (rssi == 0) {
        return -1.0; // if we cannot determine accuracy, return -1.
    }

    double ratio = rssi * 1.0 / txPower;
    if (ratio < 1.0) {
        return Math.pow(ratio, 10);
    } else {
        return (0.89976) * Math.pow(ratio, 7.7095) + 0.111;
    }
}

对于 rssi ,设置 mRssi 给出 Log 和 txPower 设置 Static int ,但 return value 不正确。

现在我有两个问题:

  1. 为什么 Collection&lt;Beacon&gt; beacons 总是返回 0 值?
  2. cat 如何在移动设备和 Ibeacon 硬件之间实现正确的Distance

在我尝试这个库和资源之前:

https://forums.estimote.com/t/get-distance-of-beacons/1986

Measure distance to iBeacon from Android device

https://github.com/AltBeacon/android-beacon-library/issues/43

https://github.com/NickdeDycker/EstimoteIndoorAndroid

http://altbeacon.github.io/android-beacon-library/samples.html

http://developer.estimote.com/android/tutorial/part-3-ranging-beacons/

还有许多其他链接!

Thank you for your attention and help


编辑1

它在Logcat 中显示:

   W/ModelSpecificDistanceCalculator﹕ Cannot find match for this device.  Using default

@davidgyoung

【问题讨论】:

    标签: android ibeacon ibeacon-android altbeacon


    【解决方案1】:

    一些提示:

    1. 使用现成的扫描应用程序(如 Locate.)确保信标正在传输您认为的标识符。如果标识符不匹配,您可以在 Region 定义中调整它们.

    2. onBeaconServiceConnect 的顶部添加一个调试行,以确保它被调用。

    3. 验证您在didRangeBeaconsInRegion 中大约每秒都能看到调试行。

    【讨论】:

    • 我之前做过重要提示(如代码所示)并在 didRangeBeaconsInRegion 方法中添加了 Log 并且这项工作正常,但我的问题是 Collection&lt;Beacon&gt; beaconsdidRangeBeaconsInRegion 的第一个参数)总是返回零值。
    • 为什么Locate 中显示的距离与移动设备和 iBeacin 硬件之间的real 距离不同,并且在计算距离时不能正常工作? --- ios Mobiles 是否可能比 android Mobiles 与 Beacon 一起工作更准确?
    • 它也显示在Logcat 中:W/ModelSpecificDistanceCalculator:找不到此设备的匹配项。使用默认
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多