Подтвердить что ты не робот

Измерение сердечного ритма с использованием Xiaomi MiBand и BLE

Я пытаюсь реализовать простой sdk для работы с фитнес-трекером Xiaomi Mi Band. В настоящее время я могу отслеживать шаги, приводить в действие вибрацию, обрабатывать сенсорный сенсор, но у меня проблема с измерением частоты сердечных сокращений. Мой sdk основан на https://github.com/pangliang/miband-sdk-android. Чтобы измерить частоту сердечных сокращений, мне нужно написать дескриптор к соответствующему признаку, чтобы включить обработку обратного вызова, когда значение этого признака было изменено, а затем записать соответствующие данные в контрольную точку сердечного ритма, чтобы непосредственно начать процесс измерения сердечного ритма. Проблема заключается в том, что процесс измерения сердечного ритма не начинался после того, как данные для инициирования этого процесса были успешно записаны на характеристику (когда Mi Band начинает измерять частоту сердечных сокращений, а нижний датчик мигает зеленым цветом). Это может быть вызвано новой прошивкой фитнес-трекера (версия прошивки: 4.15.12.10; версия HeartRate: 1.3.74.64) или некоторые недостатки в моем коде:

/-------- MiBandProfile --------/
public static final UUID UUID_SERVICE_HEARTRATE = UUID.fromString("0000180d-0000-1000-8000-00805f9b34fb");
public static final UUID UUID_NOTIFICATION_HEARTRATE = UUID.fromString("00002a37-0000-1000-8000-00805f9b34fb");
public static final UUID UUID_CHAR_HEARTRATE = UUID.fromString("00002a39-0000-1000-8000-00805f9b34fb");
public static final UUID UUID_DESCRIPTOR_UPDATE_NOTIFICATION = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");

/-------- MiBandProtocol --------/
public static final byte[] START_HEART_RATE_SCAN = {21, 1, 1};

/-------- BleProvider --------/
public class BleProvider extends BluetoothGattCallback {

public interface NotifyListener {
     void onNotify(byte[] data);
}

private HashMap<UUID, NotifyListener> mNotifyListeners = new HashMap<UUID, NotifyListener>();
.
.
.
public void setNotifyListener(UUID serviceUUID, UUID charaUUID, NotifyListener listener) {
        //enable chara notofication
        if (this.mGatt == null || !this.mIsServicesDiscovered) {
            if (DBG) Log.d(Debug.TAG, "Device is not connected or services are not discovered");
            return;
        }

        BluetoothGattCharacteristic chara = this.mGatt.getService(serviceUUID).getCharacteristic(charaUUID);

        if (DBG) Log.d(Debug.TAG, "setCharacteristicNotification: " + this.mGatt.setCharacteristicNotification(chara, true));
        BluetoothGattDescriptor descriptor = chara.getDescriptor(MiBandProfile.UUID_DESCRIPTOR_UPDATE_NOTIFICATION);
        if (DBG) Log.d(Debug.TAG, "setValue: " + descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE));
        if (DBG) Log.d(Debug.TAG, "writeDescriptor: " + this.mGatt.writeDescriptor(descriptor));
        this.mNotifyListeners.put(charaUUID, listener);
}

@Override
public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
        //this method must be called when the characteristic value was changed but nothing happened :(
        super.onCharacteristicChanged(gatt, characteristic);

        if (this.mNotifyListeners.containsKey(characteristic.getUuid())) {
            this.mNotifyListeners.get(characteristic.getUuid()).onNotify(characteristic.getValue());
        }
}
} //end BleProvider

.
.
.

setNotifyListener(MiBandProfile.UUID_SERVICE_HEARTRATE, MiBandProfile.UUID_NOTIFICATION_HEARTRATE, new BleProvider.NotifyListener(){...});
//waiting few seconds
writeCharacteristic(MiBandProfile.UUID_SERVICE_HEARTRATE, MiBandProfile.UUID_CHAR_HEARTRATE, MiBandProtocol.START_HEART_RATE_SCAN);

Возможно, протокол устарел, и есть люди, которые могут поделиться мне новым протоколом. Я буду очень рад) Спасибо.

4b9b3361

Ответ 1

Я решил проблему! Перед вызовом setNotifyListener для отслеживания изменения значения импульса вам необходимо записать информацию о пользователе (возраст, вес) в соответствующую характеристику, потому что без этого Mi Band не начнет измерение.

Ответ 2

Im работает с BLE A & D, чтобы использовать iformation i:

Чтобы найти UUID

  @SuppressLint("NewApi")
private void displayGattServicesService(List<BluetoothGattService> gattServices) {
    //  salida.append("Buscando servicio");
    if (gattServices == null)
        return;
    for (BluetoothGattService gattService : gattServices) {

        String uuid = gattService.getUuid().toString();

        List<BluetoothGattCharacteristic> gattCharacteristics = gattService
                .getCharacteristics();
        if (uuid.equals("00001810-0000-1000-8000-00805f9b34fb")) {
            //  salida.append("Ecnontro");
            for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) {
                String uuid1 = gattCharacteristic.getUuid().toString();
                if (uuid1.equals("00002a35-0000-1000-8000-00805f9b34fb")) {
                    //     salida.append("Envio caracterisitca");
                    mensaje(getResources().getString(R.string.Espere_res));
                    mBluetoothLeService.setCharacteristicNotification(
                            gattCharacteristic, true);
                }
            }
        }
    }
}

Чтобы установить UUID

BluetoothLeService.ACTION_GATT_SERVICES_DISCOVERED.equals(action)) {

            // Show all the supported services and characteristics on the user interface.
            displayGattServicesService(mBluetoothLeService.getSupportedGattServices());

Используйте пример BleGatt https://github.com/googlesamples/android-BluetoothLeGatt