Beacons on HSYCO App for iOS

From HSYCO
Revision as of 10:44, 21 September 2020 by Gionatan (talk | contribs) (Created page with "Category:INCOMPLETE Category:Advanced Programming <div style="color:#CC0000">'''{{Note|<center>WARNING! The Beacons functionality for iOS is experimental and subject t...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
WARNING! The Beacons functionality for iOS is experimental and subject to changes.

HSYCO App works with beacons to provide location awareness.

This can be used for example to trigger a specific command when a user enters or leaves an area, or to display a relevant information when the user approaches a location.

General Concept

Each beacon is identified with the following values:

  • UUID: Universally Unique Identifier, which typically identifies a region
  • Major: also called most significant value, used to distinguish beacons with the same UUID by dividing regions
  • Minor: also called least significant value, used to divide regions even further

Beacons also have a Proximity property, which describes the distance between the beacon and the user's device. There are two modes of detecting beacons:

  • monitoring: detects entering and exiting a region. This happens even when the app is closed or in background
  • ranging: detects all the beacons currently in range, with their specific Proximity, which can have one of the following values: far, near, immediate, depending on the distance

HSYCO Implementation

HSYCO implements beacon detecting by using the values that identify a beacon to define regions as following:

  • Area: defined by UUID. Beacons should be setup so that a device can only be inside one Area at a time. An Area could for example describe the region of a specific connection, like an office.
  • Zones: divide Areas into smaller regions. Defined by UUID and Major. In the example above, a Zone could describe a room of the office.
  • Beacons: a single beacon defined by UUID, Major and Minor. This could be used to define a sub-region of a room, like the a desk.

Each Beacon is defined in hsyco.ini and given a unique Location ID.

e.g. Here is an example of the configuration of a beacon in hsyco.ini

LocationBaseBeacon.17081 = ACFD165E-C0C0-11E3-9BBE-1A514932AC01,1,17081

iOS has a hard limit of 20 on the number of regions that can be monitored at the same time.

To work with this limitation, HSYCO App automatically decides which region to monitor, using the following logic:

  • monitor Areas:
    • only if there are more than 20 Zones defined across all the enabled connections
    • only when the device is not inside an Area
    • a maximum of 20 Areas can be monitored
    • once an Area is entered, the App switches to monitor Zones
  • monitor Zones
    • only if there are more than 20 beacons defined across all the enabled connections
    • a maximum of 20 Zones can be monitored
    • when the device exits all the Zones, the App switched to monitor Areas
  • monitor Beacons
    • only if there are less than 20 beacons defined across all the enabled connections
    • useful for small applications, it gives the highest accuracy

Monitoring is used to detect entering and leaving regions. When the app is closed and an enter/exit event occurs, it will trigger ranging in background mode for a few seconds. This will in turn call the HSYCO Server LocationBeaconEvent, allowing logic to be applied. The Proximity of each beacon is saved locally on the device, so the LocationBeaconEvent will be triggered with the detected Proximity only when there's a variation. Ranging is always active for all defined beacons when the app is open (in foreground).

function LocationBeaconEvent(session, address, userid, zone, distance, background) : {
   messageLog("BEACON: " + address + ", " + userid + ", " + zone + "=" + distance + " (" + background + ")");
}


Working Around the 20 Zone Limit

Since no more than 20 Zones can be defined in an Area, working with more than that requires setting up the beacon identities in a specific way. Multiple beacons can have the same Zone identifier as long as the UUID is different.

So to cover large areas with a lot of Zones, 20 Zone identifiers can be repeated as long as they do not overlap, which means that at all times only one Zone with a specific identifier should be in range of a device.

Here's an example of how it could work:

IBeacon Zones.png