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

How to reinitialize advertising ?

Hello, I use nrf51822 , sdk 8.0.0, s110

I defined advertise interval and timeout

#define APP_ADV_INTERVAL                         320              
#define APP_ADV_TIMEOUT_IN_SECONDS      3   

Also, I write advertising init function at below;

static void advertising_init(void)
{

   .
   .
   .

    ble_adv_modes_config_t options = {0};
    options.ble_adv_fast_enabled  = BLE_ADV_FAST_ENABLED;
    options.ble_adv_fast_interval = APP_ADV_INTERVAL;
    options.ble_adv_fast_timeout  = APP_ADV_TIMEOUT_IN_SECONDS;

    err_code = ble_advertising_init(&advdata, &options, NULL, NULL);
    APP_ERROR_CHECK(err_code);
}

The question is, How it will start to advertise again? I'm trying to build a periodic advertise structure. For example;

  1. Start advertise
  2. Timeout x seconds later (Stop advertise)
  3. Start advertise again y seconds later.

Is it possible?

  • Hi Purgoufr!

    If the interval is set to 1 second and the timeout is set to 180 seconds, the device will advertise every second for 180 seconds, and then timeout (i.e stop advertising).

    In most of the BLE peripheral examples, the SDK is set up to advertise for 180s and then stop until button 1 is pressed.
    You can disable this timeout by setting the APP_ADV_TIMEOUT_IN_SECONDS to 0. This will make your device advertise until told not to.
    You can start/stop advertising by using the sd_ble_gap_adv_stop() / sd_ble_gap_adv_start() functions.

    You should be able to change the code to stop/start advertising on another event, i.e using a timer.

    Best regards,
    Joakim.

Related