📜 ⬆️ ⬇️

iBeacon. Myths and Reality


(picture from developer.apple.com )

What it is?


In mid-2013, Apple at a conference for developers suddenly said that they had prepared a new technology for indoor navigation, that they began to create maps of museums, shopping centers and other interesting places, and in general, everything is cool. Believing in the word of a large company, many began to offer “solutions” for indoor navigation, but few of them got something workable. It turned out that in reality it is quite difficult to apply this technology.

I also took an active part in technology research. It was possible to deploy a network of beacons at GeekPicnic events in Moscow and in St. Petersburg, testing the capabilities of the technology. After that, I wrote a library that, using a small number of lighthouses, makes it possible to determine the location inside the premises quite well.
')
In the article I will briefly describe what iBeacon is, what tasks I had to solve with this technology, what was possible, what was not very.

What is iBeacon ? This is a protocol subset of Bluetooth Low Energy, which allows you to find out:


It looks like this:

fb0b57a2-8228-44 cd-913a-94a122ba1206 Major 1 Minor 2 

You can use iBeacons on iPhones, starting with 4S, Aipads, starting with the third generation, iPad Mini, iPod Touch (fifth generation), Android support should be found in specific devices, and the OS version should be 4.3 or higher. You can also use Macintosh computers.

Real-life experience


When we considered the possible uses of technology, it turned out very nicely:


In practice, it turned out that everything is not so simple.

The main disappointment is that the navigation is extremely inaccurate. In the next section, I will show how you can make adequate navigation on beacons, but generally beacons are poorly designed for navigation.

In general, the basic algorithm for working with beacons - when a user device approaches it, a notification appears. Immediately you want to catch all beacons in a row. But, unfortunately, in order to process a notification, you need to write the appropriate application and enter the parameters of a specific beacon (or a specific type of beacons, for this purpose, the UUID is usually used, which are the same for all the desired beacons). That is, you can not just take and hang up, for example, an advertising beacon, so that it hangs and cuts to all who pass. It is necessary to force to put an application that listens only to those beacons to which it is configured (it cannot be configured for everything, because startMonitorForRegion will not allow adding an infinite number of regions):

 NSString *uuid = @"B9407F30-F5F8-466E-AFF9-25556B57FE6D"; CLBeaconRegion *region = [[CLBeaconRegion alloc] initWithProximityUUID:[[NSUUID alloc] initWithUUIDString:uuid] identifier:[NSString stringWithFormat:@"beacon_%@", uuid]]; region.notifyEntryStateOnDisplay = YES; _locationManager startMonitoringForRegion:region]; [_locationManager startRangingBeaconsInRegion:region]; 

Chop is also not easy. The reaction rate of the device (smartphone) is from a second to a couple of minutes. That is, the user can walk past the beacon, walk a few more minutes, only after that a notification will appear.

Beacons themselves - break. If you buy a lot of them (and this is more or less necessary for almost all use cases), then you have to save, therefore, the beacons fail and need to be replaced. Nothing could be simpler, but after replacing you need to re-match the correspondence to a specific data bicon (advertising text, or coordinates). As a result, in the development you can not do only the application and the Beacons. We have to create a server that must keep the information consistent with the beacons, and the application needs to regularly update the data.

Returning to real use. In 2015, two GeekPicnic events took place in Moscow and St. Petersburg. These are outdoor events where many different speakers, interesting artifacts, cars, and art objects gather. In two days, the event is attended by 25,000 people.

At each event (which takes place in the open air and in several pavilions) dozens of interesting objects. It’s not very convenient to search for them on the map, so it was decided to use beacons for their designation and notifications when the user approaches them. I wrote an application for iPhone, colleagues then repeated it for Android.


The scheme itself turned out to be about the following:


In order to avoid “bounce” and a large number of notifications, data on all the beacons around and the closest one was kept, and it should be “substantially closest”, while several beacons are approximately at the same distance, the notification does not pass.

Also had to solve the problem of energy consumption. To ensure that navigation is not turned on immediately after installing the application, firstly, scanning of beacons was turned on only on certain days, and secondly, only in a certain area (within a radius of several kilometers from the venue of the event). It was fun to test both of these conditions, I had to drive a car with debugging turned on, watching the smartphone's activity (and, in different states, active, sleep mode).

As a result, everything turned out well, and my colleagues and I got invaluable experience in implementing a large project using beacons.

