简体   繁体   English

如何使用AltBeacon API从Kontakt.io信标获取电池​​电量

[英]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.

相关问题 在Xamarin中使用AltBeacon - Using AltBeacon in Xamarin 如何在前台和后台使用 Android 信标库检测信标? - How to detect beacons using Android Beacon Library in foreground and background? 如何在 Xamarin android Z8A5DA52ED126447D359E70C05721A8A8 级别中获取 Package 签名 - How to get Package Signature in Xamarin android api level more than 28 使用C#,iOS从API获取JSON地址 - Using c#, ios to get a JSON address from an API 如何使用Mobile Vision API获取图像中文本的位置? - How to get position of text in an image using Mobile Vision API? 如何使用 Newtonsoft.Json 对象从 API 获取所有数据,我在 xamarin c# 中收到错误数据 - How to get all data from API using objects with Newtonsoft.Json and I receive wrong data in xamarin c# 如何在 Xamarin.Forms android 中向用户请求自动启动和省电模式(无限制)的权限? - How can I request permission from the user for autostart and for Battery saver(No restrictions) in Xamarin.Forms android? 如何从移动应用程序中的私有API获取后台的即时更改? - How to get instant changes in background from private api in mobile app? 在另一个过程中启动AltBeacon - Start AltBeacon in another process 如何在Xamarin froms中获取/设置当前音量水平? - How to get/set current volume level in Xamarin froms?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM