diff --git a/iot_wireless_communication/src/main/java/inc/osips/iot_wireless_communication/wireless_comms_module/remote_comms/ble_comms/BleConnection.java b/iot_wireless_communication/src/main/java/inc/osips/iot_wireless_communication/wireless_comms_module/remote_comms/ble_comms/BleConnection.java index 0b06a8f..e655501 100644 --- a/iot_wireless_communication/src/main/java/inc/osips/iot_wireless_communication/wireless_comms_module/remote_comms/ble_comms/BleConnection.java +++ b/iot_wireless_communication/src/main/java/inc/osips/iot_wireless_communication/wireless_comms_module/remote_comms/ble_comms/BleConnection.java @@ -62,7 +62,7 @@ public void disableNotificationsFor(String serviceUuid, String attrId, } @Override - public void connectToDeviceWithDeviceInfoFrom(Intent intent) { + public void connectToDeviceWithDeviceInfoFrom(@NonNull Intent intent) { } @Override diff --git a/iot_wireless_communication/src/main/java/inc/osips/iot_wireless_communication/wireless_comms_module/remote_comms/ble_comms/services/BleGattService.java b/iot_wireless_communication/src/main/java/inc/osips/iot_wireless_communication/wireless_comms_module/remote_comms/ble_comms/services/BleGattService.java index b926b7b..26ad5dd 100755 --- a/iot_wireless_communication/src/main/java/inc/osips/iot_wireless_communication/wireless_comms_module/remote_comms/ble_comms/services/BleGattService.java +++ b/iot_wireless_communication/src/main/java/inc/osips/iot_wireless_communication/wireless_comms_module/remote_comms/ble_comms/services/BleGattService.java @@ -781,21 +781,22 @@ public void writeToDescriptorToEnableIndicator(String serviceUUID, String charxU if (setCharacteristicNotification(gatt, charx, false)) { BluetoothGattDescriptor descriptor = charx.getDescriptor( UUID.fromString(CCC_DESCRIPTOR_UUID)); - descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE); - - Queue BleWriteQueue = writeQueueMap.get(deviceAddress); - Objects.requireNonNull(BleWriteQueue).add(descriptor); - writeQueueMap.put(deviceAddress, BleWriteQueue); - if(BleWriteQueue.size()==1) - Log.d(TAG, "writeToDescriptorToEnableNotifications: ->" - +gatt.writeDescriptor(descriptor)); + if(descriptor!=null) { + descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE); + + Queue BleWriteQueue = writeQueueMap.get(deviceAddress); + Objects.requireNonNull(BleWriteQueue).add(descriptor); + writeQueueMap.put(deviceAddress, BleWriteQueue); + if (BleWriteQueue.size() == 1) + Log.d(TAG, "writeToDescriptorToEnableNotifications: ->" + + gatt.writeDescriptor(descriptor)); + } } } private void writeToDescriptorToEnableNotifications(BluetoothGattCharacteristic characteristic, BluetoothGatt gatt){ if (setCharacteristicNotification(gatt, characteristic, true)) { - UUID descUuid = UUID.fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG); - BluetoothGattDescriptor descriptor = characteristic.getDescriptor(descUuid); + BluetoothGattDescriptor descriptor = characteristic.getDescriptors().get(0); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); String deviceAddress = gatt.getDevice().getAddress(); @@ -810,8 +811,7 @@ private void writeToDescriptorToEnableNotifications(BluetoothGattCharacteristic private void writeToDescriptorToEnableIndicator(BluetoothGattCharacteristic characteristic, BluetoothGatt gatt){ if (setCharacteristicNotification(gatt, characteristic, true)) { - UUID descUuid = UUID.fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG); - BluetoothGattDescriptor descriptor = characteristic.getDescriptor(descUuid); + BluetoothGattDescriptor descriptor = characteristic.getDescriptors().get(0); descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE); String deviceAddress = gatt.getDevice().getAddress(); @@ -835,13 +835,15 @@ public void writeToDescriptorToDisableNotifications(String serviceUUID, String c BluetoothGattDescriptor descriptor = charx.getDescriptor( UUID.fromString(CCC_DESCRIPTOR_UUID)); - descriptor.setValue(BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE); - Queue BleWriteQueue = writeQueueMap.get(deviceAddress); - Objects.requireNonNull(BleWriteQueue).add(descriptor); - writeQueueMap.put(deviceAddress, BleWriteQueue); - if(BleWriteQueue.size()==1) - Log.d(TAG, "writeToDescriptorToDisableNotifications: " - +gatt.writeDescriptor(descriptor)); + if(descriptor!=null) { + descriptor.setValue(BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE); + Queue BleWriteQueue = writeQueueMap.get(deviceAddress); + Objects.requireNonNull(BleWriteQueue).add(descriptor); + writeQueueMap.put(deviceAddress, BleWriteQueue); + if (BleWriteQueue.size() == 1) + Log.d(TAG, "writeToDescriptorToDisableNotifications: " + + gatt.writeDescriptor(descriptor)); + } } }