【问题标题】:GATT characteristic not change valueGATT 特性不改变值
【发布时间】:2017-05-03 07:02:49
【问题描述】:

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

【问题讨论】:

标签: java android bluetooth bluetooth-lowenergy gatt


【解决方案1】:

决定:

@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,所有工作都正常

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多