2017-05-03 8 views
1

特性のBLEデバイス(パルソメーター)値は常に同じです。信号はonCharacteristicChangedに行きますが、値は変化しません。異なる方法で値を取得しようとしました。GATT特性値が変更されない

@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

+0

チェックこのHTTPS:/それが役に立つなら/github.com/devunwired/accessory-samples/blob/master/BluetoothGatt/src/com/example/bluetoothgatt/MainActivity.java – Raghunandan

答えて

0

決定:

@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 GET値 - SmartGattLib、およびすべての作業)

関連する問題