Using Beacons

From Appmethod Topics
Jump to: navigation, search

Go Up to Using Bluetooth

A beacon is a Bluetooth Low Energy device including some information in its advertising data, specifically in the "Manufacturer Specific Data" described in "Bluetooth Specification Version 4.1, page 2023" This information allows any Bluetooth Low Energy device in the surrounding area to identify the device and calculate the distance to it without being paired or establishing a connection.

Beacon Overview

Beacon Types

Two beacon formats are available: iBeacon and AltBeacon:

  • iBeacon: It is the format defined by Apple. For the RTL API, the iBeacon is considered the Standard Mode.
  • AltBeacon: It is an open format, known as Alternative beacon. The full specifications can be found in For the RTL API the Alternative beacon is considered the Alternative Mode.

You need to know the format that is using the beacon you want to monitor.

Manufacturer Information

Bluetooth Low Energy devices in advertising mode send the Advertising Data repeatedly over radio in different AD type structures. One of the AD types in the Advertising Data is the "Manufacturer Specific Data" which is utilized for beacons. The data included in the "Manufacturer Specific Data" which the RTL API provides for beacons is:

  • UUID: A unique identifier which identifies a group of beacons, for example, the beacons of a specific company.
  • MajorID, MinorID: Identifies regions inside a specific UUID. MajorID identifies a sub-region within a larger region defined by an UUID. The MinorID specifies further subdivision within a MajorID.
  • TxPower: The TxPower is the measured power from 1 meter of distance. With TxPower and the Received Signal Strength Indicator (RSSI), the approximate distance to a Beacon is calculated.

Platform Support

Platform Supported?


Mac OS X






RTL API for beacons is not available for Windows platform because the advertising data is not accessible.

How to Use Beacons

The RTL API for beacons allows you to obtain the Distance between the device that is running your application and the surrounding beacons. The RTL API for beacons provides information only for the beacons within a defined region. Region is a group of beacons specified with their UDID, MajorID and MinorID.

Obtaining an instance of TBeaconManager

To use the RTL API for beacons, you must include the System.Beacon unit in your application, and call TBeaconManager.GetBeaconManager for the TBeaconScanMode you want to use to get an instance of TBeaconManager.

For iBeacons:

    BeaconManager := TBeaconManager.GetBeaconManager(TBeaconScanMode.Standard);

For AltBeacons:

    BeaconManager := TBeaconManager.GetBeaconManager(TBeaconScanMode.Alternative);

The ScanMode identifies the type of beacon the system should look for: Standard Mode or Alternative Mode. TBeaconManager is the main class of the beacon implementation of the RTL API for beacons. TBeaconManager is in charge of registering regions, and manages the events to get the information from beacons. The TBeaconManager instance must be created either for Standard Mode or Alternative Mode.

Registering Regions to be Monitored

You must register the regions of the beacons you want to monitor. For registering regions, you must call TBeaconManager.RegisterBeacon.


Regions are specified with the parameters UUID, MajorID and MinorID. For registering a region, only the parameter UUID is required. In case you want to be more specific about the region you want to register, you can also use MajorID, MinorID or both, according to the three overloaded TBeaconManager.RegisterBeacon defined.

Start & Stop to Scan Beacons

Once the beacons you want to monitor are registered, you can start to monitor those beacons calling TBeaconManager.StartScan. In case you want to stop to monitor beacons you must call TBeaconManager.StopScan.

Getting information from incoming beacons

The way of getting the information about the monitored beacons is through the events associated to the TBeaconManager. These events are:

Once the event is fired, you can use the information provided by the event.

Note: Due to cross platform compatibility requirements, if you register several region items with the same UUID and you wish to monitor them, you can only get events of the last region item that you registered in the TBeaconRegionCollection. In case you want to monitor different regions, you can proceed in two different manners depending on your scenario:
  • Register a region with its specific UUID, MajorID=-1 and MinorID=-1 in order to receive events associated to all the beacons with the same UUID.
  • Register a region with its specific UUID and design your app to filter MajorID and MinorID according to your custom values and app requirements.

Adding Location Services

Location services allow location-based apps to use information from cellular, Wi-Fi, GPS and beacons to determine your approximate location. For detecting beacons, you must enable the location services.

For Android, you must enable the bluetooth options in Project > Options > Uses Permissions.

For iOS platform on Alternative Mode, you do not need to activate Location services. In Standard Mode (iBeacons), the location activation request must be accepted first time the App is launched.

From iOS 8.0, if you use the Standard Mode, some keys for enabling the application to use the location services are needed for beacon detection. The IDE already includes NSLocationAlwaysUsageDescription and NSLocationWhenInUseUsageDescription.

The key we need to add manually is:

  • NSLocationUsageDescription

For the values we just need a text message such as "This app needs access to Location services to monitor beacons". The system shows the text message when it accesses the app configuration.

The key can be added in the IDE, Project > Options > Version Info and then right-click on the grid and Add Key.


Indoor Limitations

The radio signal that beacons broadcast is highly sensitive to noise effects such as diffraction, absorption, multipath reflections, or interferences that come from other devices that emit in the same radio frequency band. In particular, these harmful effects critically affect the signal of the beacon in indoor environments. As a result, the estimates extracted from power measurements, such as Rssi, Distance or Proximity, become considerably unstable and tend to fluctuate. Thus the accuracy of these estimations diminishes.

Signal processing

The RTL provides two different algorithms to make the signal of a beacon and the estimates extracted from that signal more stable:

  • RssiToDistance introduces a model to get the distance estimate derived from Rssi measurements. Note that a calibrated power parameter, ATxPower, enhances the robustness of the algorithm.
  • TBeaconManager implements an optional differential filter algorithm. This algorithm stabilizes the Rssi and distance measurements. To enable this algorithm, select the Stabilized calculation mode on the CalcMode property. This mode is especially useful for proximity estimation and movement detection.

Embeding algorithms

You can also embed further signal-processing algorithms, which may be either general-purpose algorithms or algorithms designed by yourself. The following list contains some example filters that you can implement to mitigate noise effects:

  • Moving average filter
  • Weighted average filer
  • Curve fitting filter

See Also