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

Periodic advertisement when APP_ADV_DURATION expires

Hi,

I am using ble_app_uart example for peripheral device and it will be powered by a 3.7 V battery. I need to use battery as long as possible. So I decided to make peripheral device advertise periodically.

Since I need to use app_timer, System ON sleep mode works for me. I know that device doesn't advertise when APP_ADV_DURATION expires (assume it is not 0).  I tried to restart advertise after APP_ADV_DURATION which triggers BLE_ADV_EVT_IDLE event. Also I disabled sleep_mode_enter() function in BLE_ADV_EVT_IDLE since it will put device in System OFF sleep mode.

My timeout handler is like this:

static void single_shot_timer_handler(void * p_context)
{
 uint32_t err_code;
 
 err_code = ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST); 
 APP_ERROR_CHECK(err_code);
}



And I wanted to start timer in BLE_ADV_EVT_IDLE event like this:

switch (ble_adv_evt)
    {
        case BLE_ADV_EVT_FAST:
            NRF_LOG_INFO("adv fast");
            err_code = bsp_indication_set(BSP_INDICATE_ADVERTISING);
            APP_ERROR_CHECK(err_code);
            break;
        case BLE_ADV_EVT_IDLE:
            NRF_LOG_INFO("idle");                        
            err_code = app_timer_start(m_single_shot_timer_id, APP_TIMER_TICKS(20000), NULL);
            APP_ERROR_CHECK(err_code);
            //sleep_mode_enter();
            break;

I just wanted to advertise for 10 seconds and make it sleep for 20 seconds. I expected timer to start 20 seconds after BLE_ADV_EVT_IDLE. However, device advertises all the time. I mean when APP_ADV_DURATION expires, it doesn't stop advertising.

By the way APP_ADV_DURATION macro is 1000. And I use SDK 16

Could you please help me about it ? I will be very appreciated if you give me a suggestion.

Best Regards

Related