iOS, maximum UUID number of beacon ranging in CLLocation - ios

Hi i trying to detect iBeacons.
in case of region monitoring, i knew that maximum UUID number is 20.
How about beacon ranging in CLLocation?
Have maximum UUID number limite?
Thank you in advance.

There is no hard limit to the number of regions that can be ranged by iOS Core Location. I have personally set up 100 regions to range to cover a large number of Proximity UUIDs.
That said, once you get significantly over 100 it starts to have real performance impact on the phone. There will be one callback to the delegate for each region, so with 100 regions, you will have 100 callbacks per second, and even with minimal processing in the callback CPU starts to spike. The ultimate limit will be hit when the system simply cannot keep up, and depends on other variables like the number of beacons in the vicinity, the phone model, and other processing going on at the same time.

Related

When do I get notified when monitoring an iBeacon region based on UUID?

I want to build that gets notified (even when in the background) when it gets in range of any iBeacon with a given UUID.
I know I could monitor an individual region for each of my beacons, but if I understand correctly, on iOS, I am limited to 20 monitored regions.
So the other alternative is to monitor a region based solely on its UUID, but then when do I get enter/exit notifications for that region? Whenever I get in range or out of range of any beacon with the same UUID, or only when I get in range of the first one and out of range of the last one?
If you monitor based on a wildcard region that includes only a ProximityUUID (leaving major and minor nil) then :
You will only get one didEnter callback the first time the first beacon is detected. If a second, third, or additional beacon is detected matching this wildcard region, then you did not get any monitoring callbacks.
You won't get any further callbacks until all beacons matching the wildcard region disappear (this takes at least 30 seconds in the foreground, longer in the background.) At that time, you'll get a call to didExit. After receiving a didExit, you will again be eligible for the callback in (1) above.
If you want more granular callbacks about individual beacons there are a few choices:
Use additional region definitions (up to the 20 allowed) and monitor them all.
Dynamically change the regions you are monitoring when you get a didEnter. This might work if you have a limited number of beacons (e.g. less than 20) matching a particular wildcard region. You could then activate monitoring for each of these sub-regions.
Use ranging APIs. These give you callbacks once per second with a list of all matching beacons seen that match a region. The trick is that this is generally limited to 10 seconds after region transition in the background. But it is possible to extend it to 180 seconds on request, or indefinitely if you declare your app to be a background location app in Info.plist. (If you go this route, there are a few tricks to get this working properly.)

android maximum regions to ranging and monitoring

I want to track all nearby beacons using global region, then i create individual region for each ranged region from the global region, is there any regions limit for android phone ? i've read that in the ios regions are limited into 20 max.
Any help would be appreciated
Short answer: The Android Beacon Library has no hard limit on the number of regions you can range or monitor.
Longer answer: If you go beyond a reasonable number of monitored or ranged regions (a few dozen), you may experience some issues:
Elevated CPU and battery usage will be needed to process all the region matches
A maximum of 50 monitored regions will has their state persisted across app restarts. If you go beyond 50 monitored regions, then this persistence will no longer happen, and the app will receive duplicate region entry events for nearby beacons each time the operating system restarts the app due to memory pressure.
As an alternative to monitoring a very large number of regions, consider using broader wildcard patterns in a smaller number of regions (basically specify fewer identifiers that must be matched) and then read the specific identifiers in ranging callbacks and custom logic based on the identifier patterns you see there.
It is worth noting that with iOS CoreLocation, there is also no limit to the number of regions that may be ranged. The limit of 20 regions is for monitoring only, and applies to both geofence regions and beacon regions.

Ranging 500 iBeacons using one UUID

Let's say I have 500 iBeacons deployed that I want to use with one app.
Can I have one UUID for all 500 beacons and specific major and minor identifiers to each of the 500 beacons?
If so, can I monitor the region of my UUID and start ranging for the specific major and minor identifiers once the region is entered?
I'm confused as to what ranging actually does. Can I get the major and minor identifiers from ranging, or I will only get the distance from the device?
Yes, you can have all your beacons included in a single region defined by the UUID. It can be 500 beacons or much more: there is no upper limit. Then if you enter this region and start ranging, you'll receive a list of beacons in range, along with Major and Minor IDs. Keep in mind though that not all beacons in this region have to be in range.
I think this article we posted on Estimote Community Portal explains difference between monitoring and ranging quite well: https://community.estimote.com/hc/en-us/articles/203356607-What-are-region-Monitoring-and-Ranging-
Cheers.
The major and minor values are unsigned short integers, so that means they can store a number no greater than 65'536 within them, so in theory you can monitor and see up to 4'294'967'296 beacons per UUID, and you can have 20 of those.
Monitoring can be done in the background, Ranging needs to be done in the foreground.
Monitoring is a low power activity, ranging I read isn't.
Monitoring can be slow to react, too slow for many, especially if your looking at region triggers, entering is ok, leaving can take 10 to 15 seconds or more. Ranging in contrast is almost immediate, and quite dependable. I tried both and gave up on relying on monitoring, you need your app to be running in foreground; ranging in an ideal world.

iBeacon region monitoring AND proximity for >20 beacons?

I have been working on a prototype iOS app utilizing iBeacons to provide location-relevant information to office employees depending on where in the office they are. The ideal use case is that whenever an employee enters or exits their office, a callback is fired which provides them some information in the form of a notification (it might make a server query to get information first, etc - that sort of thing). We also want to be able to do this when the app is backgrounded or terminated; fortunately, we already know that beacon region boundary crossings trigger the appropriate CoreLocation callbacks even if the app is backgrounded or suspended.
From looking around, I understand that broadly, I have two options for how to approach the beacon region monitoring:
Give each iBeacon its own CLBeaconRegion, and monitor for each of these regions independently.
Monitor for CLBeaconRegions that correspond to multiple iBeacons - for example, each iBeacon has the same UUID and only monitor for a CLBeaconRegion corresponding to that UUID - then try to determine which beacon triggered the boundary crossing using ranging.
Thus far, I had chosen option #1. The advantage of this approach is that I get didEnterRegion: and didExitRegion: calls for each individual beacon and immediately know which beacon I have entered/exited. Also, I only get one enter call and one exit call, which is exactly what I want. Unfortunately, I just realized that this approach also limits me to 20 beacons (since each beacon gets its own region).
I'm not as familiar with the exact implementation details of #2, so correct me if I'm wrong. But it seems that this approach has more drawbacks:
Apple discourages ranging when the app is in the background because the results may not be as accurate.
The ranging calls fire once every second, while I only want to have "enter/exit" callbacks.
If the beacons have region overlap, the ranging calls might continually flip which one is "closest", which would further complicate things.
Basically, I'm wondering if there is a way to utilize option #2, but still have the benefits of option #1 - a quick and easy way to immediately determine which beacon triggered the region change with only one enter or exit callback?
I hope this question is clear enough. It's not all entirely clear in my own head, especially how ranging works.
Option #2 is absolutely more complicated, but you must accept these complications in order to get around the 20 region monitoring limit.
A few points:
In the background, you only have around 5 seconds of ranging time, which does not give you as much time to average RSSI (signal strength) from each beacon to get a good distance estimate. So, yes, the estimates will be less accurate. If you understand this limitation and can live with it for your use case, there is nothing wrong with ranging in the background.
Yes, you will get multiple ranging calls per beacon after region entry, and you won't get any callbacks on region exit. You have to write extra code to take care of this. I have done this by maintaining a NSMutableArray of all the unique beacons (same uuid/major/minor) seen and update it in the ranging callback. You can then access this array in the region exit callback, so you know which beacons disappeared. Of course, it is possible that additional beacons were seen after the 5 seconds of background ranging time expires, but your app will never know about them. With this option, you must accept this limitation.
While it is true that errors on the distance estimate in ranging may incorrectly tell you which beacon is closest, you have an even worse problem when doing monitoring, because you don't get a distance estimate at all. If multiple beacons come into monitoring range around the same time, there is no guarantee that the first entered region callback you get will be for the closest beacon. So if your use case requires taking action based on the closest beacon, then you must do ranging (knowing that there may be error on the distance estimate.)
The drawback of the second approach is detecting the entry of a particular beacon will be purely based on ranging, that will not work if the application is killed. The reason is we will get didEnterRegion only once, because we are monitoring only one region with a particular UID. The next beacon with same UID will not be detected again if the application is terminated or if the background ranging stopped.
I recommend a combination of the mentioned approaches ,
Use same UID for all the beacons.
A beacon is uniquely identified using major/minor value that is collected when ranging.
As mentioned in apple doc, always keep number of monitoring regions below 20 by removing and adding beacons when the user moves from beacon to beacon (better to keep a beacon neighbour relationship graph in the server.)
Start ranging when entering the region ... and identify major/minor and calculate proximity.
Stop ranging when exiting the region.
Find the closest beacon from ranging method (need to skip unknown range beacons).
Monitor only the neighbours of the closest beacon in a given time.
When implementing both options, We should consider one fact, An iBeacon will be detected in 200feet distance. There may be multiple beacons in 200feet range.
If you use the same UUID for every beacon, you can just set the major/minor numbers to differentiate between the different beacons. This way, you are only monitoring for 1 beacon instead of > 20. Then just sort out which one is which from the other identifiers. This is how it works currently with Starbucks and other retailer apps. 1 beacon no matter where you are in the world, and different identifiers to sort things out on the back end.

