Legacy Advertising bluetooth power saving with bt_le_adv_stop()

Hi there, 

I am trying to implement some power saving features of my device, and am having trouble with stopping advertising in SDK v3.1.0

I would like to advertise for 1 minute, and then stop. A button press would resume advertising with the same timeout. I do not need the device to advertise 24/7 

It looks like setting BT_LE_AD_LIMITED for bt_data inside bt_le_adv_start , and setting CONFIG_BT_LIM_ADV_TIMEOUT=60 allows me to implement the timeout feature. However, in SDK v3.1.0, advertising immediately restarts after stopping. It seems that there used to be an option inside BT_LE_ADV_PARAM to set advertising to one time. The alternative BT_LE_ADV_OPT_CONN does not seem to do this by default and I cannot find any instructions on how to implement this. 

Is anyone able to tell me how I can implement this feature? 

Thank you very much

Parents
  • Hi Ryan,
    One idea is to create a delayed work item that stops the advertising after some specified time.

    Something like this logic:

    static void adv_stop_work_handler(struct k_work *work)
    {
    	bt_le_adv_stop();
    }
    
    K_WORK_DELAYABLE_DEFINE(adv_stop, adv_stop_work_handler);
    
    static void button_pressed_work_handler(struct k_work *work)
    {
    	bt_le_adv_start();
    
    	k_work_reschedule(&adv_stop, K_MSEC(ADV_TIMEOUT_MS));
    }

    You may also set up a button callback to start advertising.

    Regards,
    Benjamin

  • Hi Benjamin, 

    Thanks for getting back to me. 

    I like the app logic that you used. However my trouble isn't implementing a timeout, but instead, that bt_le_adv_stop() doesn't permanently stop advertising.

    The issue is that advertising will restart immediately after bt_le_adv_stop() is called. It looks like the deprecated BT_LE_ADV_OPT_ONE_TIME config used to prevent this. 

    Thanks for your help

Reply
  • Hi Benjamin, 

    Thanks for getting back to me. 

    I like the app logic that you used. However my trouble isn't implementing a timeout, but instead, that bt_le_adv_stop() doesn't permanently stop advertising.

    The issue is that advertising will restart immediately after bt_le_adv_stop() is called. It looks like the deprecated BT_LE_ADV_OPT_ONE_TIME config used to prevent this. 

    Thanks for your help

Children
  • Hi Ryan,

    To confirm, using either of these methods, you experience that advertising resumes immediately?

    • Calling bt_le_adv_stop()

    • Setting the CONFIG_BT_LIM_ADV_TIMEOUT symbol and the BT_LE_AD_LIMITED

    I tested a minimal advertising setup in v3.1.0 and was able to stop it properly by just calling bt_le_adv_stop(). Maybe there’s something different in your configuration, or you’re doing some callback logic? Could you try starting and stopping advertising with a bare-minimum setup to compare?

    Also, the BT_LE_ADV_OPT_ONE_TIME option was used to prevent advertising from restarting automatically after a connection is closed. 

    Best regards,
    Benjamin

  • Hi Bejamin, 

    Thank you. I just noticed that my on_recycled() callback was restarting the advertising. 

    static struct bt_conn_cb conn_cb = {
        .connected = on_connected,
        .disconnected = on_disconnected,
        .recycled = on_recycled,
        .le_param_updated = on_le_param_updated,
        .le_phy_updated = on_le_phy_updated,
        .security_changed = on_security_changed,
    };

    Removing that logic fixed the issue. 

    Much appreciated

Related