<?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>Bluetooth advertising timeout needs to be modified</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/96163/bluetooth-advertising-timeout-needs-to-be-modified</link><description>I am creating proof of concept software using a nRF52840 Dev Kit. The code is based on the Nordic UART Service example which uses Zephyr, but has been substantially modified to suit the application. 
 I use &amp;quot;bt_le_adv_start&amp;quot; to begin Bluetooth advertising</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 03 Feb 2023 09:05:45 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/96163/bluetooth-advertising-timeout-needs-to-be-modified" /><item><title>RE: Bluetooth advertising timeout needs to be modified</title><link>https://devzone.nordicsemi.com/thread/407923?ContentTypeID=1</link><pubDate>Fri, 03 Feb 2023 09:05:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:25d81627-c827-48ee-84b7-806946713643</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello Craig,&lt;/p&gt;
&lt;p&gt;Glad to hear it sorted out. I didn&amp;#39;t test it, but I can&amp;#39;t tell why it didn&amp;#39;t work with your implementation of the ad[] struct. Perhaps there is something with the way the data parameter is set. It is the fact that the data variable inside ad[] is a pointer that is throwing you off, I think (at least it throws me off).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You can try doing something like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;    uint8_t test_data[1] = {BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR};
    test_ad[0].type = BT_DATA_FLAGS;
    test_ad[0].data_len = 1u;
    test_ad[0].data = test_data;
    LOG_INF(&amp;quot;test_ad[0] = 0x%02x&amp;quot;, test_ad-&amp;gt;data[0]);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I tried the way that you did initially, and it printed &amp;quot;test_ad[0] = 01&amp;quot;, which will trigger the timeout since 0x01 = BT_LE_AD_LIMITED (and also your flags will be wrong).&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bluetooth advertising timeout needs to be modified</title><link>https://devzone.nordicsemi.com/thread/407878?ContentTypeID=1</link><pubDate>Fri, 03 Feb 2023 04:23:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:641aea87-848e-4546-96bf-690a448d3d05</guid><dc:creator>craig.goldman</dc:creator><description>&lt;p&gt;Testing done.&lt;/p&gt;
