This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Android direct connection takes time after first error 133

Hello,

i'm developing an interface based on nrf52. The app does a direct connection, performs some exchanges with the peripheral, and tells the peripheral to disconnect.

On Android I only use direct connection because i need to connect as fast as i can, and i make disconnection from peripheral side by sending a command to nrf52.

This works as expected until i get the first error 133. After that, the direct connection starts taking seconds (up to 6 s) before i get OnConnectionStateChanged callback. A lot of times i also get error OnConnectionStateChanged with error 133 right after connectGatt command was issued, and even if Bluetooth is off.

Performing a background connection seems to "fix it" in some way, after that i can perform direct connection again with no errors, untill i get error 133 again.

Do you have any advise on that?

Thanks

UPDATE:

By direct connection i mean connectGatt with autoConnect = 0. I believe it is something related to the Android stack because i don't see any delay in the trace sniffed.

The trace always shows the CONNECT_REQ whitout any delay after, and the whole procedure (connect / authentication / data trasfert / disconnect) always takes around 3.5 seconds.

The delay i experience is always before the actual connection is made and is always between the call to connectGatt function and the receive of onConnectionStateChanged callback, as you can see here:

08-01 14:57:13.006 D/BluetoothGatt: connect() - device: CB:89:36:71:EC:32, auto: false
08-01 14:57:13.006 D/BluetoothGatt: registerApp()
08-01 14:57:13.006 D/BluetoothGatt: registerApp() - UUID=2f611549-ccb6-4478-b3f6-b94efa047519
08-01 14:57:13.046 D/BluetoothGatt: onClientRegistered() - status=0 clientIf=10
08-01 14:57:16.046 D/BluetoothUtils: getBtEnabledContainers(): btContainers = []
08-01 14:57:16.086 D/BluetoothUtils: getBtEnabledContainers(): btContainers = []
08-01 14:57:16.096 D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=10 device=CB:89:36:71:EC:32
Parents Reply
  • It's not only about time but also about frequency of advertisement and scanning parameters you use in Android API (as far as I know there are 3 or 4 levels in the latest release). What is the adv. interval of your peripheral? Is it using all 3 adv. channels on every interval or just rotates the channel and uses one at the time? And in the end how are you synchronizing the clock between sniffer and Android phone so you are sure how long it took to really issue CONNECT_REQ?

Children
No Data
Related