How to limit the advertising range of a beacon?

Is it possible to limit the ranging of the beacon, so that only devices within a certain close range(or proximity) can identify and connect to the beacon? Lets say for example the devices outside 0.5 meter zone shouldn't be able to see or connect to the beacon. I am using a iOS device as a beacon. In the Apple's CoreLocation API, there is a method called peripheralDataWithMeasuredPower in the CLBeaconRegion class which says:
peripheralDataWithMeasuredPower:
Retrieves data that can be used to advertise the current device as a beacon.
(NSMutableDictionary *)peripheralDataWithMeasuredPower:(NSNumber *)measuredPower
Parameters:
measuredPower:
The received signal strength indicator (RSSI) value (measured in decibels) for the device. This value represents the measured strength of the beacon from one meter away and is used during ranging. Specify nil to use the default value for the device.
Can this be used to limit the range of beacon? If yes, I am unable to understand how to decide the value to set for measurePower parameter? What are they trying to say by ...value represents the measured strength of the beacon from one meter away..?
Please forgive if this is a very basic question. I've recently started iOS development and will appreciate your help. Thanks.
Unfortunately, there is no easy way to adjust the range of an iBeacon without special hardware.
The power field that you mention is simply a calibration value transmitted by an iBeacon. It doesn't affect the actual physical radio range of the iBeacon. If the transmitter can be seen by an iPhone 50 meters away, altering the power field value will not change this at all. The only thing it does is change is the calibration constant which is an input to the distance estimation algorithm (used for the accuracy and proximity fields) inside the iOS software. Altering the power field will affect the estimated distance returned by the API, but it won't change the actual distance at which the iBeacon is first detected.
Altering the transmit power of a standard bluetooth iBeacon is practically impossible. In theory you can use metal shielding to construct a "faraday cage" around the transmitter to mute its power, but my experience is that it isn't very effective and it is highly susceptible to tiny imperfections in the shielding. If you want to change the transmit power you have to have somebody build you custom hardware.
The software alternative is to use the ranging API to track an iBeacon while it is visible, and only perform an action when the estimated distance is close enough, say 0.5 meters as you suggest. This works great -- only in the foreground.
If you require actually waking up your app in the background at a close range, this won't work. The best you can do is have the monitoring API wake up your app when the iBeacon is first detected, and then send a notification to the user and start ranging. If the user elects to bring the app to the foreground (at 50 meters) you can keep monitoring and then perform your desired action at 0.5 meters. If the user does not elect to bring the app to the foreground, iOS will only give you about 5 seconds of time to continue ranging before it suspends your app. It is very unlikely that the distance will change from 50 meters to 0.5 meters in this time.
With most BLE chips I've investigated, there are usually at least four settings for transmission power level that can be used to limit the advertising range.
The Texas Instruments CC2541 (as used in their SensorTag development device) and CC2540 have +4, 0, -6, and -23 as their power level options. However, changing that in the SensorTag does require a recompile of the firmware. As-is, the provided firmware mentions the power level in only one place, but that is just a value that is broadcasted to inform any central listener how loud the beacon is—so that the central device can better calculate an estimated range based on received signal strength (RSSI). An additional line must be added to the firmware to actually change the transmission power. For example:
HCI_EXT_SetTxPowerCmd( HCI_EXT_TX_POWER_0_DBM );
Based on this, there should be two places on an iOS device where you can set the power level: one that just informs the listeners what the level is, and one where the BLE chip's true transmission power is actually changed. However, expect these values to be restricted to only a few enumerated choices which may or may not meet your real-world range needs.
(The SensorTag's -23 setting would probably do well for a 0.5 meter detection range. But if you want the SensorTag to always be advertising, it will require an additional firmware change.)
Have you looked to see if the proximity property was helpful? From the apple docs:
CLProximity
Constants that reflect the relative distance to a beacon.
typedef {
CLProximityUnknown,
CLProximityImmediate,
CLProximityNear,
CLProximityFar
} CLProximity;
I would also experiment trying to combine the the proximity with accuracy and rssi.
It's gonna vary from beacon to beacon. If you use beacons from Radius Networks, they have a transmit power setting that lets you essentially limit the ability of the beacon radio to broadcast to long ranges. I don't know if other brands have it, but most do not from what I've seen.

Resources