&lt;p&gt;I put a breakpoint in after &amp;quot;ad_is_limited(ad, ad_len)&amp;quot;.&amp;nbsp; The function is returning &amp;#39;true&amp;#39;.&amp;nbsp; When I examined the variable holding the advertising data, it looked wrong.&lt;/p&gt;
&lt;p&gt;I modified the code to follow your suggestion and used &amp;quot;BT_DATA_BYTES&amp;quot; macro to load the struct bt_data with the advertising flags.&amp;nbsp; RE-tested the code and Bluetooth no longer times out.&lt;/p&gt;
&lt;p&gt;Edvin, thank you for help.&lt;/p&gt;
&lt;p&gt;This case can be closed.&lt;/p&gt;
&lt;p&gt;-Craig&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bluetooth advertising timeout needs to be modified</title><link>https://devzone.nordicsemi.com/thread/407830?ContentTypeID=1</link><pubDate>Thu, 02 Feb 2023 15:02:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:162843f8-692b-4374-9e36-629cc5c303c6</guid><dc:creator>craig.goldman</dc:creator><description>&lt;p&gt;Edvin,&lt;/p&gt;
&lt;p&gt;That is an excellent suggestion.&amp;nbsp; There may be a one-day delay in getting this done, since I am committed to a meeting most of the day.&lt;/p&gt;
&lt;p&gt;-Craig&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bluetooth advertising timeout needs to be modified</title><link>https://devzone.nordicsemi.com/thread/407719?ContentTypeID=1</link><pubDate>Thu, 02 Feb 2023 09:49:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:94d3721f-c3d6-4a37-bbc0-ef8a14a68307</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;It looks like this format is a bit different to how it is implemented in our samples. It may work just fine, but it is difficult for me to say exactly why it behaves like it does based on this snippet. Can you please try to debug/add logging to see whether ad_is_limited() returns true inside bt_le_adv_start()?&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;	if (ad_is_limited(ad, ad_len)) {
		k_work_init_delayable(&amp;amp;adv-&amp;gt;lim_adv_timeout_work, adv_timeout);
		k_work_reschedule(&amp;amp;adv-&amp;gt;lim_adv_timeout_work,
				  K_SECONDS(CONFIG_BT_LIM_ADV_TIMEOUT));
	}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I suggest you figure out why the timer is started (lim_adv_timeout_work, adv_timeout), rather than figuring out whether it is restarted.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;As far as I can tell,&amp;nbsp;bt_le_adv_update_data() doesn&amp;#39;t start/restart the advertising. It just updates the data that is used for advertising, so I don&amp;#39;t think this will reset any timers.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The only way I see that &amp;quot;Failed to stop advertising&amp;quot; is printed to the log is inside&amp;nbsp;adv_timeout(), and the only way this is triggered is from&amp;nbsp;k_work_init_delayable(&amp;amp;adv-&amp;gt;lim_adv_timeout_work, adv_timeout); inside the check for ad_is_limited().&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bluetooth advertising timeout needs to be modified</title><link>https://devzone.nordicsemi.com/thread/407624?ContentTypeID=1</link><pubDate>Wed, 01 Feb 2023 16:27:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c7d0094b-57bf-4051-b4b0-194512be4d71</guid><dc:creator>craig.goldman</dc:creator><description>&lt;p&gt;Thank you for the respone but I don&amp;#39;t use BT_LE_AD_LIMITED - just&amp;nbsp;&lt;span&gt;BT_LE_AD_GENERAL and BT_LE_AD_NO_BREDR&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;My advertising data looks like the following...&lt;br /&gt; advertData[0].type = BT_DATA_FLAGS;&lt;br /&gt; advertData[0].data_len = 1u;&lt;br /&gt; advertData[0].data = (const void*)(BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR);&lt;br /&gt; advertData[1].type = BT_DATA_NAME_COMPLETE;&lt;br /&gt; advertData[1].data_len = 7u;&lt;br /&gt; advertData[1].data = &amp;quot;Sensor&amp;quot;;&lt;/p&gt;
