Zephyr NCS Extended advertising restart after disconnect

NRF54L15 NCS 3.02

I have to change my BLE advertising from Legacy to Extended. Looking at the Zephyr example "advertiser" which compiles & runs fine, but I notice that behaviour is different in that advertising does not resume after disconnection, compared to e.g. sample project "peripheral_uart" which does.

Is this just inherent in the implementation of extended advertising, or is there a configuration or parameter to select it?

If not, I guess I need to implement a work item to restart it (the advertiser sample uses a polling loop which is no good to me as I sleep the main thread for low power)

  • Both legacy and extended advertising stop after connection. In peripheral_uart, the advertising is started again in connected() callback. 

    The API for starting the legacy advertising is different than the extended advertising. For extended advertising, you need to change the calls of bt_le_adv_start to bt_le_ext_adv_start after you have created an extended advertising set using bt_le_ext_adv_create.

    Double check in your connected and disconnected callbacks if there are still traces of starting the legacy advertisement instead of extended.

  • Here is the code snippet from peripheral_uart from ncs 2.9.0 (this is what I started using as a template for my app)

    BT_CONN_CB_DEFINE(conn_callbacks) = {
    	.connected    = connected,
    	.disconnected = disconnected,
    #ifdef CONFIG_BT_NUS_SECURITY_ENABLED
    	.security_changed = security_changed,
    #endif
    };
    
    static void disconnected(struct bt_conn *conn, uint8_t reason)
    {
    	char addr[BT_ADDR_LE_STR_LEN];
    
    	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
    
    	LOG_INF("Disconnected: %s, reason 0x%02x %s", addr, reason, bt_hci_err_to_str(reason));
    
    	if (auth_conn) {
    		bt_conn_unref(auth_conn);
    		auth_conn = NULL;
    	}
    
    	if (current_conn) {
    		bt_conn_unref(current_conn);
    		current_conn = NULL;
    		dk_set_led_off(CON_STATUS_LED);
    	}
    }

    You can see there isn't any provision from restarting advertising on disconnection. I notice that has changed for ncs 3.0.2 as there is now a .recycled callback which *does* restart advertising. I start advertising with the (deprecated) BT_LE_ADV_OPT_CONNECTABLE and if you look at the definition you see:

    	 * If the advertising set was started with @ref bt_le_adv_start
    	 * without @ref BT_LE_ADV_OPT_ONE_TIME, the host will attempt to
    	 * resume the advertiser under some conditions.

    In any case that's academic really, you're confirming I need to restart advertising myself.

  • Yes, you are right, if you select the legacy advertising start without BT_LE_ADV_OPT_ONE_TIME, then the host seems to auto resume it after the disconnect. I was mistaken and comparing the behavior with our legacy SDK solution. My bad.

    With extended advertising you need to manually restart the advertising as there is no ONE_TIME kind of feature with extended. 

Related