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

[advertising stop]

Hi all,

Someone can give me a information about the difference between function uint32_t err_code = sd_ble_gap_adv_stop(); and stop the advertising with using the timeout that put the state machine to ADV_MODE_SLOW and after in IDLE_MODE when arrive the GAP_EVT_TIMEOUT ( i use a gls example).

Because i don't understand how when the a BLE_ADV_EVT_IDLE is send the advertising stopped. how Does work it?

If i use a sd_ble_gap_adv_stop, is there a way to stopped the EVT_TIMEOUT? Thanks, Anna

  • Hi,

    The function sd_ble_gap_adv_stop() is used to stop the advertising directly from your application code.

    In the gls example you can choose to use ADV_MODE_FAST, ADV_MODE_SLOW or to use both. You can enable the different modes in the advertising_init() function with:

    options.ble_adv_fast_enabled  = true;
    options.ble_adv_slow_enabled =  true; 
    

    And you can set the timeout for the different modes with:

    options.ble_adv_fast_timeout  = 30;
    options.ble_adv_slow_timeout  = 180;
    

    When the timeout happens, you will get the event BLE_GAP_EVT_TIMEOUT. If you are in ADV_MODE_FAST mode, it will switch to ADV_MODE_SLOW, and if you are in ADV_MODE_SLOW it will switch to BLE_ADV_MODE_IDLE and the SoftDevice will stop advertising. The function sd_ble_gap_adv_stop() is not used.

    With the limited discoverable mode(BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE) it is not allowed to advertise longer than the timeout period. But if you don't want the advertising to stop, you can switch to general discoverable mode(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE), and set the timeout to 0 to do unlimited advertising:

    advdata.flags                 = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
    options.ble_adv_fast_timeout  = 0;
    
  • Hi Sigurd,

    thank you for the clear answer. I have only a last question. On the gls example, only the BLE_ADV_FAST is enable in the advertising_init(). But when the BLE_GAP_EVT_TIMEOUT occurs, the advertising go in slow mode and advertising stop. This is is possible, if in the advertising_init the slow advertising is not enable?

    thanks, Anna

  • Yes, if you have not enabled the ADV_MODE_SLOW, only ADV_MODE_FAST, the advertising will stop when ADV_MODE_FAST timeouts(BLE_GAP_EVT_TIMEOUT). So ADV_MODE_FAST --> BLE_ADV_MODE_IDLE(advertising is stopped). ADV_MODE_SLOW is completely skipped.

  • Perfect. Now it's all clear. So when the Advertising go in BLE_ADV_MODE_IDLE is the softdevice that worry to stop the advertising? Thanks.

Related