<?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>SDK 15.3.0: Restart Non-Connectable Advertising after Timeout</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/47391/sdk-15-3-0-restart-non-connectable-advertising-after-timeout</link><description>The objective is to have a device which constantly advertises some status information - this must be always visible to any Central in range. 
 The device may connect to at most one Central - but must continue to advertise the status information while</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 24 Jun 2019 22:09:08 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/47391/sdk-15-3-0-restart-non-connectable-advertising-after-timeout" /><item><title>RE: SDK 15.3.0: Restart Non-Connectable Advertising after Timeout</title><link>https://devzone.nordicsemi.com/thread/194469?ContentTypeID=1</link><pubDate>Mon, 24 Jun 2019 22:09:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7b6dd0b2-bdc0-491e-b3fb-c85cbade696c</guid><dc:creator>awneil</dc:creator><description>[quote userid="26263" url="~/f/nordic-q-a/47391/sdk-15-3-0-restart-non-connectable-advertising-after-timeout/194468"]Did you&amp;nbsp;end up making any changes to ble_advertising.c? [/quote]
&lt;p&gt;I don&amp;#39;t think so.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SDK 15.3.0: Restart Non-Connectable Advertising after Timeout</title><link>https://devzone.nordicsemi.com/thread/194468?ContentTypeID=1</link><pubDate>Mon, 24 Jun 2019 21:57:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:59b452e3-3abb-4ae7-8dce-4f4980e34b49</guid><dc:creator>Eric</dc:creator><description>&lt;p&gt;Hi Awneil, &lt;br /&gt;I&amp;#39;m also getting&amp;nbsp;NRF_ERROR_INVALID_PARAM after using your fix. Did you&amp;nbsp;end up making any changes to ble_advertising.c? What advertising interval&amp;nbsp;APP_ADV_INTERVAL did you use?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SDK 15.3.0: Restart Non-Connectable Advertising after Timeout</title><link>https://devzone.nordicsemi.com/thread/192273?ContentTypeID=1</link><pubDate>Wed, 12 Jun 2019 08:56:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4a82d668-3ab6-4d1b-992f-1612bb5dd2ca</guid><dc:creator>awneil</dc:creator><description>[quote userid="6462" url="~/f/nordic-q-a/47391/sdk-15-3-0-restart-non-connectable-advertising-after-timeout"]It is an unhelpful Error code as it give no help in identifying &lt;em&gt;which&lt;/em&gt; parameter was invalid, nor&amp;nbsp;&lt;em&gt;how&lt;/em&gt; it was invalid[/quote]
&lt;p&gt;See also:&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/48490/graceful-recovery-from-bluetooth-errors/192270#192270"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/48490/graceful-recovery-from-bluetooth-errors/192270#192270&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SDK 15.3.0: Restart Non-Connectable Advertising after Timeout</title><link>https://devzone.nordicsemi.com/thread/188008?ContentTypeID=1</link><pubDate>Mon, 20 May 2019 14:51:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f9957dc1-3144-410e-995e-b3bd62bcd555</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;&lt;span&gt;Hi,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thank you for the feedback.&lt;/span&gt;&lt;/p&gt;
[quote userid="6462" url="~/f/nordic-q-a/47391/sdk-15-3-0-restart-non-connectable-advertising-after-timeout/187697"]The trouble is, there are now no examples of how to do advertising &amp;quot;manually&amp;quot;, and&amp;nbsp;&lt;span&gt;the Advertising module obfuscates it all so much that it&amp;#39;s hard to pull the relevant details out.&lt;/span&gt;[/quote]
&lt;p&gt;The ble_app_beacon and&amp;nbsp;ble_app_blinky examples does not use the advertising module.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SDK 15.3.0: Restart Non-Connectable Advertising after Timeout</title><link>https://devzone.nordicsemi.com/thread/187697?ContentTypeID=1</link><pubDate>Fri, 17 May 2019 16:18:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ab020c04-4db0-473a-bbb4-5f6cf33e9320</guid><dc:creator>awneil</dc:creator><description>[quote userid="6462" url="~/f/nordic-q-a/47391/sdk-15-3-0-restart-non-connectable-advertising-after-timeout/187695"]my final solution[/quote]
&lt;p&gt;I guess the real solution is to just not use the Advertising module at all.&lt;/p&gt;
&lt;p&gt;It&amp;#39;s&amp;nbsp;fine when it works but, when you want to do something a little different, it&amp;#39;s an absolute pain in the behind!&lt;/p&gt;
&lt;p&gt;&lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f61e.svg" title="Disappointed"&gt;&amp;#x1f61e;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;The trouble is, there are now no examples of how to do advertising &amp;quot;manually&amp;quot;, and&amp;nbsp;&lt;span&gt;the Advertising module obfuscates it all so much that it&amp;#39;s hard to pull the relevant details out.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f61e.svg" title="Disappointed"&gt;&amp;#x1f61e;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SDK 15.3.0: Restart Non-Connectable Advertising after Timeout</title><link>https://devzone.nordicsemi.com/thread/187695?ContentTypeID=1</link><pubDate>Fri, 17 May 2019 16:01:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fec11b11-d4fb-4d8b-8453-5e8abbb679b0</guid><dc:creator>awneil</dc:creator><description>[quote userid="6462" url="~/f/nordic-q-a/47391/sdk-15-3-0-restart-non-connectable-advertising-after-timeout"]None of the parameters should have changed[/quote]
&lt;p&gt;Oh - if only it were that simple!&lt;/p&gt;
&lt;p&gt;But no - the Advertising module has to mess with the settings!&lt;/p&gt;
&lt;p&gt;Thanks to&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/members/niclas-heitz"&gt;Niclas Heitz&lt;/a&gt;&amp;nbsp;- who did a write-up on some of this:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/37233/ble_advertising_init-returning-nrf_error_invalid_param-for-parameters-set-by-the-function-itself/145212#145212"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/37233/ble_advertising_init-returning-nrf_error_invalid_param-for-parameters-set-by-the-function-itself/145212#145212&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;This pointed me to the fact that the Advertising Interval gets trashed:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;lt;info&amp;gt; app: Connectable advertising
&amp;lt;info&amp;gt; app: Fast advertising.
&amp;lt;debug&amp;gt; app: ADV: GAP Conn
&amp;lt;info&amp;gt; app: GAP Conn
&amp;lt;info&amp;gt; app: Non-connectable, Non-scannable advertising; Handle 0; interval 300
&amp;lt;debug&amp;gt; app: ADV: Conn Parm Upd
&amp;lt;debug&amp;gt; app: ADV: Term
&amp;lt;info&amp;gt; app: Adv Tmo: Conn Hdl 0000; Adv Hdl 0; Mnf01
&amp;lt;info&amp;gt; app: Non-connectable, Non-scannable advertising; Handle 0; interval 0
&amp;lt;error&amp;gt; app: ERROR 7 [NRF_ERROR_INVALID_PARAM] at main.c:790
PC at: 0x000313A1
&amp;lt;error&amp;gt; app: End of error report
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Fixing that, the Non-connectable advertising would re-start once - but then never time out.&lt;/p&gt;
&lt;p&gt;Which suggested that the Advertising Duration was also getting trashed:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;lt;info&amp;gt; app: Connectable advertising
&amp;lt;info&amp;gt; app: Fast advertising.
&amp;lt;debug&amp;gt; app: ADV: GAP Conn
&amp;lt;info&amp;gt; app: GAP Conn
&amp;lt;info&amp;gt; app: Non-connectable, Non-scannable advertising: Hdl 0; Int 300; Dur 3000
&amp;lt;debug&amp;gt; app: ADV: Conn Parm Upd
&amp;lt;debug&amp;gt; app: ADV: Term
&amp;lt;info&amp;gt; app: Adv Tmo: Conn Hdl 0000; Adv Hdl 0; Mnf01
&amp;lt;info&amp;gt; app: Non-connectable, Non-scannable advertising: Hdl 0; Int 0; Dur 0
&amp;lt;error&amp;gt; app: ERROR 7 [NRF_ERROR_INVALID_PARAM] at main.c:781
PC at: 0x00031397
&amp;lt;error&amp;gt; app: End of error report
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;But fixing that just led to a different error:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;lt;info&amp;gt; app: Connectable advertising
&amp;lt;info&amp;gt; app: Fast advertising.
&amp;lt;debug&amp;gt; app: ADV: GAP Conn
&amp;lt;info&amp;gt; app: GAP Conn
&amp;lt;info&amp;gt; app: Non-connectable, Non-scannable advertising: Hdl 0; Int 300; Dur 3000
&amp;lt;debug&amp;gt; app: ADV: Conn Parm Upd
&amp;lt;debug&amp;gt; app: ADV: Term
&amp;lt;info&amp;gt; app: Adv Tmo: Conn Hdl 0000; Adv Hdl 0; Mnf01
&amp;lt;info&amp;gt; app: Non-connectable, Non-scannable advertising: Hdl 0; Int 0; Dur 0
&amp;lt;debug&amp;gt; app: ADV_SET_TERMINATED: start result 0
&amp;lt;info&amp;gt; app: ADV_SET_TERM.
&amp;lt;debug&amp;gt; app: ADV: Term
&amp;lt;debug&amp;gt; app: ADV_SET_TERMINATED: start result 18
&amp;lt;info&amp;gt; app: ADV_SET_TERM.
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The &amp;quot;&lt;strong&gt;ADV_SET_TERMINATED: start result 18&lt;/strong&gt;&amp;quot; comes from on_terminated() in ble_advertising.c:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void on_terminated(ble_advertising_t * const p_advertising, ble_evt_t const * p_ble_evt)
{
    ret_code_t ret;

    if (p_ble_evt-&amp;gt;header.evt_id != BLE_GAP_EVT_ADV_SET_TERMINATED)
    {
        // Nothing to do.
        NRF_LOG_DEBUG( &amp;quot;!ADV_SET_TERMINATED&amp;quot; );
        return;
    }

    if (  p_ble_evt-&amp;gt;evt.gap_evt.params.adv_set_terminated.reason == BLE_GAP_EVT_ADV_SET_TERMINATED_REASON_TIMEOUT
        ||p_ble_evt-&amp;gt;evt.gap_evt.params.adv_set_terminated.reason == BLE_GAP_EVT_ADV_SET_TERMINATED_REASON_LIMIT_REACHED)
    {
        // Start advertising in the next mode.
        ret = ble_advertising_start(p_advertising, adv_mode_next_get(p_advertising-&amp;gt;adv_mode_current));

        NRF_LOG_DEBUG( &amp;quot;ADV_SET_TERMINATED: start result %d&amp;quot;, ret );   // &amp;lt;&amp;lt;&amp;lt;&amp;lt; HERE !!

        if ((ret != NRF_SUCCESS) &amp;amp;&amp;amp; (p_advertising-&amp;gt;error_handler != NULL))
        {
            p_advertising-&amp;gt;error_handler(ret);
        }
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The 18 is&amp;nbsp;NRF_ERROR_CONN_COUNT: so the Advertising module has trashed the setting to do Non-connectable advertising - and, instead, is trying to start Connectable advertising!!&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;So my final solution is:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void non_connectable_advertising_start(void)
{
    uint32_t    err_code;
    ble_gap_adv_params_t  adv_params;

    memcpy(&amp;amp;adv_params, &amp;amp;m_advertising.adv_params, sizeof(adv_params));

#if 0
    NRF_LOG_INFO( &amp;quot;Non-connectable, Scannable advertising&amp;quot; );
    adv_params.properties.type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_SCANNABLE_UNDIRECTED;
#else
    NRF_LOG_INFO( &amp;quot;Non-connectable, Non-scannable advertising: Hdl %d; Int %d; Dur %d&amp;quot;, m_advertising.adv_handle, m_advertising.adv_params.interval, m_advertising.adv_params.duration );
    adv_params.properties.type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED;
#endif

    // Restore parameters which get trashed by the Advertising module
    adv_params.duration = APP_ADV_DURATION;
    adv_params.interval = APP_ADV_INTERVAL;

    // Don&amp;#39;t let the Advertising module think it&amp;#39;s got somewhere else in its advertising sequence
    m_advertising.adv_mode_current = BLE_ADV_MODE_FAST;

    err_code = sd_ble_gap_adv_set_configure(&amp;amp;m_advertising.adv_handle,
                                            &amp;amp;m_advertising.adv_data,
                                            &amp;amp;adv_params);
    APP_ERROR_CHECK(err_code);

    err_code = sd_ble_gap_adv_start(m_advertising.adv_handle, m_advertising.conn_cfg_tag);
    APP_ERROR_CHECK(err_code);
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>