Advertising with timeout in loop

Hello,

I want to design an application that advertises for X seconds. then stops advertising for Y seconds. then again starts advertising. I am trying to implement the same using app_easy_timer();

as it is visible from the image, I have called stop_advertising_cb().

in the stop advertising call back fuction I have stopped advertising using app_easy_gap_advertise_stop(); 

Which is working fine. I can also see the next line printed on my uart consol.

Then I have initialised the same timer handler with, 

start_advertising_again_cb(); 

which is not working.

Have I missed something. I have currently set 10s in app_easy_timer();

Parents
  • Hi Sumo,

    Thank you for posting your question online.
    When you call the app_easy_gap_advertise_stop function, the app_on_adv_undirect_complete callback function will be called. 
    So, for my implementation I worked on the ble_app_peripheral example and I declared the following:
    On user_callback_config.h file:

    .app_on_adv_undirect_complete       = user_app_adv_undirect_complete,

    // Default Handler Operations
    static const struct default_app_operations user_default_app_operations = {
        .default_operation_adv = user_app_adv_start,		//user_app_adv_start
    };

    On user_peripheral.c file:
    timer_hnd app_adv_timeout_timer_used						__SECTION_ZERO("retention_mem_area0");
    #define START_ADV_IN_SEC			500	//5 seconds
    #define STOP_ADV_IN_SEC				1000 // 10 seconds

    On user_app_init function I initiliaze the app_adv_timeout_timer_used:
     app_adv_timeout_timer_used = EASY_TIMER_INVALID_TIMER;

    The callback user_app_adv_start function will be called after default_app_on_init:
    void user_app_adv_start(void)
    {
        // Schedule the next advertising data update
        app_adv_data_update_timer_used = app_easy_timer(APP_ADV_DATA_UPDATE_TO, adv_data_update_timer_cb);
    
        struct gapm_start_advertise_cmd* cmd;
        cmd = app_easy_gap_undirected_advertise_get_active();
    
        // Add manufacturer data to initial advertising or scan response data, if there is enough space
        app_add_ad_struct(cmd, &mnf_data, sizeof(struct mnf_specific_data_ad_structure), 1);
    	//Check if Timer for Advertising is unitiliazed and initialize him again
    	  if( app_adv_timeout_timer_used != EASY_TIMER_INVALID_TIMER)
    	  {
    		app_adv_timeout_timer_used = EASY_TIMER_INVALID_TIMER;
    	  }
    		// Start the timer to stop advertising after 10seconds
    		app_adv_timeout_timer_used = app_easy_timer(STOP_ADV_IN_SEC, stop_adv_cb);
    	  arch_set_extended_sleep(false);
        app_easy_gap_undirected_advertise_start();
    	
    }

    After 5 seconds, the stop_adv_cb callback function will be called:
    void stop_adv_cb(void)
    {
      //Check if Timer for Advertising is unitiliazed and initialize him again
    	if( app_adv_timeout_timer_used != EASY_TIMER_INVALID_TIMER)
    	{
    		app_adv_timeout_timer_used = EASY_TIMER_INVALID_TIMER;
    		
    	}
    		app_easy_gap_advertise_stop();
    	
    }

    Then the user_app_adv_undirect_complete custom callback function will be called:
    void user_app_adv_undirect_complete(uint8_t status)
    {
        // If advertising was canceled then wait 5 seconds and start advertising again
        if (status == GAP_ERR_CANCELED)
        {
      		app_adv_timeout_timer_used = app_easy_timer(START_ADV_IN_SEC, user_app_adv_start);
      	}
    
    }

    With the SmartSnippets Toolbox, Power Profiler Tool I am able to see:

    So, keep in mind to initialize your Timer each time and that when you stop advertising to use the callback function.
    Note: You should use the app_easy_timer_cancel function if you establish a connection.

    Kind Regards,
    OV_Renesas

Reply
  • Hi Sumo,

    Thank you for posting your question online.
    When you call the app_easy_gap_advertise_stop function, the app_on_adv_undirect_complete callback function will be called. 
    So, for my implementation I worked on the ble_app_peripheral example and I declared the following:
    On user_callback_config.h file:

    .app_on_adv_undirect_complete       = user_app_adv_undirect_complete,

    // Default Handler Operations
    static const struct default_app_operations user_default_app_operations = {
        .default_operation_adv = user_app_adv_start,		//user_app_adv_start
    };

    On user_peripheral.c file:
    timer_hnd app_adv_timeout_timer_used						__SECTION_ZERO("retention_mem_area0");
    #define START_ADV_IN_SEC			500	//5 seconds
    #define STOP_ADV_IN_SEC				1000 // 10 seconds

    On user_app_init function I initiliaze the app_adv_timeout_timer_used:
     app_adv_timeout_timer_used = EASY_TIMER_INVALID_TIMER;

    The callback user_app_adv_start function will be called after default_app_on_init:
    void user_app_adv_start(void)
    {
        // Schedule the next advertising data update
        app_adv_data_update_timer_used = app_easy_timer(APP_ADV_DATA_UPDATE_TO, adv_data_update_timer_cb);
    
        struct gapm_start_advertise_cmd* cmd;
        cmd = app_easy_gap_undirected_advertise_get_active();
    
        // Add manufacturer data to initial advertising or scan response data, if there is enough space
        app_add_ad_struct(cmd, &mnf_data, sizeof(struct mnf_specific_data_ad_structure), 1);
    	//Check if Timer for Advertising is unitiliazed and initialize him again
    	  if( app_adv_timeout_timer_used != EASY_TIMER_INVALID_TIMER)
    	  {
    		app_adv_timeout_timer_used = EASY_TIMER_INVALID_TIMER;
    	  }
    		// Start the timer to stop advertising after 10seconds
    		app_adv_timeout_timer_used = app_easy_timer(STOP_ADV_IN_SEC, stop_adv_cb);
    	  arch_set_extended_sleep(false);
        app_easy_gap_undirected_advertise_start();
    	
    }

    After 5 seconds, the stop_adv_cb callback function will be called:
    void stop_adv_cb(void)
    {
      //Check if Timer for Advertising is unitiliazed and initialize him again
    	if( app_adv_timeout_timer_used != EASY_TIMER_INVALID_TIMER)
    	{
    		app_adv_timeout_timer_used = EASY_TIMER_INVALID_TIMER;
    		
    	}
    		app_easy_gap_advertise_stop();
    	
    }

    Then the user_app_adv_undirect_complete custom callback function will be called:
    void user_app_adv_undirect_complete(uint8_t status)
    {
        // If advertising was canceled then wait 5 seconds and start advertising again
        if (status == GAP_ERR_CANCELED)
        {
      		app_adv_timeout_timer_used = app_easy_timer(START_ADV_IN_SEC, user_app_adv_start);
      	}
    
    }

    With the SmartSnippets Toolbox, Power Profiler Tool I am able to see:

    So, keep in mind to initialize your Timer each time and that when you stop advertising to use the callback function.
    Note: You should use the app_easy_timer_cancel function if you establish a connection.

    Kind Regards,
    OV_Renesas

Children