I have 6 characteristics on my device. One of them needs notification to send data. I register characteristics like this :
private void registerEnvironmentCharacteristics(List<BluetoothGattCharacteristic> characteristics) {
for (BluetoothGattCharacteristic characteristic : characteristics) {
UUID characteristicUuid = characteristic.getUuid();
if (Characteristics.TEMPERATURE_CHARACTERISTIC_UUID.equals(characteristicUuid))
temperatureCharacteristic = characteristic;
flipNotifications(temperatureCharacteristic,true);
}
}
This is my flip method to setCharacteristicNotification :
private void flipNotifications(BluetoothGattCharacteristic characteristic, boolean enable) {
boolean notifications = bluetoothGatt.setCharacteristicNotification(characteristic, enable);
BluetoothGattDescriptor descriptor = characteristic.getDescriptor(Characteristics.CONFIGURATION_DESCRIPTOR_UUID);
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
bluetoothGatt.writeDescriptor(descriptor);
BluetoothCommunicationManager.getInstance().add(new DescriptorCommand(descriptor, bluetoothGatt, enable ? BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE : BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE));
}
When I delete flipNotification() method from registerEnvironment I've go 5 characteristics from device (without this one with notification) but when I add flipNotification I'm getting null on all characteristics. Any idea what am I doing wrong ? This is my wrtiting method :
public void readTemperature() {
BluetoothCommunicationManager.getInstance().add(new WriteCharacteristicCommand(temperatureCharacteristic, bluetoothGatt, SINGLE_READ_COMMAND));
}
Thanks in advance for every help!