简体   繁体   中英

Android bluetooth get the heart rate measurement

I want to get the value of the HRM of an "A&D UA-651BLE" device. this is what's written in the datasheet of this device to get the HRM value:

  1. Set the application to pairing mode to start scanning.
  2. Start pairing of A&D BLE device following each instruction manual.
  3. At pairing mode, the application should set time and date and any other device settings to A&D BLE device. After successful pairing, A&D BLE device shows “End” on the screen.
  4. Take a measurement and finish the measurement, then A&D BLE device start BLE connection with advertising. The application starts scanning with suitable interval so that the application catches the advertising of A&D BLE device as soon as it can.
  5. At initial connection or pairing, the Application set “2” to CCCD (Client Characteristic Configuration Descriptor) so that A&D BLE device sends a measurement data with Indication.
  6. After A&D device recognizes to be set “2” to CCCD and to be synchronized time and date within 5 seconds after connected, send the data with Indication.
  7. If the timeout set CCCD and time and date is expired, A&D BLE device will not send data and store the data in memory. The stored data in A&D BLE device can send next successful connection.

this is my service code:

public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic,
                                              boolean enabled) {
        if (mBluetoothAdapter == null || mBluetoothGatt == null) {
            Log.w(TAG, "BluetoothAdapter not initialized");
            return;
        }

        mBluetoothGatt.setCharacteristicNotification(characteristic, enabled);

        // This is specific to Heart Rate Measurement.
        if (UUID_HEART_RATE_MEASUREMENT.equals(characteristic.getUuid())) {
            BluetoothGattDescriptor descriptor = characteristic.getDescriptor(
                    UUID.fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG));
            descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
            mBluetoothGatt.writeDescriptor(descriptor);
        }
    }

and this is the method that read data:

final byte[] data = characteristic.getValue();
            if (data != null && data.length > 0) {
                final StringBuilder stringBuilder = new StringBuilder(data.length);
                for(byte byteChar : data)
                    stringBuilder.append(String.format("%02X ", byteChar));
                Log.e("HRM value",stringBuilder.toString());
                dataComposition.put(characteristic.getUuid().toString(),stringBuilder.toString());
                intent.putExtra(EXTRA_DATA,dataComposition);
            }

the problem is that this code doesn't return any data !!

The Google Samples Codes doesn't contain the method of write and indicate . In your case, you must at first write the value of time, change the CCCD value to 2 and then the device will send you the value of HRM. to do that you can find in this repository the write and indicate method, you have just to integrate them in your code.

There's an Android Open Source Project example that does precisely this, easiest option would be to clone the android-BluetoothLeGatt code , build and compare it to your own. If you can't spot the difference / issue simply deploy both app's and step through both sets of code. Having some known working code will also help to rule out the possibility that the HRM is not functioning properly.

Do you have and example , i try this with equal device and i cant obtain the information y try with

public String response() {
if (mConnected) {
    mBluetoothLeService.readCharacteristic(characteristica);
    byte response[] = characteristica.getValue();
    String respuesta = ReadBytes(response);
    mBluetoothLeService.disconnect();
    return respuesta;
} else {
    return null;
}
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM