Skip to content

HeartRate BLE not correctly implemented and not fully exposed to Health interface #163

@ssandon

Description

@ssandon

On Polar H7 the HeartRate measurement doesn't works.

According to https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.heart_rate_measurement.xml
It seems that Energy and HeartRate are interverted.

Other issues is that Health Profile is not fully exposed (cannot request RR-interval for exemple).
Other things, battery should be exposed as service.

Following, code with correct bitmask.

private void notifyHeartRateMeasurement(final BluetoothGatt gatt,
            final BluetoothGattCharacteristic characteristic) {
        int heartRate = 0;
        int energyExpended = 0;
        double rrInterval = 0;
        int offset = 1;

        byte[] buf = characteristic.getValue();

        if (buf.length > 1) {
            // Heart Rate Value Format bit
            if ((buf[0] & 0x01) != 0) {
                Integer v = characteristic.getIntValue(FORMAT_UINT16, offset);
                if (v != null) {
                    heartRate = v;
                }
                offset += 2;
            } else {
                Integer v = characteristic.getIntValue(FORMAT_UINT8, offset);
                if (v != null) {
                    heartRate = v;
                }
                offset += 1;
            }

            // Sensor Contact Status bits
            if ((buf[0] & 0x06) != 0) {
                // MEMO: not implements yet
            }

            // Energy Expended Status bit
            if ((buf[0] & 0x08) != 0) {
                Integer v = characteristic.getIntValue(FORMAT_UINT16, offset);
                if (v != null) {
                    energyExpended = v;
                }
                offset += 2;
            }

            // RR-Interval bit
            Integer v = characteristic.getIntValue(FORMAT_UINT16, offset);
            if (v != null) {
                rrInterval = ((float) v / 1024.0) * 1000.0;
            }

        }

        mLogger.warning("@@@@@@ HEART RATE[" + heartRate + ", "
                + energyExpended + ", " + rrInterval + "]");

        BluetoothDevice device = gatt.getDevice();
        if (mListener != null) {
            mListener.onReceivedData(device, heartRate, energyExpended, rrInterval);
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions