Can't get BLE extended connectable advertising timeout callback

Using SDK 2.1.2

Trying to set up connectable advertising for specific period of time and be notified when this period of time expired.
My setup sequence (simplified for demonstration purpose):

struct bt_le_ext_adv_cb ext_adv_cb = {
.sent = adv_timed_out,
};

static struct bt_conn_cb conn_callbacks = {
.connected = connected,
.disconnected = disconnected,
.security_changed = security_changed,
};
 

Init (one time at boot):
------
bt_conn_cb_register(&conn_callbacks);
bt_conn_auth_cb_register(&conn_auth_callbacks);
bt_conn_auth_info_cb_register(&auth_cb_info);
bt_enable(NULL);
settings_load();
bt_nus_init(&nus_cb);
struct bt_le_adv_param *adv_param = BT_LE_ADV_CONN;
bt_le_ext_adv_create(adv_param, &ext_adv_cb, out_adv);
bt_le_ext_adv_set_data(...);


Start advertising (every time I want to give opportunity to my central device to connect):
----------------------
#define BLE_CONN_ADV_TIMEOUT (4 * 100) // 4 sec in 10ms units
param = BT_LE_EXT_ADV_START_PARAM(BLE_CONN_ADV_TIMEOUT, 0); 
bt_le_ext_adv_stop(adv);  // JIC there is a previous advertisement in progress
bt_le_ext_adv_start(adv, param);


If connection happens, I receive both bt_conn_cb.connected and subsequent .disconnected callbacks 
If no connection happened within 4 seconds I would expect (perhaps mistakenly) to receive bt_le_ext_adv_cb.sent callback, but it doesn't happen.

Interestingly, if I change my advertising to non-connectable, and set param as
param = BT_LE_EXT_ADV_START_PARAM(0, 3);

then I do receive this .sent callback, and info->num_events is correctly set to 3.

Looking at zephyr/include/zephyr/bluetooth/bluetooth.h

struct bt_le_ext_adv_cb {
/**
* @brief The advertising set has finished sending adv data.
*
* This callback notifies the application that the advertising set has
* finished sending advertising data.
* The advertising set can either have been stopped by a timeout or
* because the specified number of advertising events has been reached.
*
* @param adv The advertising set object.
* @param info Information about the sent event.
*/
void (*sent)(struct bt_le_ext_adv *adv,  <-----------------------
struct bt_le_ext_adv_sent_info *info);

it appears that it should work on either timeout or number of events

What am I missing ?



Parents
  • Hi

    So, from bluetooth.h, the bt_le_ext_adv_cb() returns when the advertising set has finished, either by way of a timeout or because the specified number of advertising events have been reached. I think the reason you're not seeing the timeout being trigged is because your define of the BLE_CONN_ADV_TIMEOUT doesn't really specify what the setting is. From where do you see that this equals 10ms units? 

    #define BLE_CONN_ADV_TIMEOUT 4 * 100; // 4 sec in 10ms units

    Best regards,

    Simon

  • > From where do you see that this equals 10ms units? 
    From bluetooth.h. Perhaps I misunderstood the comments ?
    What should the unit be then ?

    struct bt_le_ext_adv_start_param {
    /**
    * @brief Advertiser timeout (N * 10 ms).
    *
    * Application will be notified by the advertiser sent callback.
    * Set to zero for no timeout.
    *
    * When using high duty cycle directed connectable advertising then
    * this parameters must be set to a non-zero value less than or equal
    * to the maximum of @ref BT_GAP_ADV_HIGH_DUTY_CYCLE_MAX_TIMEOUT.
    *
    * If privacy @kconfig{CONFIG_BT_PRIVACY} is enabled then the timeout
    * must be less than @kconfig{CONFIG_BT_RPA_TIMEOUT}.
    */
    uint16_t timeout;
    /**
    * @brief Number of advertising events.
    *
    * Application will be notified by the advertiser sent callback.
    * Set to zero for no limit.
    */
    uint8_t num_events;
    };

  • Also see

    struct bt_le_per_adv_sync_param {
    /**
    * @brief Periodic Advertiser Address
    *
    * Only valid if not using the periodic advertising list
    * (BT_LE_PER_ADV_SYNC_OPT_USE_PER_ADV_LIST)
    */
    bt_addr_le_t addr;

    /**
    * @brief Advertiser SID
    *
    * Only valid if not using the periodic advertising list
    * (BT_LE_PER_ADV_SYNC_OPT_USE_PER_ADV_LIST)
    */
    uint8_t sid;

    /** Bit-field of periodic advertising sync options. */
    uint32_t options;

    /**
    * @brief Maximum event skip
    *
    * Maximum number of periodic advertising events that can be
    * skipped after a successful receive.
    * Range: 0x0000 to 0x01F3
    */
    uint16_t skip;

    /**
    * @brief Synchronization timeout (N * 10 ms)
    *
    * Synchronization timeout for the periodic advertising sync.
    * Range 0x000A to 0x4000 (100 ms to 163840 ms)
    */
    uint16_t timeout;
    };

  • Unfortunately I couldn't find (in SDK 2.1.2) any examples of using timeout in BT_LE_EXT_ADV_START_PARAM
    All examples use BT_LE_EXT_ADV_START_DEFAULT, which is BT_LE_EXT_ADV_START_PARAM(0, 0)

Reply Children
No Data
Related