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

ble_app_uart peripheral example, SDK12.3, 51822, turning advertising on/off

Hello again Nordic Pro's,

As you probably all know by now, our product app is based on the subject example code, SDK and device.  We need to programmatically disconnect from a central, turn advertising off and then later, turn advertising back on for testing purpose.  I have found a ticket that references this using a newer device and SDK, using calls to sd_ble_gap_disconnect(), sd_ble_gap_adv_stop() and sd_ble_gap_adv_start().  However the start and stop calls are not made directly from main() within the 12.3 example, as shown in the other ticket.  What are the implications of performing these calls from within our app to disconnect from a central, stop,  and later restart advertising?  ie are there any connection vars that must be managed, or other such holes we might fall into or can I freely use these functions to do as required.

Thanks again,

Robin @ TL

Parents Reply
  • Hi Robin, 

    The question is to check if you use the ble_advertising module to do your initial advertising. If the module is being used, the advertising will restart automatically after disconnected. 
    So what you need to do is to remove the call on_disconnected() inside ble_advertising_on_ble_evt() in ble_advertising.c

    And then in your own code you can start advertising again by calling ble_advertising_start() with the mode you want. 

    To disconnect you can call sd_ble_gap_disconnect() to request the connection to be terminated. There will be  BLE_GAP_EVT_DISCONNECTED event after the connection is disconnected. 

Children
Related