<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Can&amp;#39;t get BLE extended connectable advertising timeout callback</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/111260/can-t-get-ble-extended-connectable-advertising-timeout-callback</link><description>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): Init (one time at boot): ------ Start advertising (every time</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 28 May 2024 09:29:47 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/111260/can-t-get-ble-extended-connectable-advertising-timeout-callback" /><item><title>RE: Can't get BLE extended connectable advertising timeout callback</title><link>https://devzone.nordicsemi.com/thread/486126?ContentTypeID=1</link><pubDate>Tue, 28 May 2024 09:29:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6e774598-b06f-4a79-a188-1d65302b810c</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;Okay, so we were able to add this on our end after a bit trial and error. Here is the relevant&amp;nbsp;source code and configs (tested on NCS 2.1.1):&lt;/p&gt;
&lt;p&gt;main.c&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/*
 * Copyright (c) 2021 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
 */

/** @file
 *  @brief Peripheral example
 */

#include &amp;lt;zephyr/types.h&amp;gt;
#include &amp;lt;stddef.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;lt;errno.h&amp;gt;
#include &amp;lt;sys/printk.h&amp;gt;
#include &amp;lt;zephyr.h&amp;gt;

#include &amp;lt;bluetooth/bluetooth.h&amp;gt;
#include &amp;lt;bluetooth/conn.h&amp;gt;
#include &amp;lt;bluetooth/uuid.h&amp;gt;
#include &amp;lt;bluetooth/gatt.h&amp;gt;

#include &amp;lt;logging/log.h&amp;gt;
LOG_MODULE_REGISTER(app, CONFIG_LOG_DEFAULT_LEVEL);


#define BLE_INT                         (0x140) // N * 0.625. corresponds to dec. 320; 320*0.625 = 200ms
#define BLE_ADV_TIMEOUT                 (1000)  // N * 10ms for advertiser timeout
#define BLE_ADV_EVENTS                  (0)

static struct k_work start_advertising_worker;

static struct bt_le_ext_adv *adv;

static const struct bt_data ad[] = {
    BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
    BT_DATA_BYTES(BT_DATA_UUID16_ALL, 0x0d, 0x18, 0x0f, 0x18, 0x0a, 0x18),
};

#if defined(CONFIG_BT_PERIPHERAL)

static void connected(struct bt_conn *conn, uint8_t conn_err)
{
    int err;
    struct bt_conn_info info;
    char addr[BT_ADDR_LE_STR_LEN];

    bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));

    if (conn_err) {
        printk(&amp;quot;Connection failed (err %d)\n&amp;quot;, conn_err);
        return;
    }

    err = bt_conn_get_info(conn, &amp;amp;info);

    if (err) {
        printk(&amp;quot;Failed to get connection info\n&amp;quot;);
    } else {
        const struct bt_conn_le_phy_info *phy_info;
        phy_info = info.le.phy;

        printk(&amp;quot;Connected: %s, tx_phy %u, rx_phy %u\n&amp;quot;,
               addr, phy_info-&amp;gt;tx_phy, phy_info-&amp;gt;rx_phy);
    }
}

static void disconnected(struct bt_conn *conn, uint8_t reason)
{
    printk(&amp;quot;Disconnected (reason 0x%02x)\n&amp;quot;, reason);

    k_work_submit(&amp;amp;start_advertising_worker);
}

static struct bt_conn_cb conn_callbacks = {
    .connected = connected,
    .disconnected = disconnected,
    
};

#endif /* defined(CONFIG_BT_PERIPHERAL) */


static void adv_sent(struct bt_le_ext_adv *instance,
             struct bt_le_ext_adv_sent_info *info)
{   
    //printk(&amp;quot;Advertising stopped. num_sent: %d &amp;quot;, info-&amp;gt;num_sent);
    LOG_INF(&amp;quot;Advertising stopped&amp;quot;);
}