Indoor Navigation


Let us turn to the technique. When they talk about navigation, they usually mean finding a location by distance to several points (this is how GPS works, triangulation of location along cell towers, and this is exactly what they usually talk about in movies). The algorithm is simple:


Anyone who tried to do this with beacons, quickly realized the futility of the idea. The location of beacons can be measured accurately, but the distance to them is measured by the power of the beacon signal. This power is very dependent on air pressure, humidity, the presence of various obstacles (including people and other living creatures). Very - this means several times. Of course, the software tries to smooth it out by applying filters and different algorithms, but this is not important. The algorithm in such conditions, in fact, does not work (produces extremely inaccurate results).

Thinking a little, I remembered that there is another option. Unlike the "normal" algorithm, it does not give the exact location of the user, but rather shows what area he is in. But for an indoor location, this is often enough.

The algorithm is called fingerprinting, the location imprint. In general, it looks like this:


Incomprehensible moment was exactly how to save prints. Power can not be directly (they swim very much). I tried the relative power, it turned out much better.

Swimming capacity is noticeable even if just spinning in one place. We stand, we turn, and the picture changes dramatically. Therefore, I began to take several prints, standing in one place. The prints themselves turned out like this:

 @property (nonatomic) NSString *uuid; @property (nonatomic) CLBeaconMajorValue major; @property (nonatomic) CLBeaconMajorValue minor; @property (nonatomic) CGFloat relativeDistance; // 0-1 (normalized by the powerful) @property (nonatomic) CGFloat relativePowerDispersion; // 0-1 (normalized by the most powerful) 

I took these parameters for each visible beacon at a given point, and all the parameters for all beacons — and became an imprint.

I also wanted, of course, that the point on the map would not just jump, but move around the map. To do this, we had to interpolate the footprint, realizing what the user is between which areas / points, and, of course, filter the result that was very strong. The distance between the current fingerprint and the footprints of the regions was calculated like this:

 for (Fingerprint *f in in _regions[regionName].fingerprints) { CGFloat newDistance = [f normalizedDistanceToFingerprint:aBeaconsFingerprint]; CGFloat distance = (CGFloat) (result[regionName] == nil ? FLT_MAX : [result[regionName] doubleValue]); distance = MIN(newDistance, distance); result[regionName] = @(distance); } 

And, in fact, the very distance between the prints, so:

 - (CGFloat)normalizedDistanceToFingerprint:(NSMutableDictionary *)aBeaconsFingerprint { // if we do not have a beacon in region fingerprint — add DISTANCE_PENALTY_FOR_ABSENT_BEACON // if we do not have any beacons, result is "FLT_MAX" CGFloat result = 0; BOOL resultIsNotInfinite = NO; NSArray *regionBeaconIds = [_beaconsFingerprint allKeys]; NSArray *testingBeaconIds = [aBeaconsFingerprint allKeys]; for (NSString *beaconId in regionBeaconIds) { if (![testingBeaconIds containsObject:beaconId]) { result += DISTANCE_PENALTY_FOR_ABSENT_BEACON; } else { result += fabs( fabs(((Fingerprint *) _beaconsFingerprint[beaconId]).relativeDistance) - fabs([aBeaconsFingerprint[beaconId] doubleValue])); resultIsNotInfinite = YES; } } for (NSString *testingBeaconId in testingBeaconIds) { if (![regionBeaconIds containsObject:testingBeaconId]) { result += DISTANCE_PENALTY_FOR_ABSENT_BEACON; } } return resultIsNotInfinite ? result : FLT_MAX; } 

It turned out very well. This solution will require you to think up a replacement system for a failed beacon (to retake all prints is a bad decision, it can take a lot of time). And if there are a sufficient number of well-placed beacons (it is best to hang them closer to the ceiling, for example, but this is not the only recommendation) - and the accuracy is good (± a few meters).

findings


Now the buzz around iBeacon technology has subsided. But the tasks have not gone away. Indoor navigation is still required. Still need the opportunity to inform visitors of the store about new products. And now it can be done not only with advertising banners, but also with such beacons.

Of course, their actual use is not so straightforward, and many tasks need to be solved in order for it to work as it should. The main conclusion of more than a year of working with technology is, with certain reservations, viable. And then you need to look whether it is suitable for a particular application or not. Alas, the silver bullet has not happened yet.

Source: https://habr.com/ru/post/278689/


All Articles