[英]How to get the battery level from Kontakt.io beacons using AltBeacon API
I need to get the battery level from the kontakt.io beacons. 我需要从kontakt.io信标获取电池电量。 I have set the layout as below and the DataFields are empty when I read the beacons in RangingBeaconsInRegion .
我已将布局设置如下,当我在RangingBeaconsInRegion中读取信标时, DataFields为空。
I was expecting I could read the battery level from the last bit as described in the Kontakt.io documentation. 我期望我能像Kontakt.io文档中所述从最后一点读取电池电量。
This is my current code: 这是我当前的代码:
private BeaconManager InitializeBeaconManager()
{
BeaconManager bm = BeaconManager.GetInstanceForApplication(Xamarin.Forms.Forms.Context);
var iBeaconParser = new BeaconParser();
iBeaconParser.SetBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25");
bm.BeaconParsers.Add(iBeaconParser);
_rangeNotifier.DidRangeBeaconsInRegionComplete += RangingBeaconsInRegion;
bm.Bind((IBeaconConsumer)Xamarin.Forms.Forms.Context);
return bm;
}
void RangingBeaconsInRegion(object sender, RangeEventArgs e)
{
if (e.Beacons.Count > 0)
{
var beacon = e.Beacons.FirstOrDefault();
var data = beacon.DataFields.FirstOrDefault();
// here DataFields is empty!
}
}
I am using Xamarin Forms and this is the code for the Android Version. 我正在使用Xamarin Forms,这是Android版本的代码。
Is this possible? 这可能吗? or do I need to use the Kontakt.io API?
还是我需要使用Kontakt.io API?
UPDATE UPDATE
I have removed all parsers before apply the new layout and I am able to read the dataFields. 在应用新布局之前,我已经删除了所有解析器,并且能够读取dataFields。 However, I am getting a value 8 which I have no idea what this value means.
但是,我得到一个值8 ,我不知道该值是什么意思。
I am not positive the syntax on Xamarin, but try removing all existing beacon parsers before adding your custom one. 我对Xamarin的语法不满意,但尝试在添加自定义解析器之前先删除所有现有的信标解析器。 I suspect the built in iBeacon parser is still active And it is matching first.
我怀疑内置的iBeacon解析器仍处于活动状态,并且首先匹配。
The battery level in Kontakt.io beacons are part of their " scan response packet ", not part of the iBeacon structure, you'll have to use CoreBluetooth to read Characteristic 1, Service 5 . Kontakt.io信标中的电池电量是其“ 扫描响应数据包 ”的一部分,而不是iBeacon结构的一部分,您必须使用CoreBluetooth读取特征1,服务5 。
A quick breakdown of how this works is also described here , and the recently launched Xamarin component uses the same CoreBluetooth approach . 本文还描述了其工作原理的快速细分,并且最近启动的Xamarin组件使用相同的CoreBluetooth方法 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.