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

How to force bonding?

-SDK: 15.0

-S132

-nRF52832

-Segger studio

I'm trying to implement bonding/whitelisting to my project, which is a connectable beacon with a custom service. What I want to create is that when the first device connects to my device it can be whitelisted with a single button press. After that, the device should ignore all other connection requests from other devices, unless the whitelisting is reset with another button press.

I've found this previous thread, which is not to old:

https://devzone.nordicsemi.com/f/nordic-q-a/36308/peer-manager-event-dispacthing---nrf52832-sdk-15-0-0/141375#141375

This describes the same issue I've got: the peermanager is never called and thus whitelisting is never done. In the previous thread the solution is to set a characteristic to require bonding. But how can this be done? How do I set the characteristic or attributes to require bonding?

I've used the ble_peripheral\ble_app_hids_keyboard example to implement whitelisting in my project, but without the peermanager being called whitelisting does not work.I've tried to run the ble_app_hids_keyboard example, but when I connect with nRF Connect on my smartphone (Samsung S5) the peermanager isn't called either.

Should I use a different client application instead of nRF Connect, is there a different method for whitelisting available or is there something else that I need to change?

  • Thank you for your response,

    Finaly found the error after concluding that the PM_EVT_PEER_DATA_UPDATE_SUCCEEDED event was working as intended. I had two advertising_init functions: advertising_init and advertising_beacon_init. I was using the latter.  advertising_init  was from when this application wasn't an iBeacon. After adding init.config.ble_adv_whitelist_enabled = true; to advertising_beacon_init, whitelisting worked.

    Your sugesstion of changing the beacon to unconnectable upon connecting is appealing, but I can't find the parameter I need to change from connectable to unconnectable and vice versa.

    From what I found and understood, I must change the connection configuration tag with the ble_advertising_conn_cfg_tag_set()  function (currently ble_advertising_conn_cfg_tag_set(&m_advertising, APP_BLE_CONN_CFG_TAG); ), but I can't find the sd_ble_cfg_set in the online documentation. Would you mind pointing me to the correct file for the right value?

    Thank you kindly in advance and for the previous support messages!

  • Hello,

    Depending on how the advertising is set up, this is done in different places in different examples.

    in the examples\ble_peripheral\ble_app_beacon, on line 190 (if not modified), it says:

    m_adv_params.properties.type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED;

    meaning that it is not possible to connect to this device. In this example it is in advertising_init.

    I see that this option is handled in ble_advertising.c in most other examples.

    BR,

    Edvin

  • I'm building a connectable beacon, so I'm using the advertising module:

    BLE_ADVERTISING_DEF(m_advertising);                                 /**< Advertising module instance. */

    I've already found some old posts where it was said that for non-connectable advertising the advertising module should not be used:

    https://devzone.nordicsemi.com/f/nordic-q-a/14195/non-connectable-advertisement-while-scanning-as-a-central

    I tried changing BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED to BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED as a quick test, but that didn't work

    Snippet from ble_advertising.c function:ble_advertising_init()
    p_advertising->adv_params.properties.type = BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED;

    Has this changed since that post or is the advertising module still connectable-only?

  • It seems you are correct. I see that the BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED is set in ble_advertising_start() at least one time, or even twice if you use adv_mode_fast.

    You can look at our beacon example, examples\ble_peripheral\ble_app_beacon. If you set up a separate advertisement like it is done there. Note that you can only advertise with one advertising set at a point in time.

    By the way, I forgot to tell you that sd_ble_cfg_set() in the file ble.h, line 396 - 430. Alternatively, it is also documented here on infocenter.

    Best regards,

    Edvin

Related