Mi Band 2 отключается после нажатия кнопки сердечного ритма - PullRequest
0 голосов
/ 06 мая 2019

Не могу сохранить соединение с Mi Band 2 в Android. Когда я пытаюсь получить пульс от Mi Band, он отключается. Соединение остается на несколько секунд.

Так я авторизовал Mi Band.

private void authoriseMiBand() {
        BluetoothGattService service = gatt.getService(UUIDs.CUSTOM_SERVICE_FEE1);

        BluetoothGattCharacteristic characteristic = service.getCharacteristic(UUIDs.CUSTOM_SERVICE_AUTH_CHARACTERISTIC);
        gatt.setCharacteristicNotification(characteristic, true);
        for (BluetoothGattDescriptor descriptor : characteristic.getDescriptors()) {
            if (descriptor.getUuid().equals(UUIDs.CUSTOM_SERVICE_AUTH_DESCRIPTOR)) {
                Log.d("INFO", "Found NOTIFICATION BluetoothGattDescriptor: " + descriptor.getUuid().toString());
                descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
            }
        }

        characteristic.setValue(new byte[]{0x01, 0x8, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45});
        gatt.writeCharacteristic(characteristic);
    }

И это то, что я делаю на кнопке GetHeartRate. Печально, что он отключается, когда я нажимаю на эту кнопку. В дополнение к этому он не получает HeartRate.

 private void getHeartRate() {
        BluetoothGattCharacteristic characteristic =
                gatt.getService(HEART_RATE_SERVICE_UUID)
                        .getCharacteristic(HEART_RATE_CONTROL_POINT_CHAR_UUID);
        characteristic.setValue(new byte[]{1, 1, 1});

        gatt.setCharacteristicNotification(characteristic, true);
        Log.i("Characteristic", "");
        //   BluetoothGattDescriptor descriptor = characteristic.getDescriptor(CLIENT_CHARACTERISTIC_CONFIG_UUID);
        Log.i("Descriptor", "");
        //   descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
        //  gatt.writeDescriptor(descriptor);

        gatt.writeCharacteristic(characteristic);
    }
...