- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用 AltBeacon 库来对我设备附近的信标进行测距。我使用了库的所有默认值,即扫描周期为 1100 毫秒,扫描周期之间为 0 毫秒。
库每 1100 毫秒调用一次我的监听器,但问题是在很多此类调用中,没有信标检测。信标仅检测到大约 30%-40% 的调用,另外 70% 的调用表示周围没有信标。
我该怎么做才能解决这个问题?
问候
最佳答案
在查看私下发送的非常大的 50 秒 LogCat 摘录后,我看到以不规则的间隔检测到两个信标:
Beacon #1 7383942b-xxxx-xxxx-xxxx-xxxxxxxxxxxx id2: 5 id3: 5000
Max time between detections: 5.75600001 s
Mean time between detections: 2.03854544 s
% range cycles with detection: 51%
Beacon #2 b9407f30-xxxx-xxxx-xxxx-xxxxxxxxxxxx id2: 60039 id3: 2279
Max time between detections: 4.794999515 s
Mean time between detections: 1.377583336 s
% range cycles with detection: 82 %
库代码按预期每 1100 毫秒开始和停止蓝牙扫描,并且在 89% 的测距周期中,至少检测到两个信标之一。这表明应用程序、库和操作系统都在正常工作——没有很长一段时间没有检测到信标。更重要的是,每个信标的 RSSI 表明一个相当强的信号,该信号在日志期间相当一致。但是信标的检测间隔是高度不规则的。这是不寻常的。
这表明信标、手机或 radio 环境存在一些 radio 或硬件问题。几种可能性:
我认为 Android 设备出现问题的可能性最大,尽管我承认这是我见过的第一个此类案例。我建议您尝试使用第二个 Android 设备,看看是否可以重现该问题。由于这可能是硬件问题,因此记录您正在使用的设备型号会很有用。
编辑:提问者在线下发送了额外的信息,说他使用的是带有 2.0-beta7 版本库的 Nexus 5,并说这个问题过去并不存在,只是在升级时才出现到这个库的这个版本。我自己在 Nexus 5 和库的 2.0-beta7 版本上做了一些额外的测试,修改了 android-beacon-library-reference应用程序在每个测距回调中添加以下代码:
public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
if (beacons.size() > 0) {
EditText editText = (EditText)RangingActivity.this
.findViewById(R.id.rangingText);
int rssi = -100;
for (Beacon beacon: beacons) {
logToDisplay("Beacon "+beacon.toString()+" is about "+beacon.getDistance()+" meters away, with Rssi: "+beacon.getRssi());
if (beacon.getId1().toString().equals("2f234454-cf6d-4a0f-adf2-f4911ba9ffa6") && beacon.getId2().toString().equals("1") && beacon.getId3().toString().equals("1")) {
rssi = beacon.getRssi();
}
}
if (rssi > -100) {
Log.d(TAG, "Beacon found in ranging cycle. rssi: "+rssi);
}
else {
Log.d(TAG, "Beacon not found in ranging cycle");
}
}
}
然后我用 2f234454-cf6d-4a0f-adf2-f4911ba9ffa6/1/1 在 10Hz 下打开 RadBeacon USB 传输,然后使用过滤器和下面的结果查看调试输出。如您所见,在我运行测试的 60 秒内没有任何循环未检测到任何信标。
$ adb logcat -v time | grep "ranging cycle"
10-07 15:17:00.076 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -67
10-07 15:17:01.180 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -73
10-07 15:17:02.287 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -75
10-07 15:17:03.422 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -66
10-07 15:17:04.545 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -67
10-07 15:17:05.714 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -66
10-07 15:17:06.815 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -66
10-07 15:17:07.989 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -65
10-07 15:17:09.087 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -72
10-07 15:17:10.198 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -65
10-07 15:17:11.322 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -71
10-07 15:17:12.484 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -67
10-07 15:17:13.587 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -64
10-07 15:17:14.758 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -66
10-07 15:17:15.867 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -66
10-07 15:17:16.998 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -66
10-07 15:17:18.195 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -67
10-07 15:17:19.280 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -67
10-07 15:17:20.415 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -67
10-07 15:17:21.560 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -66
10-07 15:17:22.659 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -67
10-07 15:17:23.802 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -66
10-07 15:17:25.035 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -66
10-07 15:17:26.189 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -67
10-07 15:17:27.331 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -73
10-07 15:17:28.458 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -67
10-07 15:17:29.618 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -67
10-07 15:17:30.756 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -84
10-07 15:17:31.886 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -76
10-07 15:17:33.047 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -76
10-07 15:17:34.193 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -85
10-07 15:17:35.339 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -83
10-07 15:17:36.502 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -90
10-07 15:17:37.683 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -78
10-07 15:17:38.871 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -87
10-07 15:17:40.079 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -90
10-07 15:17:41.234 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -85
10-07 15:17:42.422 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -87
10-07 15:17:43.588 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -88
10-07 15:17:44.751 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -88
10-07 15:17:45.924 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -86
10-07 15:17:47.114 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -83
10-07 15:17:48.264 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -82
10-07 15:17:49.409 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -82
10-07 15:17:50.612 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -88
10-07 15:17:51.781 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -79
10-07 15:17:52.913 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -79
10-07 15:17:54.122 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -82
10-07 15:17:55.296 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -84
10-07 15:17:56.441 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -89
10-07 15:17:57.631 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -75
10-07 15:17:58.782 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -63
10-07 15:17:59.924 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -71
10-07 15:18:01.098 D/RangingActivity(16630): Beacon found in ranging cycle. rssi: -72
关于android - Altbeacon 库测距只有 30% 的时间检测到信标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26135337/
我是一名优秀的程序员,十分优秀!