1

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.

gjfonte
  • 488
  • 2
  • 4
  • 15
  • Possible duplicate of [How to get battery level of Kontakt ibeacons](http://stackoverflow.com/questions/25885659/how-to-get-battery-level-of-kontakt-ibeacons) – SushiHangover Mar 01 '17 at 22:32
  • I saw similar questions but the problem I got in mine was the fact that I didn't clean all the **BeaconParser** before apply the new layout. See @davidgyoung answer – gjfonte Mar 03 '17 at 11:05

2 Answers2

2

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.

davidgyoung
  • 63,876
  • 14
  • 121
  • 204
  • thanks for your help. I have removed the default parsers and I am now getting a value. The value is 8 (long) and looking in the Kontact.IO app the battery claims 93%. What 8 means?! – gjfonte Mar 02 '17 at 20:51
  • 1
    The raw value will range from 0-255. You have learned that 8 apparently means 93℅. You will need a few more data points to come up with a conversion formula. You might ask Kontakt.IO. unfortunately their SDK is closed source so we cannot see for ourselves. – davidgyoung Mar 03 '17 at 00:50
  • Thank you! You gave me a good help. I will contact Kontakt.IO and find out what the value means. – gjfonte Mar 03 '17 at 11:01
0

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.

mrtnclzd
  • 73
  • 6