RTL.BLE BeaconScanner Sample
This is a sample that shows the use of the Bluetooth API to search for nearby Beacons and display their information.
You can find the BLE Beacon Scanner sample project at:
- Start | Programs | Embarcadero RAD Studio Alexandria | Samples and navigate to:
Object Pascal\Multi-Device Samples\Device Sensors and Services\Bluetooth\Beacons\BLE_BeaconScanner
CPP\Multi-Device Samples\Device Sensors and Services\Bluetooth\Beacons\BLEBeaconScanner
- Subversion Repository:
- You can find Delphi and C++ code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.
This application uses the Bluetooth API to search for nearby beacons and display their information.
The application uses the following controls:
Start Discovery: Fires the
Cancel Discovery: Fires the
ListBox1: Displays the information about the discovered beacons.
How to Use the Sample
- Navigate to one of the locations given above and open:
- Delphi: BLEBeaconScanner.dproj.
- C++: BLEBeaconScannerCPP.cbproj.
- Press F9 or choose Run > Run.
- Click the Start Discovery button to start searching for devices.
- Wait until the discovery completes.
To interrupt a discovery, click the Cancel Discovery button to stop searching for devices.
The application displays the following information about the discovered beacons in the
- Beacon Found: The name of the discovered beacon and the type of the beacon. The type of the beacon is either iB (iBeacon) or AltB (any other beacon).
- Device Complete Name: The complete device name that the beacon broadcasts.
- UUID: The GUID identifier of the beacon.
- Major: The Major identifier of the beacon.
- Minor: The Minor identifier of the beacon.
- txPower: The power transmission of the beacon.
- Rssi: The received signal strength indicator of the beacon.
- Distance: The calculated distance to the beacon, in meters.
This application uses an instance of TBluetoothLEManager to:
- Search for nearby Bluetooth Low Energy devices.
- Decode the response from each device and determine if that device is a beacon.
- Display the information about each discovered beacon.
This application implements a custom event handler for the OnDiscoverLeDevice event, DiscoverLEDevice, that processes the response from discovered devices and displays the relevant information about any discovered beacons.
On initialization, the
FormShow method creates a list where the discovered devices are stored.
- The application defines the following event handlers:
Button1Click: Initializes an instance of TBluetoothLEManager, registers the event handler for the OnDiscoverLeDevice event and starts the discovery for Bluetooth Low Energy devices.
Button2Click: Cancels the discovery.
DiscoverLEDevice: Decodes the response from each discovered device. If the discovered device is a beacon, DiscoverLEDevice displays the relevant information about that beacon in the