RTL.BeaconProximityColors Sample
The sample shows how to implement an application for detecting changes on the proximity property of a detected Beacon. The sample indicates if a new beacon has gone into the Inmediate area. If a change is detected, the form changes its background color.
To have this sample working and showing changes, you need a Bluetooth LE beacon compatible to one of the available types: iBeacon or AltBeacon.
Location
You can find the ColorBeaconProximity sample project at:
- Start | Programs | Embarcadero RAD Studio Athens | Samples and navigate to:
Object Pascal\Multi-Device Samples\Device Sensors and Services\Bluetooth\Beacons\DemoProximityColors
CPP\Multi-Device Samples\Device Sensors and Services\Bluetooth\Beacons\DemoProximityColors
- Subversion Repository:
- https://github.com/Embarcadero/RADStudio12Demos/tree/master/Object%20Pascal/Multi-Device%20Samples/Device%20Sensors%20and%20Services/Bluetooth/Beacons/DemoProximityColors
- https://github.com/Embarcadero/RADStudio12Demos/tree/master/CPP/Multi-Device%20Samples/Device%20Sensors%20and%20Services/Bluetooth/Beacons/DemoProximityColors
Description
This sample searches beacons that are advertising its manufacturer data according to one of the available types. This sample is developed using the Beacon framework directly instead of the TBeacon component. In Using Beacons you can find more information about how to implement a beacon application.
How to Use the Sample
- Navigate to the location given above and open:
- Delphi: ColorsBeaconProximity.dproj.
- C++: ColorsBeaconProximityCPP.cbproj.
- Select as a platform, a device with a bluetooth LE sensor.
- Note: See Using Bluetooth for more information about client platform support for Bluetooh LE.
- Press F9 or choose Run > Run.
- Click Start to start to detect beacons.
- Click Stop to stop to detect beacons.
Implementation
When the form is initially shown, the application initializes and configures everything needed for receiving beacons:
- Gets an instance of the TBeaconManager for the beacon type. The sample is configured for Standard (iBeacon), you must get the instance for the type of your beacon.
- Registers the event OnBeaconProximity.
- Note: The OnBeaconProximity event occurs every time the proximity parameter of a detected beacon changes.
- Registers the beacons you want to detect.
- Note: The sample is registered for the UUID {B9407F30-F5F8-466E-AFF9-25556B57FE6D}. You must register the UUID of your own beacons.
- Configures some parameters of the TBeaconManager:
- And starts scanning beacons.
Once the OnBeaconProximity event occurs, if the new proximity parameter is Inmediate, the color of the form changes. The color is associated to the beacon which proximity value changes. In this sample, the beacon is identified by its Major ID, you must use the Major ID and/or Minor ID of your beacon instead.
Uses
- System.Beacon.TBeaconManager
- System.Beacon.TBeaconProximityEvent
- System.Beacon.TBeaconProximity
- System.Beacon.IBeacon.Major
- System.Beacon.TBeaconManager.StartScan
- System.Beacon.TBeaconManager.StopScan
- System.Beacon.TBeaconManager.GetBeaconManager
- System.Beacon.TBeaconManager.RegisterBeacon
- System.TGUID