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

Unable to connect to bonded device on Android

Hi, I have a problem with BLE connection. When I bond to the device and then connect, everything works and connection is stable. When I kill the app and try to connect again to the bonded device, I get disconnected from the Android with status code 22(connection terminated by localhost).

Do you know the difference of these scenarios under the Android hood? I can't figure out why does this keep happening when the phone is obviously able to connect to the device after the bonding procedure.

For connection I use the standard code used in the Android examples, there is no magic going on.

Thanks a lot for your help.

  • Well, I'll be able to try day after tomorrow so I'll let you know. The weird thing is that iOS never disconnects from the peripheral, only Android so I'm not sure if this can be the case. I'm thinking whether iOS doesn't have some better handling of this case since it stays connected. Thanks again for your tips..

  • Well, we've tried to change the FW on peripheral side but no success, no matter which parameter value we put in the peripheral, I'm still getting connection update with interval 6. I started to wonder whether this couldn't be coming from the phone but it shouldn't make sense since this value isn't supported by the system. Do you think that it's possible that it's coming from the phone?

  • It does come from the Android system. After successful bonding Android repeats service discovery. To make it faster they change connection interval to 7.5ms, but just for the discover. When it's done a new connection param update will come with higher value.

  • Oh, I see, but it's still weird since when I connect right after the bonding, I can sometimes see a couple of connection updates with interval value set to 36 and it works. When I kill the app, or disconnect from the peripheral and try to connect again, I can only see one connection update with interval value set to 6 followed by disconnect. Could you please point me to the place where you found this info about the 7.5ms interval for discovery? Maybe I can find some more there. And thank you once again for helping me here, I'm starting to be desperate.

  • If you have a phone with Android 8+ in nRF Connect you'll see the connection parameter updates. Before service discovery there is an update with 7.5 ms, and after discovery some more updates with higher values (depending on the app). Looks like the security fails in your case, or service discovery. It sets interval to 7.5ms, starts discovery/resuming security and fails, and disconnects.

Related