How to get Unique Id of a Beacon using Estimote SDK in Android
Asked Answered
G

2

7

I am developing an application in which I am using Beacons. I have gone through the related Estimote SDK for the same. Now the thing is that I need to know the Unique Id of a particular Beacon. Suppose I am having 3 Beacons and all are present in the range of a device. Now I want to perform different functions based on the Unique Id of the Beacons. For this I need to know the Unique Id of each and every Beacon. Currently I am giving UUID for a Beacon and just checking whether its in the region of the device or not. My code is as follows :-

private static final String ESTIMOTE_PROXIMITY_UUID = "XYZ";
private static final Region ALL_ESTIMOTE_BEACONS = new Region("regionId",ESTIMOTE_PROXIMITY_UUID, null, null);

beaconManager.setMonitoringListener(new MonitoringListener() {

            @Override
            public void onExitedRegion(Region region) {
            //Region Exited
            }

            @Override
            public void onEnteredRegion(Region arg0, List<Beacon> arg1) {
                // TODO Auto-generated method stub
                //Do something ...
            }
        });

Now I need to get the Unique Id of the Beacon programmatically so that I can take decision depending on the IDs. Please help me to sort out the same. Any help would be appreciable. Thanks.

Glossology answered 20/1, 2015 at 10:25 Comment(1)
I have been facing the same problem. Did you find a solution?Vitellus
S
7

Every beacon has ID.
ID is 20 bytes long and is divided into three sections:

  • proximityUUID (16 bytes)

  • major number (2 bytes)

  • minor number (2 bytes).

How to use them to identify particular beacon?

First, you have to be aware there can be a lot of beacons around you. These beacons might come from other vendors, companies or developers, so you want to filter them out.
To filter beacons, you should use proximityUUID to group beacons provided by you or your company. Give the same proximityUUID to all your beacons.
After that you can start monitoring and ranging by:

private final Region MY_BEACONS = new Region("MY_BEACONS","YOUR_PROXIMITY_UUID", null, null);

beaconManager.startMonitoring(MY_BEACONS);
beaconManager.startRanging(MY_BEACONS);

Now, in your listeners you will be notified when your beacons will be in neighborhood.

Now let's assume you are writing an app for cinemas in the city. Each cinema has two different beacons to perform different actions. How to make a distinction between beacons for cinemas and how to do that for a particular beacon in a specyfic cinema?
Use major and minor fields. For example:

  • use major for identifying all beacons in a particular cinema,
  • use minor for identifying specific beacon in a particular cinema.

When you create ID for beacons in such way, you can get specific beacon and perform action:

 private final int SCARY_CINEMA_ID = 1111;
 private final int SCARY_CINEMA_BEACON_1 = 1;
 private final int SCARY_CINEMA_BEACON_2 = 2;
 private final int COMEDY_CINEMA_ID = 2222;
 private final int COMEDY_CINEMA_BEACON_1 = 1;
 private final int COMEDY_CINEMA_BEACON_2 = 2;


 @Override
 public void onEnteredRegion(Region region, List<Beacon> beacons) {
    for(Beacon beacon : beacons){
        if(beacon.getMajor() == SCARY_CINEMA_ID){
           if(beacon.getMinor == SCARY_CINEMA_BEACON_1){
               //do something for this beacon
           } else{
               //do something for second beacon in cinema
           }
        } else if(beacon.getMajor == COMEDY_CINEMA_ID){
          ...
        }
 }

Hope, that will help you :)

Shipmaster answered 20/1, 2015 at 12:0 Comment(5)
Hi mklimek, thanks for the answer. I am not clear with the Major & Minor thing, also what is the "SCARY_CINEMA_ID" & "SCARY_CINEMA_BEACON_1" here. Can you please explain a bit more.Glossology
@SalmanKhan major and minor are standard fields for esitmote beacons. We can use them as ids to identify beacons. SCARY_CINEMA_ID is arbitrary choosen minor for cinema for example 1111. COMEDY_CINEMA_ID is second minor for other cinema for example 2222. If you have two beacons and you want to relate it with SCARY_CINEMA and proximityUUID="beaconsForCinemas", you have to set values for first beacon as: uuuid="beaconsForCinemas", major = 1111, minor=1, for second beacon in this cinema use the same but set minor = 2Shipmaster
so while creating the region I need to set the UUID, Major & Minor values to detect the Beacon, right ?Glossology
@SalmanKhan it depends how wide context of beacons you want to reach. If you want all beacons in whole city in each cinema use proxmityUUID only, if you want only beacons for one cinema add particular major, if tou want exacly one beacon in specyfic cinema you have to add all tree fields so also add minor.Shipmaster
Let us continue this discussion in chat.Glossology
M
0

Came across this article when I was trying it out, it might be of some help to you. https://community.estimote.com/hc/en-us/articles/200868188-How-do-I-modify-UUID-major-and-minor-values-

Motherhood answered 20/1, 2015 at 10:50 Comment(2)
Hey Swarna, thanks for the answer but I am searching it for Android. Any way to sort this out in Android ?Glossology
you should probably ask directly to estimote, most features are not yet available for android.Motherhood

© 2022 - 2024 — McMap. All rights reserved.