<?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 I change nRF5 bluetooth advertising interval dynamically?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/19074/can-i-change-nrf5-bluetooth-advertising-interval-dynamically</link><description>I would like to dynamically change bluetooth LE advertising interval. I am using nRF51 and nRF52, with SDK&amp;#39;s 8 and 12. Is that possible and how to do it? 
 Our application has kind of &amp;quot;interactive demo&amp;quot; mode needing short interval, but it dynamically</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 18 Jan 2017 15:09:23 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/19074/can-i-change-nrf5-bluetooth-advertising-interval-dynamically" /><item><title>RE: Can I change nRF5 bluetooth advertising interval dynamically?</title><link>https://devzone.nordicsemi.com/thread/73769?ContentTypeID=1</link><pubDate>Wed, 18 Jan 2017 15:09:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1f632e40-91b4-4aca-ac8d-cd12ad5eb53a</guid><dc:creator>Jarmo</dc:creator><description>&lt;p&gt;Okay, thank you very much about those hints! I think I can now implement the thing :)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Can I change nRF5 bluetooth advertising interval dynamically?</title><link>https://devzone.nordicsemi.com/thread/73768?ContentTypeID=1</link><pubDate>Wed, 18 Jan 2017 14:54:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:59d8a572-aa5b-48d6-b9f1-91863b20574f</guid><dc:creator>AmbystomaLabs</dc:creator><description>&lt;p&gt;Jarmo,
We developed our product in SDK11 and there wasn&amp;#39;t support for this built in.
However, you can do the same thing by just tying the advertising interval to a variable.&lt;/p&gt;
&lt;p&gt;So you init like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static void advertising_init(uint32_t adv_interval )
{ ...
		m_adv_params.interval = adv_interval;
...}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As Sigurd said you must first stop advertising:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;						err_code = sd_ble_gap_adv_stop();
						APP_ERROR_CHECK(err_code);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then init with whatever period you choose (here it is 3200*.625usec or 2second interval):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;						advertising_init(3200);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And finally start advertising:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;						err_code = sd_ble_gap_adv_start(&amp;amp;m_adv_params);
						APP_ERROR_CHECK(err_code);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I should caution you that the power requirements to re-init and re-start advertising are substantial. If your coin cell is already mostly depleted the device may well brown out and reboot.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Can I change nRF5 bluetooth advertising interval dynamically?</title><link>https://devzone.nordicsemi.com/thread/73766?ContentTypeID=1</link><pubDate>Wed, 18 Jan 2017 13:25:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:26522d27-4005-4344-95e1-8453caaa288d</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;If you want to go back to fast mode, you have to first temporarily stop the advertising, and then start in fast mode again.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;err_code = sd_ble_gap_adv_stop();
err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Can I change nRF5 bluetooth advertising interval dynamically?</title><link>https://devzone.nordicsemi.com/thread/73767?ContentTypeID=1</link><pubDate>Wed, 18 Jan 2017 12:54:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:526ddde3-1ff4-484f-9ea3-23edcbb9dd99</guid><dc:creator>Jarmo</dc:creator><description>&lt;p&gt;Okay, thanks for that. However, the code from SDK8 doesn&amp;#39;t seem to support that.&lt;/p&gt;
&lt;p&gt;Also, if I want to get bak from slow mode to fast mode, how to do that?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Can I change nRF5 bluetooth advertising interval dynamically?</title><link>https://devzone.nordicsemi.com/thread/73765?ContentTypeID=1</link><pubDate>Wed, 18 Jan 2017 10:37:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:19d3584b-f931-48c1-878f-1c5a9d01418b</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The advertising module have two different modes you can use for this. &lt;code&gt;ADV_MODE_FAST&lt;/code&gt; and &lt;code&gt;ADV_MODE_SLOW&lt;/code&gt;, and you can specify the advertising interval you want for each mode.
The advertising will start in &lt;code&gt;ADV_MODE_FAST&lt;/code&gt;, and switch to &lt;code&gt;ADV_MODE_SLOW&lt;/code&gt; after a specified timeout period(&lt;code&gt;APP_ADV_FAST_TIMEOUT_IN_SECONDS&lt;/code&gt;). The &lt;code&gt;ADV_MODE_SLOW&lt;/code&gt; also has a timeout period, and when expired it will switch to &lt;code&gt;ADV_MODE_IDLE&lt;/code&gt; and stop advertising.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;ble_adv_modes_config_t options;
memset(&amp;amp;options, 0, sizeof(options));

options.ble_adv_fast_enabled  = true;
options.ble_adv_fast_interval = APP_ADV_FAST_INTERVAL;
options.ble_adv_fast_timeout  = APP_ADV_FAST_TIMEOUT_IN_SECONDS;

options.ble_adv_slow_enabled  = true;
options.ble_adv_slow_interval = APP_ADV_SLOW_INTERVAL;
options.ble_adv_slow_timeout  = APP_ADV_SLOW_TIMEOUT_IN_SECONDS;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;With limited discoverable mode(&lt;code&gt;BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE&lt;/code&gt;) it is not allowed to advertise longer than the timeout period. But if you don&amp;#39;t want the advertising to stop in the &lt;code&gt;ADV_MODE_SLOW&lt;/code&gt; mode, you can switch to general discoverable mode(&lt;code&gt;BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE&lt;/code&gt;), and set the timeout to 0 to do unlimited advertising:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;advdata.flags                 = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
options.ble_adv_slow_timeout  = 0;
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>