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

What is the right procedure to un-bond/unpair nRF52840 from host?

Hi, 

    I tried to erase the bound and start another pairing procedure without rebooting my device. I was not able to remove the bond correctly. The system hangs when I call pm_peers_delete(). The problem is right after I call this function, a PM_EVT_PEERS_DELETE_SUCCEEDED event is sent to event handler and another advertising is started. Down in ble_advertising_start(), when it calls sd_ble_gap_adv_set_configure(), the function returns NRF_ERROR_INVALID_STATE. What is the right procedure to remove the bond properly? Can I temporary shutdown BLE before erase bond and resume it after removal?

Thank you,

Min-Ching

Parents Reply Children
  • Hi Haakonsh,

         I tried this API. Right after BLE_GAP_EVT_DISCONNECTED event, a BLE_GAP_EVT_CONNECTED happened immediately. I don't have chance to erase the bonding. How can I prevent that?

    Min-Ching

  • I believe that your application has set up it logical state machine to start advertising on a BLE_GAP_EVT_DISCONNECTED event. You need to follow this event throughout your application or search for your "advertising_start" function name. 

    It might be in the advertising module, a service, main loop, or some event handler somewhere. 

  • Hi Haakonsh:

        I found there is a advertising_start when event "PM_EVT_PEERS_DELETE_SUCCEEDED" is received. I have moved this from the code. I was able to get rid of "immediately reconnect" problem. Now, I was not able to restart another advertising after delete the previous pairing. 

        What I did for delete bond is 1. call sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION); 2. After disconnect call pm_peers_delete();

        After delete the bond, I manually trigger another advertising and I get error NRF_ERROR_INVALID_STATE when the code execute sd_ble_gap_adv_set_configure(&p_advertising->adv_handle, p_advertising->p_adv_data, &p_advertising->adv_params); in ble_advertising_start().

        I don't have any idea what is wrong here. Any suggestions?

    Thank you,

    Min-Ching

  • Hey Min-Ching,

    From the sd_ble_gap_adv_set_configure SPI reference i found that the error code NRF_ERROR_INVALID_STATE means:


    "Invalid state to perform operation.

    • It is invalid to provide non-NULL advertising set parameters while advertising.
    • It is invalid to provide the same data buffers while advertising. To update advertising data, provide new advertising buffers."

    Cheers,

    Håkon.

  • Hi Håkon,

         I checked all the parameter passed into sd_ble_gap_adv_set_configure. The advertising set parameter is not null. However, the data buffer pointer is the same. I don't understand why this buffer must be different when all your sample code uses BLE_ADVERTISING_DEF(m_advertising) to create a buffer and reused it. Does this mean when I call this API the device is already in advertising mode? Any other thing we can check? Do you have any good example code that I can take a look? 

    Thank you,

    Min-Ching Ho

Related