static int create_advertising(void)
{
    int err;
    struct bt_le_adv_param param =
        BT_LE_ADV_PARAM_INIT(
                     BT_LE_ADV_OPT_EXT_ADV | BT_LE_ADV_OPT_USE_NAME,
                     BLE_INT,
                     BLE_INT,
                     NULL);

    static const struct bt_le_ext_adv_cb adv_cb = {
        .sent = adv_sent,
    };

    err = bt_le_ext_adv_create(&amp;amp;param, &amp;amp;adv_cb, &amp;amp;adv);
    if (err) {
        printk(&amp;quot;Failed to create advertiser set (%d)\n&amp;quot;, err);
        return err;
    }

    printk(&amp;quot;Created adv: %p\n&amp;quot;, adv);

    err = bt_le_ext_adv_set_data(adv, ad, ARRAY_SIZE(ad), NULL, 0);
    if (err) {
        printk(&amp;quot;Failed to set advertising data (%d)\n&amp;quot;, err);
        return err;
    }

    return 0;
}

static void start_advertising(struct k_work *item)
{
    int err;

    err = bt_le_ext_adv_start(adv, BT_LE_EXT_ADV_START_PARAM(BLE_ADV_TIMEOUT, BLE_ADV_EVENTS));
    if (err) {
        printk(&amp;quot;Failed to start advertising set (%d)\n&amp;quot;, err);
        return;
    }

    //printk(&amp;quot;Advertiser %p set started\n&amp;quot;, adv);
    LOG_INF(&amp;quot;Advertising started&amp;quot;);
}

static void bt_ready(void)
{
    int err = 0;

    printk(&amp;quot;Bluetooth initialized\n&amp;quot;);

    k_work_init(&amp;amp;start_advertising_worker, start_advertising);

    err = create_advertising();
    if (err) {
        printk(&amp;quot;Advertising failed to create (err %d)\n&amp;quot;, err);
        return;
    }

    k_work_submit(&amp;amp;start_advertising_worker);
}

void radio_handler(const void *context)
{

    printk(&amp;quot;radio_handler&amp;quot;);

}

