1

I have an issue regarding Android BLE. It is the following: This issue occurs on Samsung Galaxy S10e, Android 10, OneUI 2.5. It comes up when the Smartphone is connected to some Wifi. If the Smartphone is connected to Wifi, onCharacteristic Changed is not called. If Wifi is turned off, everything works as expected and onCharacteristicChanged is called. It was also tested on a Google Pixel 3XL. With this smartphone everything works as expected, no matter if connected to Wifi or not. This seems to occur since the new OneUI Version 2.5. It worked as expected on OneUI 2.1. SetCharacteristicNotification on BluetoothGatt and writeDescriptor work fine and writeDescriptor(descriptor) returns true. So I don't think there is something wrong about this code, since it works as intended when Wifi is turned off. Just for the case, here my code for enabling notifications on Android BLE:

val CHARACTERISTIC_UPDATE_NOTIFICATION_DESCRIPTOR_UUID = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");
characteristic?.writeType = BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE
bg?.setCharacteristicNotification(characteristic, true)
val descriptor = characteristic?.getDescriptor(CHARACTERISTIC_UPDATE_NOTIFICATION_DESCRIPTOR_UUID)
descriptor?.value = if (enabled) BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE else byteArrayOf(0x00, 0x00)
descriptor?.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE)
bg?.writeDescriptor(descriptor) ?: false

I already tried it without the line descriptor?.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE). It doesn't change anything. Is there something I am missing? Why could a Wifi connection block onCharacteristicChanged? If the Smartphone has turned on Wifi and is NOT connected, then it works. It only doesn't work when Wifi is turned on and IS connected.

writeCharacterstic and readCharacterstic are working fine and the callbacks trigger, no matter if Wifi is connected or not. So the BluetoothGattCallback is set just fine.

Can someone help me out here? Thanks!

Best, Markus

Markus
  • 31
  • 2
  • Are you shure you always write descriptor after device connected? You can check result of `writeDescriptor` operation in `onDescriptorWrite()` method in `BluetoothGattCallback`. I think you device may be not connected yet when you write descriptor, and because of it notifications are not enabling. – Sergey Melnik Dec 07 '20 at 15:40
  • Thanks for the response Sergey. I can check your suggestion, but if this is the case and I'm not connected yet to the device, the line `bg?.writeDescriptor(descriptor) ?: false` should return false, right? It does return true. Also, I only start this operation when a certain service and a certain characteristic is discovered. I only start looking for services when the device is connected. So the logical order should be alright... Connecting -> Connected -> Discover Services -> Get Characterstic -> Characteristic found -> Enable Notification – Markus Dec 09 '20 at 08:16
  • I checked the result of onDescriptorWrite(): It gets called and the status is GATT_SUCCESS ( = 0). So it seems this is correct. Still not getting onCharacteristicChanged called when Wifi is turned on. – Markus Dec 09 '20 at 09:26
  • @Markus Did you find solution? I am facing the same problem. – Shreeya Chhatrala Jun 25 '22 at 18:16
  • We have the same issue where the Samsungs with old firmware soft-brick the BLE device and thus the device requires a power cycle. We are looking for a workaround so that people with old phones stop messing up the product for others. – Karatekid430 Feb 28 '23 at 00:50

0 Answers0