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

Calling sd_ble_gap_adv_stop() does not emit an on_adv_evt event

I'm a bit at a loss of how to voluntarily stop advertising:
My related thread says I should call sd_ble_gap_adv_stop(), but when I do, no corresponding event is raised by the soft-device. This ultimately means that on_adv_evt() in main.c does not get called, the static m_adv_mode_current in ble_advertising.c does not change state to BLE_ADV_MODE_IDLE, and the ble_advertising module in an unmatching state.

How can I overcome this? Is the only way to reliably stop advertising is to wait for it to time-out?

Version: nRF5 SDK 11.0.0, s132, with PCA10040 EVB

Parents
  • The Advertising Module can be used for many typical "Connectable Advertising" scenarios, but if you want other functionality you are free to modify it, or not use it at all.

    You can set the advertising data with ble_advdata_set(), and then call sd_ble_gap_adv_start() with the parameters you like. Maybe you want to advertise forever, and always stop it manually with sd_ble_gap_adv_stop()?

  • If you call sd_ble_gap_adv_stop() when you are not advertising it will return NRF_ERROR_INVALID_STATE. Will something like this work for you:

    uint32_t err_code = sd_ble_gap_adv_stop();
    if(err_code == NRF_ERROR_INVALID_STATE)
    {
        // Do nothing, timeout has occured
    }
    else
    {
        APP_ERROR_CHECK(err_code);
    }
    

    It means that instead of examining the advertising module, and make the necessary modifications to it, you can just use the sd_* API directly, like sd_ble_gap_adv_start(), sd_ble_gap_adv_stop() and so on.

    I don't understand your second question. If you have further questions I think you should add them separately.

Reply
  • If you call sd_ble_gap_adv_stop() when you are not advertising it will return NRF_ERROR_INVALID_STATE. Will something like this work for you:

    uint32_t err_code = sd_ble_gap_adv_stop();
    if(err_code == NRF_ERROR_INVALID_STATE)
    {
        // Do nothing, timeout has occured
    }
    else
    {
        APP_ERROR_CHECK(err_code);
    }
    

    It means that instead of examining the advertising module, and make the necessary modifications to it, you can just use the sd_* API directly, like sd_ble_gap_adv_start(), sd_ble_gap_adv_stop() and so on.

    I don't understand your second question. If you have further questions I think you should add them separately.

Children
No Data
Related