Why I can't get complete uuid when using region in altBeacon library?

0

I'm working in my app that should scan Ibeacon format devices. at first I used startMonitoringBeaconsInRegion. as I found out , I could not get access uuids of ibeacons. without deleting startMonitoringBeaconsInRegion, I added startRangingBeaconsInRegion. so my problem was solved. then I need my application just filter my beacons with specified uuid.

I'm faced new problem. for example I have many for example 3 or 4 Ibeacons in a place. like this,

00000000-0000-0000-0000-000000000001

00000000-0000-0000-0000-000000000002

00000000-0000-0000-0000-000000000003

00000000-0000-0000-0000-000000000004

I wrote beaconParser.setBeaconLayout :

beaconManager!!.beaconParsers.add(BeaconParser().setBeaconLayout("m:2-3=0215,i:4-7,i:4-19,i:20-21,i:22-23,p:24-24"))

and this region :

val region = Region("myBeaons", Identifier.parse("0x00000000"), null, null)

I need myapp filter out all beacons that matches 4 first byte 0x00000000. it is working but in the following when I want to get full uuid of each beacon , it returns just that 4 first byte that I wrote in region . I need complete UUID of each beacon to send to my server.

  beaconManager!!.removeAllRangeNotifiers()
        beaconManager!!.addRangeNotifier(object : RangeNotifier {
            override fun didRangeBeaconsInRegion(p0: MutableCollection<Beacon>?, p1: Region?) {
           beaconManager!!.stopRangingBeaconsInRegion(region)                    
           if (p0!!.size > 0) {
                    Log.d(
                        "Ranging",
                        "didRangeBeaconsInRegion called with beacon count:  " + p0.size
                    )
                    for (beacon in p0) {
                        Log.d("Ranging", "uuid:  " + beacon.id1)

                    }
                    progress.visibility = View.GONE
                    homeRelative2.visibility = View.VISIBLE
                } else if (p0.size == 0) {
                    progress.visibility = View.GONE
                    homeRelative2.visibility = View.VISIBLE
                }

            }
   })
}

beacon.id1 returns just 0x00000000. what do i do wrong ?

In addition I searched a lot about set the range(regex) in region variable . but nothing founds.

the main goal I want the app filter out just my ranged specified uuid ibeacon devices and I send them to server.

android
bluetooth-lowenergy
altbeacon
asked on Stack Overflow Sep 12, 2020 by nIMaaZx • edited Sep 12, 2020 by nIMaaZx

1 Answer

1

Beacon Regions as defined by popular Android libraries (inspired by the iOS Core Location standard) don't work that way -- there are no partial identifier matches. The whole identifier must match.

The easiest solution is to create a region for each of the UUIDs you want to match, and monitor for each of them like this:

val region1 = Region("region1", Identifier.parse("00000000-0000-0000-0000-000000000001"), null, null)
val region2 = Region("region2", Identifier.parse("00000000-0000-0000-0000-000000000002"), null, null)
val region3 = Region("region3", Identifier.parse("00000000-0000-0000-0000-000000000003"), null, null)
val region4 = Region("region4", Identifier.parse("00000000-0000-0000-0000-000000000004"), null, null)
beaconManager.startRangingBeaconsInRegion(region1);
beaconManager.startRangingBeaconsInRegion(region2);
beaconManager.startRangingBeaconsInRegion(region3);
beaconManager.startRangingBeaconsInRegion(region4);

A second but more complex option is to redefine your beacon layout expression to break up id1 into at least two identifiers, so you end up with id1, id2, id3 and id4. That way you could due a match on a prefix of all zeroes. This approach however, is a bit non-standard, and difficult to set up. It will likely cause trouble if you continue to need help from forums like this because almost nobody else programs this way. This alternative approach also has the disadvantage that it would prevent you from ever porting your solution to iOS which cannot support such a partial identifier prefix.

answered on Stack Overflow Sep 12, 2020 by davidgyoung • edited Sep 13, 2020 by nIMaaZx

User contributions licensed under CC BY-SA 3.0