2

I am learning to program with Bluetooth LE Devices and writing a simple mobile app. Here is my entry-level question:

Say I only want to connect to a certain type of Bluetooth LE device (like a blood pressure device), but when I do a scan it could return more than one result if there are other Bluetooth LE device present in range. So I might get the following results:

Device 1 RSSI, Device 1 Name, Device 1 Address;

Device 2 RSSI, Device 2 Name, Device 2 Address ...

How can I tell the code to pick up the type of device that I want (in this case, the blood pressure device)? Does the device address get assigned by the vendor of the product and are they unique enough and following a scheme that I can use to identify this type of device? If not, what other option do I have for the app to automatically recognize a certain type of Bluetooth device?

Jason
  • 821
  • 2
  • 16
  • 28

3 Answers3

2

If you want to pick up the particular device means you have to mention in displayGattServices. For Example :-for using heart rate sensor device you have mentioned like this

 if (SampleGattAttributes.lookup(uuid, unknownCharaString)
                        .contains("Heart")) {
                    hrt_rate_char = gattCharacteristic;
                }

For Detail see displayGattServices method:

private void displayGattServices(List<BluetoothGattService> gattServices) {
        if (gattServices == null)
            return;
        String uuid = null;
        String unknownServiceString = getResources().getString(
                R.string.unknown_service);

        String unknownCharaString = getResources().getString(
                R.string.unknown_characteristic);

        ArrayList<HashMap<String, String>> gattServiceData = new ArrayList<HashMap<String, String>>();

        ArrayList<ArrayList<HashMap<String, String>>> gattCharacteristicData = new ArrayList<ArrayList<HashMap<String, String>>>();

        mGattCharacteristics = new ArrayList<ArrayList<BluetoothGattCharacteristic>>();

        for (BluetoothGattService gattService : gattServices) {
            HashMap<String, String> currentServiceData = new HashMap<String, String>();

            uuid = gattService.getUuid().toString();
            currentServiceData.put(LIST_NAME,
                    SampleGattAttributes.lookup(uuid, unknownServiceString));

            currentServiceData.put(LIST_UUID, uuid);
            gattServiceData.add(currentServiceData);

            ArrayList<HashMap<String, String>> gattCharacteristicGroupData = new ArrayList<HashMap<String, String>>();
            List<BluetoothGattCharacteristic> gattCharacteristics = gattService
                    .getCharacteristics();

            ArrayList<BluetoothGattCharacteristic> charas = new ArrayList<BluetoothGattCharacteristic>();

            for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) {
                charas.add(gattCharacteristic);

                HashMap<String, String> currentCharaData = new HashMap<String, String>();

                uuid = gattCharacteristic.getUuid().toString();
                if (SampleGattAttributes.lookup(uuid, unknownCharaString)
                        .contains("Heart")) {
                    hrt_rate_char = gattCharacteristic;
                }
                currentCharaData.put(LIST_NAME,
                        SampleGattAttributes.lookup(uuid, unknownCharaString));

                currentCharaData.put(LIST_UUID, uuid);
                gattCharacteristicGroupData.add(currentCharaData);

            }
            mGattCharacteristics.add(charas);

            gattCharacteristicData.add(gattCharacteristicGroupData);

        }
    }
krishnan muthiah pillai
  • 2,711
  • 2
  • 29
  • 35
  • So how do I know the device contains "heart" is a heart rate sensor? Is it set by the manufacturer of the device? Also, anything for iOS? thanks. – Jason Apr 22 '15 at 18:19
1

The above code won't work. You will have to scan the device, connect to it, and discover the services. A heart rate device has a specific service characteristic. Here is a link for that: https://developer.bluetooth.org/TechnologyOverview/Pages/HRP.aspx

check out this link of an answer I have that demonstates heart rate device: https://stackoverflow.com/a/29548205/862382

Community
  • 1
  • 1
Droid Chris
  • 3,455
  • 28
  • 31
1

Suppose if you want your app to connect only to Hear Rate monitoring devices, and if you have the liberty to connect and check, you should use the standard Heart Rate service implementation. But, suppose if you want to get it done without connecting to a BLE device, Appearance field in the advertisement packet should help you, provided that BLE Server developers have taken proper care to set the device appearance in the GAP service.

Appearance values 832 and 833 are for Generic Heart rate Sensor and Heart Rate Sensor: Heart Rate Belt.

That said, be assured that you will also have the capability to connect to custom devices that implement Heart Rate Service as a supplementary service with their primary application, only if the custom service has the GAP characteristics Appearance set to 833 or 832.

WedaPashi
  • 3,561
  • 26
  • 42