This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Start & stop of advertising and how to prevent automatically restart of advertising in case of a random disconnection or disconnection initiated from the application.

Dear sir/madame

Start & stop of advertising and how to prevent automatically restart of advertising in case of a random disconnection or disconnection initiated from the application.

Setup:

One peripheral unit (nRF52840) and one central unit (nRF52840), SDK 17.02.1 and Softdevice 7.2.0

Starting point of our central and peripheral app was the example ble_app_uart (peripheral and central) where we have stripped it down to a NUS service only app. This one is tested and used as foundation of our apps.

Most of our functionalities are added and verified but there is one feature I’m struggling with and that is automatically restart of advertising.

Have used hour on reading this forum but not been able to figure out how to, even there is tons of post regarding automatically restart of advertising.

There are situations when we get a disconnect by some reason and that we want to restart advertising with a different DEVICE_NAME.

I have a working function that stop advertising, set a new DEVICE_NAME, and reinitiate advertising, but in some situations the advertising is not restarted automatically by some reason at disconnect, hence my function for re-initiate advertising will end in an fatal error since I’m sending stop advertising (sd_ble_gap_adv_stop(m_advertising.adv_handle).

 

So, my question is: How can I completely stop automatically restart of advertising or ensure that SD sends an event if advertising is not automatically restarted?

 

Kind regards

Svein

  • Hello Svein,

    There are situations when we get a disconnect by some reason and that we want to restart advertising with a different DEVICE_NAME.

    Have you seen this blogpost detailing how to dynamically update advertising data? It might be useful to have a look at, and it also includes an simple demonstration of how you can proceed to update the advertising dynamically when using the ble advertising library.

    So, my question is: How can I completely stop automatically restart of advertising or ensure that SD sends an event if advertising is not automatically restarted?

    I am not exactly sure what you mean when you say that the SoftDevice should send an event in case advertising is not automatically restarted - the SoftDevice does send an event to the application upon starting advertising, such as BLE_ADV_EVT_FAST when it starts to advertise in fast mode, etc. Perhaps this is what you are looking for? 
    The advertising library will automatically restart advertising on disconnection or termination (such as due to timeout) of the link, please see the callback functions on_terminated and on_disconnected in ble_advertising.c. You could modify these to not automatically restart advertising if you wish for the device to not immediately resume advertising upon link termination, and then instead have the advertising restarted elsewhere in your program, if this is what you are after?

    Best regards,
    Karl

Related