gpt4 book ai didi

java - GATT 特性不改变值

转载 作者:太空宇宙 更新时间:2023-11-04 11:31:20 26 4
gpt4 key购买 nike

BLE 设备(脉搏计)的特性值始终相同。信号转到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

最佳答案

决定:

@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);
}

这个Helped,更改 UUID(it can be found),lib 获取值 - SmartGattLib,并且所有工作)

关于java - GATT 特性不改变值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43753269/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com