0
votes

I am developing a museum type application that when detecting a beacon at a certain distance near to a point of interest, shows me relevant information about it.

My problem is that all my beacons come by default with the same UUID, therefore I have no way to distinguish them by means of a:

if (beacon.getId1().toString().equals("iBeacon UUID here"){}

since as the estimote library says, there are only three ways to ranging a beacon form a region (https://community.estimote.com/hc/en-us/articles/203776266-What-is-a-beacon-region-):

1. With only UUID: it consists of all beacons with a given UUID. For example: a region defined with default Estimote UUID would consist of all Estimote Beacons with unchanged UUID.

2. With UUID and Major: it consists of all beacons using a specific combination of UUID and Major. For example, all Estimote Beacons with default UUID and Major set to 13579.

3. With UUID, Major and Minor: it consists of only a single beacon (Estimote Cloud prevents having two beacons with the same IDs). For example, one with default Estimote UUID, Major set to 13579 and Minor set to 2468.

I had the idea to use the next instance:

if(beacon.getBluetoothAddress().equals("iBeacon UUID here")){}

instead of the above.

But the result of using this instance is negative and the beacons are not detected correctly if i use the function "getBluetoothAddress()".

This is an example of code using "beacon.getId1().toString().equals":

beaconManager.setRangeNotifier(new RangeNotifier() {
           @Override
           public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
              if (beacons.size() > 0) {

                  String current=" ";
                 //EditText editText = (EditText)RangingActivity.this.findViewById(R.id.rangingText);
                 Beacon firstBeacon = beacons.iterator().next();
                  Log.e(TAG,firstBeacon.toString());
                  String x =firstBeacon.getId1().toString();
                  Double d=firstBeacon.getDistance();
                 // x=x.substring(24);
                 Log.e("Ranging","The first beacon " + firstBeacon.getId1().toString() + " is about " + firstBeacon.getDistance() + " meters away.");

                  if(x.equals("00112233-4455-6677-8899-aabbccddeeff") && k1!=1 && d< 5.0)
                  {
                      x = current;
                          monolisa_fragment fragment = new monolisa_fragment();
                          getFragmentManager().beginTransaction().replace(R.id.framelayout, fragment).commit();

                      k2=0;k3=0;k4=0;k1=1;

                  }

                  else if(x.equals("00112233-4455-6677-8899-aabbccddeeff") && k2!=1 && d< 5.0)
                  {
                      Log.e("Sure",x.toString());
                      kohinoor fragment=new kohinoor();
                      getFragmentManager().beginTransaction().replace(R.id.framelayout,fragment).commit();
                      k1=0;k3=0;k4=0;k2=1;

                  }

                  else if(x.equals("00112233-4455-6677-8899-aabbccddeeff") && k3!=1 && d< 5.0){
                      allanhills fragment =new allanhills();
                      getFragmentManager().beginTransaction().replace(R.id.framelayout,fragment).commit();
                      k1=0;k2=0;k3=1;k4=0;
                  }

              }
           }

        });

        try {
            beaconManager.startRangingBeaconsInRegion(new Region("myRangingUniqueId", null, null, null));
        } catch (RemoteException e) {   }
    }

but i can't use "beacon.getId1().toString().equals" because my UIID beacons, have the same UUID. And i can't use "getBluetoothAddress()", because fails and because how the estimote library says, i need the UUID of every beacon, but in my case, every beacon have the same UUID.

thanks in advance.

1

1 Answers

0
votes

Yes, it is possible to do this.

Two points:

  1. It is common for every beacon to have the same UUID, but for the major and minor (also known as ID2 and ID3) to vary. You might consider distinguishing them by those fields if they are different. This is the standard practice.

  2. If you can't do this for some reason, you can use the MAC address to distinguish your beacons. Simply set Beacon.setHardwareEqualityEnforced(true). This will result in you getting multiple detections for an identical identifier so long as the MAC address is different.

When it comes to searching for beacons by MAC Address, you will need to use Ranging APIs like this:

Beacon.setHardwareEqualityEnforced(true);
Region region = Region("all-beacons-matching-uuid", "2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6", null, null); // Replace with your UUID
beaconManager.startRangingBeaconsInRegion(region)

If you only want to discover one beacon with a specific MAC address you can do so like this:

Beacon.setHardwareEqualityEnforced(true);
Region region = Region("only-one-beacon-matched-by-mac", "00:11:22:33:44:55"); // replace with your beacon's MAC address
beaconManager.startRangingBeaconsInRegion(region)

Then read the MAC like this:

public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
  for (Beacon beacon: beacons) {
     if (beacon.getHardwareAddress().equals("00:11:22:33:44:55") {
        Log.d(TAG, "This is the beacon I am looking for.");
     }
  }
}

You'll need to know the MAC address of each of your beacons to do this. You can use an off-the-shelf scanner like my BeaconScope to do this.