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.
Below are the necessary UUIDs we need to connect to our heart rate sensor:
1 2 3 4 5 6 |
const HRDeviceName = 'Cardiosport HRM'; ServiceUUID = ''; CharactUUID = ''; <strong> // Fr<span style="line-height:15.8079996109009px;">om the Bluetooth website </span><span style="line-height:1.3em;">Home > GATT Specifications > Services > ServiceViewer<br></span></strong><span style="line-height:1.3em;"><strong> // Exposes heart rate and other data from a Heart Rate Sensor</strong> </span> |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
HRSERVICE: TBluetoothUUID = '{0000180D-0000-1000-8000-00805F9B34FB}'; <strong> // from the Bluetooth website under Home > GATT Specifications > Characteristics > CharacteristicViewer</strong> HRMEASUREMENT_CHARACTERISTIC: TBluetoothUUID = '{00002A37-0000-1000-8000-00805F9B34FB}'; BODY_SENSOR_LOCATION_CHARACTERISTIC: TBluetoothUUID = '{00002A38-0000-1000-8000-00805F9B34FB}'; <strong> //building Sensor Location Characteristic value used to index the array to display the string</strong> BodySensorLocations : array[0..6] of string = ('Other', 'Chest', 'Wrist', 'Finger', 'Hand', 'Ear Lobe', 'Foot'); HR_VALUE_FORMAT_MASK = $1; SENSOR_CONTACT_STATUS_MASK = $6; ENERGY_EXPANDED_STATUS_MASK = $8; RR_INTERVAL_MASK = $10; |
Here is the btnScanClick code:
1 2 3 4 5 6 7 8 |
procedure TfrmHeartMonitor.DoScan; begin ClearData; lblDevice.Text := ''; lblBodyLocation.Text := ''; lblContactStatus.Text := ''; BluetoothLE1.DiscoverDevices(2500, [HRSERVICE]); end; |
We also set up several additional events:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
procedure TfrmHeartMonitor.BluetoothLE1EndDiscoverDevices(const Sender: TObject; const ADeviceList: TBluetoothLEDeviceList); var I: Integer; begin // 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 begin FBLEDevice := BluetoothLE1.DiscoveredDevices.First; lblDevice.Text := HRDeviceName; if BluetoothLE1.GetServices(FBLEDevice).Count = 0 then begin Memo1.Lines.Add('No services found!'); lblBPM.Font.Size := 26; lblBPM.Text := 'No services found!'; end else GetServiceAndCharacteristics; end else lblDevice.Text := 'Device not found'; end; |
Here is a video of our Bluetooth LE support in action:
{“video”:”https://www.youtube.com/watch?v=oeyGzuC_QqU”,”width”:”480″,”height”:”360″}
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition