Bluetooth LE support in RAD Studio XE7

Posted by on in Tools

RAD Studio XE7's integrated wireless support (Bluetooth and Wifi) works with thousands of consumer and industry specific devices. RAD Studio's approach makes it easy to integrate virtually any device into the app user experience, and even support multiple device vendors with the same code.

In RAD Studio XE7, we have a new Bluetooth LE component for connecting to many different Bluetooth Smart Devices that work with the different GATT profiles.

We ship several Bluetooth demos with the product that you can look at. For Bluetooth LE, we have a heartrate monitor demo that displays your current heart rate by connecting to a heart rate sensor.
You can find the demo under: C:UsersPublicDocumentsEmbarcaderoStudio15.0SamplesObject PascalMobile SamplesDevice Sensors and ServicesBluetoothHeartRateMonitor

I am using the Zephyr heartrate monitor for this, but have also used Polar's H7 heartrate monitor.

I extended the demo slightly by adding a Listbox for logging the heartrate. Also, for the iPhone version, I customized my iPhone view using the new FireUI Multi-Device Designer to display a + icon instead of the 'Save' text for logging my heart rate since I am working with less screen real estate.



bluetooth_iPod.jpg   bluetooth2.jpg

Below are the necessary UUIDs we need to connect to our heart rate sensor:

  HRDeviceName = 'Cardiosport HRM';
  ServiceUUID = '';
  CharactUUID = '';

  // From the Bluetooth website Home > GATT Specifications > Services > ServiceViewer
// Exposes heart rate and other data from a Heart Rate Sensor
  HRSERVICE: TBluetoothUUID = '{0000180D-0000-1000-8000-00805F9B34FB}';

  // from the Bluetooth website under Home > GATT Specifications > Characteristics > CharacteristicViewer
  HRMEASUREMENT_CHARACTERISTIC: TBluetoothUUID  = '{00002A37-0000-1000-8000-00805F9B34FB}';
  BODY_SENSOR_LOCATION_CHARACTERISTIC: TBluetoothUUID  = '{00002A38-0000-1000-8000-00805F9B34FB}';

  //Body Sensor Location Characteristic value used to index the array to display the string
  BodySensorLocations : array[0..6] of string = ('Other', 'Chest', 'Wrist', 'Finger', 'Hand', 'Ear Lobe', 'Foot');



Here is the btnScanClick code:

procedure TfrmHeartMonitor.DoScan;
  lblDevice.Text := '';
  lblBodyLocation.Text := '';
  lblContactStatus.Text := '';
  BluetoothLE1.DiscoverDevices(2500, [HRSERVICE]);

We also set up several additional events:


procedure TfrmHeartMonitor.BluetoothLE1EndDiscoverDevices(const Sender: TObject;
  const ADeviceList: TBluetoothLEDeviceList);
  I: Integer;
  // log
  Memo1.Lines.Add(ADeviceList.Count.ToString +  ' devices discovered:');
  for I := 0 to ADeviceList.Count - 1 do Memo1.Lines.Add(ADeviceList[I].DeviceName);

  if BluetoothLE1.DiscoveredDevices.Count > 0 then
    FBLEDevice := BluetoothLE1.DiscoveredDevices.First;
    lblDevice.Text := HRDeviceName;
    if BluetoothLE1.GetServices(FBLEDevice).Count = 0 then
      Memo1.Lines.Add('No services found!');
      lblBPM.Font.Size := 26;
      lblBPM.Text := 'No services found!';
    lblDevice.Text := 'Device not found';


 Here is a video of our Bluetooth LE support in action: 




Gold User, Rank: 5, Points: 558
Senior Product Manager, RAD Studio


  • Tommy
    Tommy Thursday, 14 April 2016

    Hi, this demo in XE10 can be built and deployed into Android and iOS app very well. But I had a problem. I found that I could not SubscribeToCharacteristic again after I disconnected and reconnected to the BluetoothLE device in iOS. If I put two BluetoothLE components on the same application, I can use the two components to SubscribeToCharacteristic two times very well. I think it is because there is some closing procedure not done. I tried to use UnSubscribeToCharacteristic before disconnecting the BluetoothLE. But, it was still no use. Anyone has the solution for this issue? Thanks in advance.

  • Reiler
    Reiler Thursday, 12 March 2015

    I have problems getting this example to work, I have tried with a WAHOO TICKR HR belt, which is both Bluetooth LE and ANT+
    The example can see the TICKR, but only if I do not search specifically for HRDEVICE, and it returns no services.

    The TICKR works with other applications on both my Android phone and on my IPad Mini (Strava, Endomondo), but not with this example.

    Do you have an suggestions of what I can try?

  • Henrik F4048
    Henrik F4048 Sunday, 8 February 2015

    I did the editing of the info file and made it work. However, I need to click the home button to make it enter background mode myself. In case I do so, I can reopen it later on - and everything is looking ok. I see all the samplings with time stamps in the log file. However, in case I leave my iPhone with the app running and the phone forces it into background mode - I am unable to reopen it again later on and read the log. It opens but in the initial state without sampling. Is this a well known thing?

  • Henrik F4048
    Henrik F4048 Saturday, 7 February 2015

    I just managed adding battery level monitoring and a few more things. It is working well with my Polar H7 sensor and my iPhone 5S - but how do I make it keep running in background? BR Henrik

  • Please login first in order for you to submit comments
  • Page :
  • 1

Check out more tips and tricks in this development video: