<?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>advertising duration (zephyr)</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/92656/advertising-duration-zephyr</link><description>Hi, 
 I would like to ask on where can I find or set the advertising duration or on how long the advertisement would last? 
 I am using zephyr, nrf52840DK. I want to be able to advertise for 30 seconds and then turn off the advertisement after 30 seconds</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 13 Oct 2022 07:17:42 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/92656/advertising-duration-zephyr" /><item><title>RE: advertising duration (zephyr)</title><link>https://devzone.nordicsemi.com/thread/390556?ContentTypeID=1</link><pubDate>Thu, 13 Oct 2022 07:17:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c9deb0e2-b7e7-4327-bd67-c8adb6f4370c</guid><dc:creator>Naeem Maroof</dc:creator><description>&lt;p&gt;Hi Oli,&lt;/p&gt;
[quote user="snowstorm "]As I understand, the above example code that you gave me is advertising once every second within the 30 seconds duration, is that right?[/quote]
&lt;p&gt;Yes, this is correct.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Naeem&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: advertising duration (zephyr)</title><link>https://devzone.nordicsemi.com/thread/390518?ContentTypeID=1</link><pubDate>Wed, 12 Oct 2022 19:46:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:97ec8d02-d9b4-4857-87ce-7ae60f3e5fd3</guid><dc:creator>Oli</dc:creator><description>&lt;p&gt;Hi Naeem,&lt;/p&gt;
&lt;p&gt;As I understand, the above example code that you gave me is advertising once every second within the 30 seconds duration, is that right?&lt;/p&gt;
&lt;p&gt;Can you show me how&amp;nbsp;to:&lt;/p&gt;
[quote userid="119245" url="~/f/nordic-q-a/92656/advertising-duration-zephyr/390416"]advertise 10 times in every second within 30 second duration[/quote]
&lt;p&gt;Thank you very much!&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;oli&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: advertising duration (zephyr)</title><link>https://devzone.nordicsemi.com/thread/390416?ContentTypeID=1</link><pubDate>Wed, 12 Oct 2022 11:17:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:28bfa288-cd8c-4a77-89d1-503a64c726ed</guid><dc:creator>Naeem Maroof</dc:creator><description>&lt;p&gt;Hi Oli,&lt;/p&gt;
&lt;p&gt;You requirement is not very clear to me.&amp;nbsp;If you want to advertise for 30 seconds then you also need to know how often you want to advertise.&amp;nbsp;For example, we can advertise once every second within 30 second duration.&amp;nbsp;Or we can also advertise 10 times in every second within 30 second duration.&amp;nbsp;Therefore, first you need to know how often you need to advertise.&lt;/p&gt;
&lt;p&gt;In the example code, the outer while loop is running forever, which means we are doing advertising forever (called periodic advertising). If you want to advertise for only 30 seconds or so, then you don&amp;#39; need while loop. Consider the following code (this should replace the complete while loop). This code uses a for loop to advertise for 30 seconds where we advertise once a second (as you can see there is delay of 1 second, and the loop control variable limit is 30).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;printk(&amp;quot;Starting advertising for 30 seconds...&amp;quot;);
err = bt_le_ext_adv_start(adv, BT_LE_EXT_ADV_START_DEFAULT);
if (err) {
    printk(&amp;quot;Failed to start extended advertising (err %d)\n&amp;quot;, err);
    return;
}
printk(&amp;quot;Done.\n&amp;quot;);

for (int i = 0; i &amp;lt; 30; i++) {
    k_sleep(K_SECONDS(1));
    mfg_data[2]++;
    printk(&amp;quot;Set Periodic Advertising Data...&amp;quot;);
    err = bt_le_per_adv_set_data(adv, ad, ARRAY_SIZE(ad));
    if (err) {
        printk(&amp;quot;Failed (err %d)\n&amp;quot;, err);
        return;
    }
    printk(&amp;quot;done.\n&amp;quot;);
}

printk(&amp;quot;Done with 30 seconds advertising...\n&amp;quot;);
printk(&amp;quot;Now stop extended advertising...&amp;quot;);
err = bt_le_ext_adv_stop(adv);
if (err) {
    printk(&amp;quot;Failed to stop extended advertising (err %d)\n&amp;quot;, err);
    return;
}
printk(&amp;quot;done.\n&amp;quot;);
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I hope you can extend / update as per your needs.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Naeem&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: advertising duration (zephyr)</title><link>https://devzone.nordicsemi.com/thread/390328?ContentTypeID=1</link><pubDate>Tue, 11 Oct 2022 19:47:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a7820961-1917-4e5a-990d-b5f075f1dcee</guid><dc:creator>Oli</dc:creator><description>&lt;p&gt;Hi Naeem,&lt;/p&gt;
&lt;p&gt;Thank you for this very informative answer. So, just to clarify, if I will modify&amp;nbsp;the sample, I&amp;nbsp;just have to change the delays to 30 seconds instead of 10 seconds?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;oli&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: advertising duration (zephyr)</title><link>https://devzone.nordicsemi.com/thread/389865?ContentTypeID=1</link><pubDate>Fri, 07 Oct 2022 15:46:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:13470b8f-f43b-48bb-8e8c-0cb8b52594ed</guid><dc:creator>Naeem Maroof</dc:creator><description>&lt;p&gt;Hi Oli,&lt;/p&gt;
&lt;p&gt;Thank you for contacting DevZone at NordicSemi.&lt;/p&gt;
&lt;p&gt;As per your query, you want to advertise for 30 seconds and then you want to turn advertisement off.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I would like to refer you to this excellent application example that has very good match with your requirements. It is called Periodic Advertising, and is located in &lt;strong&gt;/samples/bluetooth/periodic_adv&lt;/strong&gt;&amp;nbsp;in the Zephyr tree. (Link:&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/samples/bluetooth/periodic_adv/README.html"&gt;Bluetooth: Periodic Advertising — Zephyr Project Documentation (nordicsemi.com)&lt;/a&gt;&amp;nbsp;)&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Please build and flash it on your board, and see the output on the NRF terminal. As you explore this simple yet powerful example, you will see that:&lt;/p&gt;
&lt;p&gt;In the main() program:&lt;/p&gt;
&lt;p&gt;We have a while(true) loop / which means always do the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;we are enabling extended advertisement&lt;/li&gt;
&lt;li&gt;then we are doing periodic advertisement (3 times with 10 seconds delay)&lt;/li&gt;
&lt;li&gt;we are disabling extended advertisement&lt;/li&gt;
&lt;li&gt;delay for 10 seconds&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;As this loop repeats forever, you have control over both of the loops and the delay timings.&amp;nbsp;I hope you will like this and extend your project.&lt;/p&gt;
&lt;p&gt;Kind Regards,&lt;br /&gt;Naeem&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>