How to get the battery level from Kontakt.io beacons using AltBeacon API

815 Views Asked by At

I need to get the battery level from the kontakt.io beacons. I have set the layout as below and the DataFields are empty when I read the beacons in RangingBeaconsInRegion.

I was expecting I could read the battery level from the last bit as described in the Kontakt.io documentation.

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.

Is this possible? or do I need to use the Kontakt.io API?

UPDATE

I have removed all parsers before apply the new layout and I am able to read the dataFields. However, I am getting a value 8 which I have no idea what this value means.

2

There are 2 best solutions below

3
davidgyoung On BEST ANSWER

I am not positive the syntax on Xamarin, but try removing all existing beacon parsers before adding your custom one. I suspect the built in iBeacon parser is still active And it is matching first.

0
mrtnclzd On

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.

A quick breakdown of how this works is also described here, and the recently launched Xamarin component uses the same CoreBluetooth approach.