RTL.BLE BeaconScanner Sample

From RAD Studio Code Examples
Jump to: navigation, search

This is a sample that shows the use of the Bluetooth API to search for nearby Beacons and display their information.

Location

You can find the BLE Beacon Scanner sample project at:

Description

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 Button1Click event handler.
  • Cancel Discovery: Fires the Button2Click event handler.
  • ListBox1: Displays the information about the discovered beacons.

How to Use the Sample

  1. Navigate to one of the locations given above and open:
    • Delphi: BLEBeaconScanner.dproj.
    • C++: BLEBeaconScannerCPP.cbproj.
  2. Press F9 or choose Run > Run.
  3. Click the Start Discovery button to start searching for devices.
  4. 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 ListBox1 control:

  • 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.

Implementation

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.

Main Form

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 ListBox1 control.

Uses

See Also