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
  • I mean any log o Android;) If you are really interested where exactly your flow spend what time you need to see what happens in the air on 2.4GHz radio, the only truth is out there...

  • Peripheral advertising time is 21.875 ms for all 3 channels, while Android is scanning with SCAN_MODE_LOW_LATENCY. Scan is always in background, it's stopped before performing connection and retrieved after disconnection. I can't get Wireshark to print epoch, so i place log and sniffer close together. Because some times it takes really long to connect, it can be easily seen that the delay is before the sniffer captures the CONNECT_REQ. With Android log, by comparing the time between connect() and onClientConnectionState it can be seen that in normal condition connection takes ~400ms. When it's delayed, it takes ~3000ms

Reply
  • Peripheral advertising time is 21.875 ms for all 3 channels, while Android is scanning with SCAN_MODE_LOW_LATENCY. Scan is always in background, it's stopped before performing connection and retrieved after disconnection. I can't get Wireshark to print epoch, so i place log and sniffer close together. Because some times it takes really long to connect, it can be easily seen that the delay is before the sniffer captures the CONNECT_REQ. With Android log, by comparing the time between connect() and onClientConnectionState it can be seen that in normal condition connection takes ~400ms. When it's delayed, it takes ~3000ms

Children
No Data
Related