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

Can I bond master when conected?

In the example of hid_mouse, ble device will bond master when disconnect event happen.

I try to add this two codes to Implement my idea.

            err_code = ble_bondmngr_bonded_masters_store();
            APP_ERROR_CHECK(err_code);

But when I did this error appears

error:-559038737 ...line:783 file_name:src\ll_lm.s0.c

It must be some info lack to save when ble device bond the master.

Before func "ble_bondmngr_bonded_masters_store()" runs, what should I get from master?

Or when can I bond master (before disconnect happen)?

Best wishes!

  • Lets start with the first statement:

    In the example of hid_mouse, ble device will bond master when disconnect event happen.

    This is slightly wrong. It bonds as soon as it is connected. It stores the bond data in non-volatile flash memory on disconnect. The reason for this is that flash write (and especially erase) takes a lot of time and blocks the CPU. So if the link is running the flash operation will delay time-critical interrupts in the stack causing the link to drop.

    But when I did this error appears

    error:-559038737 ...line:783 file_name:src\ll_lm.s0.c

    That is what has happened here. This is actually an assert in the stack because it was not given time to handle a time critical task.

    What version of the SDK are you running? In older version it was only possible to store this bond information when there was no connection. But this has changed recently and it should no longer be a limitation.

    Or when can I bond master (before disconnect happen)?

    It's usually the master (central) who initiates the bonding sequence, but the slave can request the master to do this. There are not a lot of SDK examples of how to do this, but the softdevice call to use are:

    sd_ble_gap_authenticate

    Look it up. Should be fairly simple to use.

  • Thank you very much!

    SDK : nrf51_sdk_v4_4_2_33551 Softdevice: s110_nrf51822_5.2.1

    My chip is too old to run latest SDK v5.x and SD v6.x

    I just want to save white list info to non-volatile flash memory when I am connected to master, it seems impossible to do this in older version of SDK. I don't know whether can my version of SDK can do this or not.

    When I connect to the master at the first time, I should disconnect it to save whitelist info to connect auto to this master.

    If not do this , some issue comes:

    1. I can't connect auto to win8 PC
    2. I can connect auto to win8.1 but media button will become invalid.

    So how can I capture this in this version SDK of nrf51822?

  • I'd recommend you to read this guide thoroughly.

    As you can see from it, the bond manager will handle storing the encryption keys automatically while in a connection. However, it will not automatically store the system attributes, the CCCD values, since it can't itself know when all needed CCCDs are written. You should therefore, from your application, when you know that all needed CCCDs have been written, call the ble_bondmngr_sys_attr_store() function. If this is the first time you bond with a device, this will cause the system attributes to be written to flash, and hence allow restoration of those on any reconnection.

    However, if the system attributes have already been written, this function will return an error, and not do anything. In this case, you may want to disconnect, store bonding information and only afterwards start advertising again.

    If you take a look at the ble_app_hids_keyboard application, you can see that it does this function call on line 1110 of main.c, when notifications have been enabled in the HID service.

    Please note that the above is based on the behavior of SDK 4.4.2/S110 5.2.1. Behavior with later version may be slightly different.

Related