首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GATT特性不更改值

GATT特性不更改值
EN

Stack Overflow用户
提问于 2017-05-03 15:02:49
回答 1查看 627关注 0票数 0

BLE设备(脉搏计)的特性值总是相同的。信号转到onCharacteristicChanged,但值不变,尝试以不同的方式获取值。

代码语言:javascript
复制
@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

EN

回答 1

Stack Overflow用户

发布于 2017-05-03 17:21:01

决定:

代码语言:javascript
复制
@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、更改UUIDs (it can be found)和lib获取值- SmartGattLib,并且全部正常工作)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43753269

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档