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

A BLE_GAP_EVT_DISCONNECTED event has occurred after pairing with my phone. & I can not pair with Android app.

Hi.

I am using nRF52832 and SDK15, S132 Softdevice.

I integrated the uart example in the ble_peripheral folder with the buttonless_dfu example, and added the passkey.

The cell phone is Android.

I turned on Bluetooth on my phone and found the nRF52832 and registered the device on my phone by entering the 6 digit PIN.

However, soon  BLE_GAP_EVT_DISCONNECT event happened. After 180 seconds,  BLE_ADV_EVT_IDLE event happened and then bluetooth advertising end.

Pairing seems to have not been successful.

Through the terminal, you can see the following message.

Connected to a previously bonded device.
Connected
Data len is set to 0xF4(244)
ATT MTU exchange completed. central 0xf7 peripheral 0xf7
ATT MTU exchange completed. central 0xf7 peripheral 0xf7

(Enter 6-digit PIN.)
Connection secured: role: 1, conn_handle: 0x0, procedure: 1.
Disconnected, reason: 0x13
timeout

1) What can I do to keep my pairing going? => I saw that it could be a cache issue. What is cache?

If use the "nRF Connect"  app, the connection will not be disconnected.

However, other Bluetooth apps on Android do not pair( For example, the Bluetooth chat application ). Can you tell me why?

 

Also, my ultimate goal is to implement the device so that it is automatically paired even if the device is turned on or off.

2) How do I keep my pairing automatically?

Thanks in advance for your help.

Parents
  • Hello,

     

    Regarding the BLE_GAP_EVT_DISCONNECT event, 180 seconds, and BLE_ADV_EVT_IDLE sequence, this is expected, as most of our examples have 180 seconds advertising timeout. If it isn't connected within this time, it will go to system off mode, to save power. It is possible to disable this, if you want to, so that the device will keep advertising.

     

    Disconnection reason 0x13 is BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION (see the file ble_hci.h in the SDK). 

    It sounds like one of your devices (either phone or nRF) has stored the bonding information, while the other has not. Can you try to delete the bonding information on both of your devices? On the phone, this is usually done in the bluetooth settings. On the nRF, since you might haven't added the delete bond functionality in your application yet, the easiest way is to erase the DK/chip, reprogram the softdevice and your application, and try to bond again. If it succeeds, you can turn on and off your phone and nRF, and they should remember the bonding information.

     

    Bonding is an optional step. You can read a short description on connection, pairing, bonding and whitelisting here.

     

    If you are interrested, you can try the ble_app_hids_keyboard example from the SDK:

    SDK\examples\ble_peripheral\ble_app_hids_keyboard\...

    which will reconnect automatically after a power cycle on the nRF.

     

    Best regards,

    Edvin

  • Hi.

    I want to get rid of the 180 second ad timeout.

    So I made the following changes.

    static void on_adv_evt(ble_adv_evt_t ble_adv_evt)
    {
        uint32_t err_code;
    
        switch (ble_adv_evt)
        {
            case BLE_ADV_EVT_FAST:
                err_code = bsp_indication_set(BSP_INDICATE_ADVERTISING);
                APP_ERROR_CHECK(err_code);
                break;
            case BLE_ADV_EVT_IDLE: 
                //sleep_mode_enter();
                break;
            default:
                break;
        }
    }

    However, after 180 seconds, nRF52832 will not enter sleep mode, but your ads will end.

    What should I do to keep my ads going?

    Thank you.

  • Hello,

    The advertisement timeout is what triggers the BLE_ADV_EVT_IDLE event, and not the other way around. So the advertisement will time out even though you remove sleep_mode_enter();

     

    If you want to keep advertising "forever", you must do the two following steps:

    Near the top of main.c, you will find the "#define APP_ADV_DURATION 18000". Change this to "#define APP_ADV_DURATION 0"

    Next, in advertising_init() in main.c, you must change the advdata flag:

    init.advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE;

    to

    init.advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;

     

    Then it should not stop advertising.

     

    Best regards,

    Edvin

Reply
  • Hello,

    The advertisement timeout is what triggers the BLE_ADV_EVT_IDLE event, and not the other way around. So the advertisement will time out even though you remove sleep_mode_enter();

     

    If you want to keep advertising "forever", you must do the two following steps:

    Near the top of main.c, you will find the "#define APP_ADV_DURATION 18000". Change this to "#define APP_ADV_DURATION 0"

    Next, in advertising_init() in main.c, you must change the advdata flag:

    init.advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE;

    to

    init.advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;

     

    Then it should not stop advertising.

     

    Best regards,

    Edvin

Children
No Data
Related