0

I have a question about monitoring multiple regions with Eddystone beacons by using the AltBeacon library.

Say for example I have 3 beacons, and each of the beacons is assigned to a other region and the regions are defined based on the Instance value of the beacons i.e. ("region1", null, "InstanceValueOfBeacon", null) and I have a different action for each didEnterRegion.

Now when I place all the beacons next to each other. How will the application respond? Will it keep on switching between the different regions because multiple beacons are found? Does it just do the action of the beacon that is first found? Or how does that work exactly?

shilovk
  • 11,718
  • 17
  • 75
  • 74
brasay
  • 125
  • 1
  • 2
  • 14

1 Answers1

0

When monitoring for beacons transmitting Eddystone-UID, regions should be set up like this:

Identifier eddystoneNamespaceId1 = Identifier.parse("0x00000000000000000001");
Identifier eddystoneNamespaceId2 = Identifier.parse("0x00000000000000000002");

Region eddystoneUidRegion1 = new Region("eddystoneUidRegion1",
    eddystoneNamespaceId1, null, null);
Region eddystoneUidRegion2 = new Region("eddystoneUidRegion1", 
    eddystoneNamespaceId2, null, null);

beaconManager.setRangeNotifier(this);
beaconManager.startMonitoringBeaconsInRegion(eddystoneUidRegion1);
beaconManager.startMonitoringBeaconsInRegion(eddystoneUidRegion2);

In this example, two different regions are defined, each with a 10-byte different Eddystone-UID namespace identifier, and a null Eddystone-UID instance identifier so it will match all beacons with those namespace. The last parameter passed to the Region constructor is also null, because Eddystone-UID beacons only have two identifiers. The code starts monitoring for each of these regions in the last two lines.

The first time any beacon matching the first region is detected (e.g. one with the first namespace identifier), the didEnterRegion callback will be fired, passing a reference to the eddystoneUidRegion1 object. The equivalent callback will also happen if any beacon matching the second region is detected. You can tell which one is detected by examining the contents of the Region object passed to the callback. A different callback exists for didExitRegion when all beacons matching a monitored region disappear.

This is how the Monitoring APIs work. There are also Ranging APIs that give you a callback at approximately 1Hz with a list of all visible beacons that match the Region. Whether you use the Monitoring APIs or Ranging APIs depends on your use case.

davidgyoung
  • 63,876
  • 14
  • 121
  • 204
  • So if I understand correctly, the region that is first detected, that region will be used in the didEnterRegion callback? Or is it possible to make a didEnterRegion for the first region AND one for the second region? so that if for example the second region is detected, the actions of didEnterRegion(region2) are executed and if the first region is detected the actions of the didEnterRegion(region1) are executed? – brasay Sep 30 '15 at 14:09
  • You get a different callback per region if a beacon that matches the region definition is detected. – davidgyoung Sep 30 '15 at 14:38
  • So it is possible to differentiate between the different regions using a switch for example, where the condition is switch(region.getId1()) and execute different action depending on which of the defined regions the user is in? – brasay Sep 30 '15 at 14:44
  • Yes, you can do exactly that. – davidgyoung Sep 30 '15 at 18:23