Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Reconnecting to a already bonded device sometimes does not work

Hello,
I have a strange problem and I am not sure how to approach it.

The problem is that the connection sometimes does not get established. This issue appears on Android phones. The bonding in beforehand works fine and most of the time the reconnect works good as well. But sometimes nothing happens. On first sight the peripheral and the phone does not react when both get activated. There is no error in the peripherals logs (I output messages on pretty much all adv, pm and peer events). And here comes the strange part. If you check in the phones bluetooth settings, the peripheral is just gone. If you turn bluetooth off and on again, the peripheral appears again and the connection gets established.
I have not seen this behavior on iPhones or Windows.
I have tested on different Android phone brands and versions (6,7,8,9,10). On some it appears regularly on others it doesn't appear at all. I could not see any pattern.

I am developing the peripheral based on the ble_app_hids_keyboard example.
The chip is a ublox ANNA-B112, which is a nRF52832; using SES and SDK17.0.2 and softdevice 7.2.0
I am using a public address for the ublox chip.

I am using whitelist with a limit of 1 so only one device can be used with the peripheral. A function to delete all bonds is implemented to be able to bond with another device if needed.
The settings I use are:

#define APP_BLE_OBSERVER_PRIO               3                               
#define APP_BLE_CONN_CFG_TAG                1                               

#define APP_ADV_FAST_INTERVAL               32					
#define APP_ADV_SLOW_INTERVAL               1216                            

#define APP_ADV_FAST_DURATION               3000                            
#define APP_ADV_SLOW_DURATION               18000                           

#define MIN_CONN_INTERVAL                   MSEC_TO_UNITS(15, UNIT_1_25_MS)	
#define MAX_CONN_INTERVAL                   MSEC_TO_UNITS(45, UNIT_1_25_MS)	
#define SLAVE_LATENCY                       8					
#define CONN_SUP_TIMEOUT                    MSEC_TO_UNITS(2000, UNIT_10_MS)	

#define FIRST_CONN_PARAMS_UPDATE_DELAY      APP_TIMER_TICKS(5000)           
#define NEXT_CONN_PARAMS_UPDATE_DELAY       APP_TIMER_TICKS(30000)          
#define MAX_CONN_PARAMS_UPDATE_COUNT        3                               

#define SEC_PARAM_BOND                      1                               
#define SEC_PARAM_MITM                      0                               
#define SEC_PARAM_LESC                      0                               
#define SEC_PARAM_KEYPRESS                  0                               
#define SEC_PARAM_IO_CAPABILITIES           BLE_GAP_IO_CAPS_NONE            
#define SEC_PARAM_OOB                       0                               
#define SEC_PARAM_MIN_KEY_SIZE              7                               
#define SEC_PARAM_MAX_KEY_SIZE              16                              

The security settings for the services are SEC_JUST_WORKS

I have trouble reproducing this error. It just occurs. Sometimes on the next reconnect, sometimes on the next day.

But I managed to capture the occurence with a sniffer. The first picture is where the connection worked fine:

I cut off the picture but the master continues exploring the services and characteristics and so on. After that I turned my peripheral off (using BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION) and turned it on again and this is everything that happens:

After a few seconds the peripheral disconnects and starts advertising again.

Does anyone have a clue what is going on here? 

Parents
  • Hi.

    Sorry about the delayed response here.

    When you are trying to reconnect the peripheral, you haven't erased any bonding information on either the phone or the nRF? You are just trying to reconnect?

    Br,
    Joakim

  • Hi Joakim,

    thanks for responding! No, nothing has been erased. If I deactivate and activate the bluetooth on the phone, the connection gets established again right away. Is there something that the android phones don't like? I disconnect the previous connection with the peripheral with BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION. I also see the disconnect with the sniffer.

    Alex

  • As deactivating and activating BT on the phone seems to fix it, it does lead me to think that there is something on the Phone/Android side.

    You mention that on some phone this happens regularly and on some it doesn't happen at all.
    Could you list any Phone models / Android versions where this happens regularly? So that I might be able to test this, or do some research if this is a known problem.

    Br,
    Joakim

  • My client has a Samsung Galaxy A40 with Android 9 where it happens regularly. He has other peripherals installed which get connected from time to time (headphones for example). 

    I have a Galaxy S7 with Android 8 here as well as a Xiaomi Redmi 9 with Android 10 where it happens quite rarely. 

    I also have an old Galaxy S3 with Android 7 (LineageOS) where I haven't experienced this error yet.

    Like I said, I have trouble forcing this error. I think I had it happen more often when I flash my chip over and over again with the same firmware and check on the smartphone if the connection was successful after each flashing. But I doubt that this is a good test. I would love to give you any more hints but I am quite clueless here.

    I mean the fact that the peripheral gets deleted from the connected devices in the bluetooth menu and appears again after restarting bluetooth .. i think there must be something really wrong.

Reply
  • My client has a Samsung Galaxy A40 with Android 9 where it happens regularly. He has other peripherals installed which get connected from time to time (headphones for example). 

    I have a Galaxy S7 with Android 8 here as well as a Xiaomi Redmi 9 with Android 10 where it happens quite rarely. 

    I also have an old Galaxy S3 with Android 7 (LineageOS) where I haven't experienced this error yet.

    Like I said, I have trouble forcing this error. I think I had it happen more often when I flash my chip over and over again with the same firmware and check on the smartphone if the connection was successful after each flashing. But I doubt that this is a good test. I would love to give you any more hints but I am quite clueless here.

    I mean the fact that the peripheral gets deleted from the connected devices in the bluetooth menu and appears again after restarting bluetooth .. i think there must be something really wrong.

Children
Related