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

  • I don't know what is better, I don't know what your application is. If you only want to start one type of advertising and stop it either with sd_ble_gap_adv_stop() or on timeout this is very simple to implement. Have you tried?

  • it's simple to menage adv_stop OR timeout but if i want use both, i have a problem that one i stopped it with sd_ble_ga_adv_stop(), after the timeout expired and try to stop again the advertising and give an error. So two question

    • What's means " it is easier the sd *API directly "
    • How when the evt timeout arrived from softdevice the advertising is stopped, i don't see that in the loop Fast_slow_idle the function is called.
  • 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.

  • Thanks for the answer,

    the err_code is = NRF_ERROR_INVALID_STATE. only when an advertising stop occurs when the device is not in advertising? because if it occurs in other case maybe it's important don't ignore it.

    the second question is the same, i use a gls example and i see that the advertising stop ( i don't see the board on the phone) when timeout occurs. I use the ble example and callstack is:

    1. ble_stack_init();
    2. softdevice_ble_evt_handler_set(ble_evt_dispatch);
    3. ble_advertising_on_ble_evt(p_ble_evt);

    Case : BLE_GAP_EVT_TIMEOUT,

    starts the ble_advertising in slow mode and go in Idle mode. My question is, is there a way to stop the timer to avoid that the BLE_GAP_EVT_TIMEOUT arrived after i stop the advertising with command sd_ble_gap_adv_stop();

  • Yes, that is the only time sd_ble_gap_adv_stop() will return NRF_ERROR_INVALID_STATE. You shouldn't get a BLE_GAP_EVT_TIMEOUT event (with timeout source BLE_GAP_TIMEOUT_SRC_ADVERTISING) if you have called sd_ble_gap_adv_stop().

    If things are still unclear, or you have more questions please add them separately as new question. This is getting very cluttered.

Related