First Question:
How do I range only 1 region using just UUID?
I tried defining the region like this, which returns me all 3 beacons instead of just the 2 I’m looking for when calling startRangingBeaconsInRegion:
var beacon1And2 = {identifier: 'BlueAndPurpleBeacons', proximityUUID: 'B9407F30-F5F8-466E-AFF9-25556B57FE6D'};
However, If I define my region using both UUID and Major, then it correctly returns 2 beacons instead of three. I was under the impression that you could return a specific region by ONLY passing in UUID and identifier. This example below works:
var beacon1And2 = {identifier: 'BlueAndPurpleBeacons', proximityUUID: 'B9407F30-F5F8-466E-AFF9-25556B57FE6D', major: 50};
Second Question:
How do I range multiple regions?
Similar to this post that was actually posted last year Monitoring Multiple Regions, if I add multiple regions, then it is only ranging the last one in the array. In the following code example it will display beacon3, the green colored beacon:
var beacon1And2 = {identifier: 'BlueAndPurpleBeacons', proximityUUID: 'B9407F30-F5F8-466E-AFF9-25556B57FE6D', major: 50};
var beacon3 = {identifier: 'GreenBeacon', proximityUUID: 'A9407F30-F5F8-466E-AFF9-25556B57FE6D', major: 100};
var allBeacons = [beacon1And2 ,beacon3];
for (var i = 0; i < allBeacons.length; i++) {
var beacon = allBeacons[i];
// Start ranging.
estimote.beacons.startRangingBeaconsInRegion(
beacon, // Empty region matches all beacons.
onRange,
onError);
}
If you want to filter your Blue and Purple beacons by UUID only, you can assign a custom UUID to both of them, and use that in your region. The third beacon will have a different UUID and won’t be returned then.
As for ranging multiple regions—keep in mind that if you start ranging for multiple regions, you’ll get individual callbacks for each region. So it works like this: (pseudo-code)
0 s: startRanging("BlueBeaconRegion")
0 s: startRanging("PurpleBeaconRegion")
1 s: didRangeBeacons(["BlueBeacon"], inRegion: "BlueBeaconRegion")
1 s: didRangeBeacons(["PurpleBeacon"], inRegion: "PurpleBeaconRegion")
2 s: didRangeBeacons(["BlueBeacon"], inRegion: "BlueBeaconRegion")
2 s: didRangeBeacons(["PurpleBeacon"], inRegion: "PurpleBeaconRegion")
// etc.
and NOT like this:
0 s: startRanging("BlueBeaconRegion")
0 s: startRanging("PurpleBeaconRegion")
1 s: didRangeBeacons(["BlueBeacon", "PurpleBeacon"], inRegions: ["BlueBeaconRegion", "PurpleBeaconRegion"])
2 s: didRangeBeacons(["BlueBeacon", "PurpleBeacon"], inRegions: ["BlueBeaconRegion", "PurpleBeaconRegion"])
// etc.
If you want ranging results merged, then at this time you need to do it yourself.
I generated a new UUID and it is still returning me all three beacons.
var beacon2and3 = {identifier: 'BlueAndPurple', proximityUUID: 'C9407F30-F5F8-466E-AFF9-25556B57FE6D'
I also tried this way.
var beacon2and3 = {identifier: 'BlueAndPurple', proximityUUID: 'C9407F30-F5F8-466E-AFF9-25556B57FE6D', major: null, minor: null};
And you only assigned this UUID to the two beacons?
That is correct, that UUID is only assigned to those two beacons. If I add major as a filter, then it works properly, but without that it is not working
That’s weird, and could indicate that the bug lies with the SDK you’re using. I can see it’s some JavaScript SDK, and we don’t have an official Estimote JS SDK, so could you inquire with the authors of the library themselves.