Correct layout to detect Kontakt Beacon on Android with AltBeacon
Asked Answered
A

2

13

I'm trying to detect a Kontakt Beacon with the following BeaconLayout:

setBeaconLayout("m:8-9=0215,i:10-13,i:14-15,i:16-17,i:18-25"));

but I don't seem to be doing it correctly. The advertising packet structure is like this:

enter image description here

Thanks in advance.

Acrosstheboard answered 15/8, 2014 at 0:39 Comment(1)
For version 2 docs.kontakt.io/beacon/kontakt-beacon-v2.pdfWhitver
A
15

Thanks to @davidgyoung comments, I finally could detect my Kontakt beacon with the following code:

public class MainActivity extends Activity implements BeaconConsumer {

protected static final String TAG = "RangingActivity";
BeaconManager beaconManager = BeaconManager.getInstanceForApplication(this);

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);        
    beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25"));
    beaconManager.bind(this);    
}

@Override
public void onBeaconServiceConnect() {
      beaconManager.setRangeNotifier(new RangeNotifier() {
            @Override 
            public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
                if (beacons.size() > 0) {
                    Log.d(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) {   }
}

Please note that I'm using a 2.2 version Kontakt beacon, which is a different version from the layout posted above.

Acrosstheboard answered 17/8, 2014 at 19:51 Comment(1)
Could you tell if Android beacon library is enough to start with detecting the beacons or do I need to follow the docs from the kontakt.io webpage?Commentary
L
6

A few issues with your beaconLayout:

  1. The byte offsets in the beaconLayout string start with the manufacturer data (byte 6 in the table you show) so you need to subtract 6 from all of your offsets.

  2. The table shows there are only three identifiers in the beacon, but your beaconLayout string has four. Note the first identifier is 16 bytes long.

If you get it working, please post the correct beaconLayout you used.

Lissettelissi answered 15/8, 2014 at 21:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.