&lt;p&gt;(The actual device name string in the application is constucted from using the device serial number.)&lt;/p&gt;
&lt;p&gt;I would rather disable the timeout, but other less desirable solutions could be used.&lt;br /&gt;Do you know if the timeout re-starts if I periodically call&amp;nbsp;&lt;span&gt;&amp;quot;bt_le_adv_update_data&amp;quot;?&lt;br /&gt;Is there a callback on advetising stop which I could use to re-start the advertising?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;-Craig&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bluetooth advertising timeout needs to be modified</title><link>https://devzone.nordicsemi.com/thread/407576?ContentTypeID=1</link><pubDate>Wed, 01 Feb 2023 14:12:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8626069f-270a-4435-ae78-b681e74fa38b</guid><dc:creator>Edvin</dc:creator><description>[quote user="craig.goldman"]The Noridic SDK allow the programmer to define advertising modes which include how timeout is handled.&lt;br /&gt;(&amp;quot;ble_advertising_config&amp;quot;).[/quote]
&lt;p&gt;Ah, you are talking about the nRF5 SDK when you say &amp;quot;Nordic SDK&amp;quot;. I understand. (In some cases Nordic SDK can mean nRF Connect SDK, while Zephyr SDK is referred to as the pure Zephyr SDK (which is a standalone code base without nRF Connect SDK).&lt;/p&gt;
&lt;p&gt;Regarding your question:&lt;/p&gt;
&lt;p&gt;I see. This is not triggered in most (any?) of our samples, but I see that there is a timeout functionality that is started in&amp;nbsp;bt_le_adv_start() if ad_is_limited() returns true. This returns true if the BT_LE_AD_LIMITED flag is set.&lt;/p&gt;
&lt;p&gt;So if your advertising data is set up something like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static const struct bt_data ad[] = {
	BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_LIMITED | BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
	BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),
};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Try to remove the BT_LE_AD_LIMITED, so that you are left with this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static const struct bt_data ad[] = {
	BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
	BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),
};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Then, the advertisements will not time out. Alternatively, if you want to change the duration of the timeout you can either leave the BT_LE_AD_LIMITED in, and configure the timeout by adding this config to your prj.conf:&lt;/p&gt;
&lt;p&gt;CONFIG_BT_LIM_ADV_TIMEOUT 60&lt;/p&gt;
&lt;p&gt;(change 60 with the number of seconds you want to use. The range is 1 to 180 seconds).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you want something longer than 180 seconds, you should remove the BT_LE_AD_LIMITED, and start a timer to stop the advertisements manually.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The log warning &amp;quot;Failed to stop advertising: 0&amp;quot; looks very much like a bug from Zephyr. It looks like it was supposed to check the return value (err) before printing that. If it is printed with the value 0, it means that it successfully stopped the advertisements.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bluetooth advertising timeout needs to be modified</title><link>https://devzone.nordicsemi.com/thread/407424?ContentTypeID=1</link><pubDate>Tue, 31 Jan 2023 18:51:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:49c6c66b-2afd-44e5-85b6-1a05e78c9978</guid><dc:creator>craig.goldman</dc:creator><description>&lt;p&gt;Unfortuantely, the application requires specialized hardware connected to the nRF52840 to run; it is also 1000&amp;#39;s of lines of code (not including SDK and Zephyr library files) spread over 56 files.&lt;br /&gt;If needed, I can send the file which calls &amp;quot;bt_le-adv_start&amp;quot;.&lt;/p&gt;
&lt;p&gt;I believe advertsiing has stopped for two reasons&lt;br /&gt;* I am using the J-Link RTT Viewer to monitor code logging.&lt;br /&gt;&amp;nbsp; I get the following log entry:&amp;nbsp;00&amp;gt; [00:00:54.335,479] &amp;lt;wrn&amp;gt; bt_adv: Failed to stop advertising: 0&lt;br /&gt;&amp;nbsp; The source of this is in &amp;quot;adv.c&amp;quot; following a call to &amp;quot;bt_le_adv_stop&amp;quot;; the error code of 0 indicates success&lt;br /&gt;&amp;nbsp; (BTW this is a really poor debugging message to get on success.)&lt;br /&gt;* I am using NRF Connect App running on an iPAD to monitor advertsing and to connect to the running code.&lt;br /&gt;&amp;nbsp; If I start NRF Connect after I get the warning message, I view no advetrtisements from the device.&lt;br /&gt;&amp;nbsp; If I start NRF Connect earlier, I can see the bluetooth advertisements on NRF Connect screen.&lt;/p&gt;
&lt;p&gt;The Noridic SDK allow the programmer to define advertising modes which include how timeout is handled.&lt;br /&gt;(&amp;quot;ble_advertising_config&amp;quot;).&amp;nbsp; I was referring to the documentation for &amp;quot;ble_advertising_start&amp;quot; which can select one of those modes.&amp;nbsp; I do not see an API specifically for changing the advertising timeout.&lt;/p&gt;
&lt;p&gt;Please remember that I am starting bluetooth advertising using &lt;span&gt;&amp;quot;bt_le_adv_start&amp;quot;, which is a Zephyr library call.&lt;br /&gt;This was used in the Nordic UART Service example I followed to create the application.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thank you&lt;br /&gt;-Craig&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bluetooth advertising timeout needs to be modified</title><link>https://devzone.nordicsemi.com/thread/407307?ContentTypeID=1</link><pubDate>Tue, 31 Jan 2023 12:00:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7bf41118-f0ec-4622-aa9f-1726cb6eeaf5</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;By default the BLE advertisements doesn&amp;#39;t time out in NCS (unless that changed recently). Are you sure they time out? How do you know that it does? What do you observe? Is it possible to send the application that you are currently working on so that I can have a look?&lt;/p&gt;
[quote user=""]I&amp;#39;ve noticed that the Nordic SDK has functions which allow for changing of the timeout value; can I mix Zephyr API calls and Nordic SDK API calls?[/quote]
&lt;p&gt;What API do you refer to?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>