我是编程iBeacons的新手,并且想知道是否有人可以使用AltBeacon库(android-beacon-library-2.5.1)帮助我解决有关测距更新的问题 . 我有一些Radius网络的RadBeacon Dot信标,它们以10Hz的频率进行广告宣传 . 我只是尝试AltBeacon快速入门页面中的测距示例,如下所示:
public class RangingActivity extends Activity implements BeaconConsumer {
protected static final String TAG = "RangingActivity";
private BeaconManager beaconManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ranging);
beaconManager = BeaconManager.getInstanceForApplication(this);
// To detect proprietary beacons, you must add a line like below corresponding to your beacon
// type. Do a web search for "setBeaconLayout" to get the proper expression.
// beaconManager.getBeaconParsers().add(new BeaconParser().
// setBeaconLayout("m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25"));
beaconManager.bind(this);
}
@Override
protected void onDestroy() {
super.onDestroy();
beaconManager.unbind(this);
}
@Override
public void onBeaconServiceConnect() {
beaconManager.setRangeNotifier(new RangeNotifier() {
@Override
public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
if (beacons.size() > 0) {
Log.i(TAG, "The first beacon I see is about "+beacons.iterator().next().getDistance()+" meters away.");
}
}
});
try {
beaconManager.startRangingBeaconsInRegion(new Region("myRangingUniqueId", null, null, null));
} catch (RemoteException e) { }
}}
这一切都很简单,但测距仅通过didRangeBeaconsInRegion回调返回1Hz的范围数据 . 我想知道如何更频繁地从库中获取范围数据,并且't see how to do it. Since the beacons adevrtise at 10Hz, I'd理想地希望以此速率(或接近它)从它们中采样rssi值 . 可以将蓝牙扫描时间设置为相应的值,但回调仍然只发生在1 Hz . 有谁知道这样做的方法吗?
帕特里克,提前谢谢
1 回答
如果您想将Android Beacon Library的默认扫描间隔更改为100毫秒,您可以使用以下代码执行此操作:
但是,在此之前,请确保您了解一些概念:
如果将扫描间隔从默认值(1100毫秒)缩短到100毫秒,则会丢失大量数据包,因为如果在扫描停止和重新启动期间传输,则会丢失数据包 .
虽然你会在更短的扫描间隔内更频繁地获得回调,但它将使用更多的CPU,并且由于上述问题,你通常会在回调中获得零信标 .
使用以10 Hz通告的信标与使用1 Hz通告的信标的主要原因是 not 以获得更频繁的回调 . (例如,在iOS上,回调固定为1 Hz且不可更改 . )10 Hz信标的主要原因是为更好的距离估计获得更多的测距统计样本 . 您必须使用的信号强度测量值越多,您获得的距离估计就越稳定和准确 .