void main(void)
{
    int err;

    printk(&amp;quot;Main start&amp;quot;);

    err = bt_enable(NULL);
    if (err) {
        printk(&amp;quot;Bluetooth init failed (err %d)\n&amp;quot;, err);
        return;
    }

    bt_ready();

    bt_conn_cb_register(&amp;amp;conn_callbacks);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;prj.conf&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_BT=y
CONFIG_BT_DEBUG_LOG=y
CONFIG_BT_PERIPHERAL=y

CONFIG_BT_CTLR_PHY_CODED=y
CONFIG_BT_EXT_ADV=y
CONFIG_BT_USER_PHY_UPDATE=y

# Log
CONFIG_LOG=y
CONFIG_LOG_DEFAULT_LEVEL=3&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Here we get the callback after ~10 seconds when using&amp;nbsp;&lt;span&gt;&lt;span dir="ltr"&gt;&lt;i&gt;BT_LE_EXT_ADV_START_PARAM(1000, 0)&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1716888543523v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Can't get BLE extended connectable advertising timeout callback</title><link>https://devzone.nordicsemi.com/thread/485821?ContentTypeID=1</link><pubDate>Fri, 24 May 2024 12:46:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:badc7184-509e-4c7b-b080-b4e54a74496d</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;I&amp;#39;ll get back to you next week with a decisive answer here, as I&amp;#39;ll need some more time to look into/ask the devs about how to implement this correctly. Thank you for your patience!&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Can't get BLE extended connectable advertising timeout callback</title><link>https://devzone.nordicsemi.com/thread/485680?ContentTypeID=1</link><pubDate>Thu, 23 May 2024 15:44:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6023f555-36bc-4e37-83e8-ad560157af4c</guid><dc:creator>Alex_S@Aperia</dc:creator><description>&lt;p&gt;Unfortunately I couldn&amp;#39;t find (in SDK 2.1.2) any examples of using timeout in&amp;nbsp;BT_LE_EXT_ADV_START_PARAM&lt;br /&gt;All examples use BT_LE_EXT_ADV_START_DEFAULT, which is&amp;nbsp;BT_LE_EXT_ADV_START_PARAM(0, 0)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Can't get BLE extended connectable advertising timeout callback</title><link>https://devzone.nordicsemi.com/thread/485679?ContentTypeID=1</link><pubDate>Thu, 23 May 2024 15:41:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2e2e002c-cb92-4529-9580-fe4670a7dc4f</guid><dc:creator>Alex_S@Aperia</dc:creator><description>&lt;p&gt;Also see&lt;/p&gt;
&lt;p&gt;struct bt_le_per_adv_sync_param { &lt;br /&gt; /** &lt;br /&gt; * @brief Periodic Advertiser Address &lt;br /&gt; * &lt;br /&gt; * Only valid if not using the periodic advertising list &lt;br /&gt; * (BT_LE_PER_ADV_SYNC_OPT_USE_PER_ADV_LIST) &lt;br /&gt; */ &lt;br /&gt; bt_addr_le_t addr; &lt;br /&gt; &lt;br /&gt; /** &lt;br /&gt; * @brief Advertiser SID &lt;br /&gt; * &lt;br /&gt; * Only valid if not using the periodic advertising list &lt;br /&gt; * (BT_LE_PER_ADV_SYNC_OPT_USE_PER_ADV_LIST) &lt;br /&gt; */ &lt;br /&gt; uint8_t sid; &lt;br /&gt; &lt;br /&gt; /** Bit-field of periodic advertising sync options. */ &lt;br /&gt; uint32_t options; &lt;br /&gt; &lt;br /&gt; /** &lt;br /&gt; * @brief Maximum event skip &lt;br /&gt; * &lt;br /&gt; * Maximum number of periodic advertising events that can be &lt;br /&gt; * skipped after a successful receive. &lt;br /&gt; * Range: 0x0000 to 0x01F3 &lt;br /&gt; */ &lt;br /&gt; uint16_t skip; &lt;br /&gt; &lt;br /&gt; /&lt;strong&gt;** &lt;/strong&gt;&lt;br /&gt;&lt;strong&gt; * @brief Synchronization timeout (N * 10 ms) &lt;/strong&gt;&lt;br /&gt;&lt;strong&gt; * &lt;/strong&gt;&lt;br /&gt;&lt;strong&gt; * Synchronization timeout for the periodic advertising sync. &lt;/strong&gt;&lt;br /&gt;&lt;strong&gt; * Range 0x000A to 0x4000 (100 ms to 163840 ms) &lt;/strong&gt;&lt;br /&gt;&lt;strong&gt; */ &lt;/strong&gt;&lt;br /&gt;&lt;strong&gt; uint16_t timeout;&lt;/strong&gt; &lt;br /&gt;}; &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Can't get BLE extended connectable advertising timeout callback</title><link>https://devzone.nordicsemi.com/thread/485678?ContentTypeID=1</link><pubDate>Thu, 23 May 2024 15:39:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:762282e9-516f-4d6d-a276-dccd75bff93e</guid><dc:creator>Alex_S@Aperia</dc:creator><description>&lt;p&gt;&lt;span&gt;&amp;gt; From where do you see that this equals 10ms units?&amp;nbsp;&lt;/span&gt;&lt;br /&gt;From bluetooth.h. Perhaps I misunderstood the comments ?&lt;br /&gt;What should the unit be then ?&lt;br /&gt;&lt;br /&gt;struct bt_le_ext_adv_start_param { &lt;br /&gt; /** &lt;br /&gt; * &lt;strong&gt;@brief Advertiser timeout (N * 10 ms).&lt;/strong&gt; &lt;br /&gt; * &lt;br /&gt; * Application will be notified by the advertiser sent callback. &lt;br /&gt; * Set to zero for no timeout. &lt;br /&gt; * &lt;br /&gt; * When using high duty cycle directed connectable advertising then &lt;br /&gt; * this parameters must be set to a non-zero value less than or equal &lt;br /&gt; * to the maximum of @ref BT_GAP_ADV_HIGH_DUTY_CYCLE_MAX_TIMEOUT. &lt;br /&gt; * &lt;br /&gt; * If privacy @kconfig{CONFIG_BT_PRIVACY} is enabled then the timeout &lt;br /&gt; * must be less than @kconfig{CONFIG_BT_RPA_TIMEOUT}. &lt;br /&gt; */ &lt;br /&gt; uint16_t timeout; &lt;br /&gt; /** &lt;br /&gt; * @brief Number of advertising events. &lt;br /&gt; * &lt;br /&gt; * Application will be notified by the advertiser sent callback. &lt;br /&gt; * Set to zero for no limit. &lt;br /&gt; */ &lt;br /&gt; uint8_t num_events; &lt;br /&gt;}; &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Can't get BLE extended connectable advertising timeout callback</title><link>https://devzone.nordicsemi.com/thread/485041?ContentTypeID=1</link><pubDate>Tue, 21 May 2024 10:42:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b89e47a8-2c75-4f73-a18a-d26cd2ed80ca</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;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&amp;#39;re not seeing the timeout being trigged is because your define of the&amp;nbsp;BLE_CONN_ADV_TIMEOUT doesn&amp;#39;t really specify what the setting is. From where do you see that this equals 10ms units?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define BLE_CONN_ADV_TIMEOUT 4 * 100; // 4 sec in 10ms units&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Can't get BLE extended connectable advertising timeout callback</title><link>https://devzone.nordicsemi.com/thread/484789?ContentTypeID=1</link><pubDate>Thu, 16 May 2024 23:02:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1b45f959-a480-4acb-ad17-0bd78b18ad42</guid><dc:creator>Alex_S@Aperia</dc:creator><description>&lt;p&gt;Nah, looking at SDK code, the only place this&amp;nbsp;&lt;span&gt;BT_GAP_ADV_HIGH_DUTY_CYCLE_MAX_TIMEOUT is used is for direct high duty advertisement, mine is regular connectable advertisement, not direct)&lt;br /&gt;&lt;br /&gt;So, back to original question, why&amp;nbsp;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;param = BT_LE_EXT_ADV_START_PARAM(1000, 0);&lt;/pre&gt;&lt;br /&gt;&lt;strong&gt;doesn&amp;#39;t&amp;nbsp;generate&lt;/strong&gt; bt_le_ext_adv_cb.sent callback after 10 sec timeout, but&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;param = BT_LE_EXT_ADV_START_PARAM(0, 3);&lt;/pre&gt;&lt;br /&gt;&lt;strong&gt;does&lt;/strong&gt; after 3 adverisements sent&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Can't get BLE extended connectable advertising timeout callback</title><link>https://devzone.nordicsemi.com/thread/484769?ContentTypeID=1</link><pubDate>Thu, 16 May 2024 17:26:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1c2de5a6-69f5-44e8-bde1-590ba59306d5</guid><dc:creator>Alex_S@Aperia</dc:creator><description>&lt;p&gt;Perhaps this is my problem&lt;br /&gt;/* The maximum allowed high duty cycle directed advertising timeout, 1.28 &lt;br /&gt; * seconds in 10 ms unit. &lt;br /&gt; */ &lt;br /&gt;#define BT_GAP_ADV_HIGH_DUTY_CYCLE_MAX_TIMEOUT 128&lt;br /&gt;&lt;br /&gt; I&amp;#39;m trying much longer timeouts...&lt;br /&gt;&lt;br /&gt;Is there a way to translate timeout in seconds to number of events ?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>