简体   繁体   English

GATT特征没有改变价值

[英]GATT characteristic not change value

BLE device (pulsometer) value in characteristic always the same. BLE装置(脉冲计)的特性值始终相同。 The signal goes to onCharacteristicChanged but the value does not change, tried to get the value in different ways. 信号转到onCharacteristicChanged但值不会改变,试图以不同的方式获取值。

@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
super.onServicesDiscovered(gatt, status);
    BluetoothGattCharacteristic characteristic3 = gatt.getService(UUID.fromString("0000180f-0000-1000-8000-00805f9b34fb"))
                    .getCharacteristic(UUID.fromString("00002a19-0000-1000-8000-00805f9b34fb"));
    gatt.setCharacteristicNotification(characteristic3, true);
    gatt.readCharacteristic(characteristic3);
}

@Override
public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
    super.onCharacteristicRead(gatt, characteristic, status);
    UUID uuid = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");
    BluetoothGattDescriptor descriptor = characteristic.getDescriptor(uuid);
    descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
    gatt.writeDescriptor(descriptor);
}

@Override
public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
    super.onCharacteristicChanged(gatt, characteristic);
    Log.e(TAG, "pulse: " + characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0));
}

logcat logcat的

Decision: 决定:

@Override
    public void onServicesDiscovered(BluetoothGatt gatt, int status) {
    super.onServicesDiscovered(gatt, status);

    BluetoothGattCharacteristic characteristic2 = gatt.getService(UUID.fromString("0000180d-0000-1000-8000-00805f9b34fb"))
                    .getCharacteristic(UUID.fromString("00002a37-0000-1000-8000-00805f9b34fb"));

    gatt.setCharacteristicNotification(characteristic2, true);

    // 1 !!!!!!
    UUID uuid = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");
    BluetoothGattDescriptor descriptor = characteristic2.getDescriptor(uuid);
    descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
    gatt.writeDescriptor(descriptor);

    // 2 !!!!!!
    gatt.readCharacteristic(characteristic2);
}

This Helped , change UUIDs ( it can be found ), and lib get value - SmartGattLib, and all working ) 这个Helped ,更改UUID( 可以找到 ),lib获取值 - SmartGattLib,以及所有工作)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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