RTL.Desktop Beacon Cast Demo Sample

From RAD Studio Code Examples
Jump to: navigation, search

The sample shows how to use the TBeacon component in a client application to scan for beacon devices. The sample also demonstrates how to take some actions on a specific beacon device, defined by GUID, Major and Minor parameters, when the proximity is inmediate (below 0.5 meters).

To have this sample working and showing values, you need a beacon device.

Location

You can find the Desktop Beacon Cast sample project at:

Description

This is a sample of a server - client application that uses tethering and beacon technology. Beacon transmitters use Bluetooth 4.0 technology to send specific information to nearby devices based on location.

The server and client applications connect to each other using tethering components. Start the server to enable the tethering manager to allow communication with the client application.

The TBeacon component on the client scans for beacon devices, when the beacon device with the parameters defined on the server is found and the proximity to the device is below 0.5 meters, remote actions are executed to take and get a screenshot from the server.

How to Use the Sample

Navigate to the location given above and open DesktopBeaconCast.groupproj. The group contains two projects, the server and the client application. Run the server on a computer and then deploy the client to a mobile device.

  • Run the server:
  1. Select VCLBeaconCastDesktop.exe on the Projects Window.
  2. Press F9 or choose Run > Run.
  3. Introduce the parameters GUID, Major and Minor identifying the beacon that you want to use to represent the server.
  4. Click Start to enable communication with the client.
  5. Click Stop to stop communication with the client.
    • Note: You can create as many server - beacon associations as you need by repeating the steps above. Make sure that the server app has permissions to access the network in order for clients to connect.
  • Run the client:
  1. With the server running, select FMXClientBeaconCast on the Projects Window.
  2. Select the target platform. The application works with iOS and Android.
    Note: See Using Beacons for more information about client platform support for Beacons.
  3. Press F9 or choose Run > Run.
  4. Click Connect to start the automatic connection between tethering managers.
  5. Approach the mobile to the beacon associated to the server that you want to present on the client application. Once you are close enough to the beacon, a remote screenshot from the server is created and sent to the client by using tethering.

Implementation

The client application lists all the available servers after clicking Connect. The client is notified about the beacon parameters associated with all the available servers. The parameters that identify a specific beacon, that is GUID, Major, and Minor, are stored in a shared resource on the server application. The method used to get the information from the server resource is GetRemoteResourceValue.

The client application uses a TBeacon component to scan for beacon devices. ScanningSleepingTime and ScanningTime properties are used to define the scanning period. The OnBeaconProximity event is fired every time the proximity value changes on the detected beacon. The event handler checks if:

  • The parameters GUID, Major and Minor from the beacon are the same parameters as the ones defined on the server application.
  • The Proximity to the beacon is Inmediate, below 0.5 meters.

When restrictions are met, OnBeaconProximity event launches a remote screen shot on the server and loads it on the client.

To take and load the remote screenshot from the server, the application uses the TTetheringManager component and the TTetheringAppProfile component.

The TTetheringAppProfile component is used on the server and the client to create tethering profiles. The Group property allows the connection between the server and the client. There is an action defined on the server profile, actFullShot to create and save the screenshot as a resource. The client uses GetRemoteResourceValue to load the image to the client.

Uses

See Also