<?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>Switching advertising type</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/33228/switching-advertising-type</link><description>I have seen that the recommended method for switching between connectable and non-connectable advertising is: 
 sd_ble_gap_adv_stop() ...change advertising structures as needed... sd_ble_gap_adv_start() 
 My app is doing this, and it works. But using</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 12 Apr 2018 08:50:58 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/33228/switching-advertising-type" /><item><title>RE: Switching advertising type</title><link>https://devzone.nordicsemi.com/thread/127984?ContentTypeID=1</link><pubDate>Thu, 12 Apr 2018 08:50:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:17a7cb55-0d51-4b18-be08-85496735d752</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Can you try the solution from&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/10015/how-to-confing-non-connectable-advertise" target="_blank" rel="noopener noreferrer"&gt; this post&lt;/a&gt;?&lt;/p&gt;
&lt;p&gt;I managed to run sd_ble_gap_adv_start(&amp;amp;adv_params, NULL)&amp;nbsp; &amp;nbsp; &amp;nbsp;(note that the second input is ignored when you use BLE_GAP_ADV_TYPE_ADV_NONCONN_IND)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I tried the following:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;ret_code_t non_conn_advertising(void)
{
    NRF_LOG_INFO(&amp;quot;non_conn_advertising()&amp;quot;);
    ret_code_t err_code;
    
    ble_gap_adv_params_t adv_params;
    memset(&amp;amp;adv_params, 0, sizeof(adv_params));
    adv_params.type         = BLE_GAP_ADV_TYPE_ADV_NONCONN_IND;
    adv_params.p_peer_addr  = NULL;
    adv_params.fp           = BLE_GAP_ADV_FP_ANY;
    adv_params.interval     = NON_CONNECTABLE_ADV_INTERVAL;
    adv_params.timeout      = NON_CONNECTABLE_ADV_TIMEOUT;
    
    err_code = sd_ble_gap_adv_start(&amp;amp;adv_params, NULL);
    NRF_LOG_INFO(&amp;quot;err_code = %d&amp;quot;, err_code);
    APP_ERROR_CHECK(err_code);
    
    return NRF_SUCCESS;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;And then I added err_code = non_conn_advertising(); within the BLE_GAP_EVT_CONNECTED event in ble_evt_handler(...)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I have not tried to sniff the advertising yet, but I saw that I could still find the device from nRF Connect for desktop while I was connected with my phone. (The rssi was still changing, but of course, I could not connect to it).&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Also note that NON_CONNECTABLE_ADV_INTERVAL must be larger than 160 (=100ms in units of 0.625).&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Switching advertising type</title><link>https://devzone.nordicsemi.com/thread/127920?ContentTypeID=1</link><pubDate>Wed, 11 Apr 2018 21:14:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4339f777-3630-4da8-ad3f-686a013fb3d4</guid><dc:creator>Lee Daniel Crocker</dc:creator><description>&lt;p&gt;Yes, I&amp;#39;m connected, because I do this inside the reply to BLE_GAP_EVT_CONNECTED. I stop advertising, then I change all the settings in m_adv_params to the non-connectable settings (including setting type to BLE_GAP_ADV_TYPE_NONCONN_IND), then restart advertising. That could well be the core of the issue--ble_advertising_start() takes the same ble_advertising_t structure as _init(), and that structure doesn&amp;#39;t seem to have any place for the advertising parameters that would set non-connectable type.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Switching advertising type</title><link>https://devzone.nordicsemi.com/thread/127729?ContentTypeID=1</link><pubDate>Wed, 11 Apr 2018 07:04:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0eef20e2-14bc-410c-b56d-417388b82fc5</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Ok,&lt;/p&gt;
&lt;p&gt;It looks like sd_ble_gap_adv_start(...) (in ble_advertising.c) returns 0x12 = NRF_ERROR_CONN_COUNT, yes.&lt;/p&gt;
&lt;p&gt;You can see the different return values for this function &lt;a href="http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.s132.api.v5.0.0%2Fgroup___b_l_e___g_a_p___f_u_n_c_t_i_o_n_s.html&amp;amp;anchor=ga241191b3fa20a5c20a60a088240a1dfa" target="_blank" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Are you in a connection when you stop and restart the advertising? The return value for this function says:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;NRF_ERROR_CONN_COUNT: The limit of available connections has been reached; connectable advertiser cannot be started.&lt;/em&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: Switching advertising type</title><link>https://devzone.nordicsemi.com/thread/127681?ContentTypeID=1</link><pubDate>Tue, 10 Apr 2018 17:05:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:47f0e71d-e415-45bd-808a-52c4fe03164a</guid><dc:creator>Lee Daniel Crocker</dc:creator><description>&lt;p&gt;I&amp;#39;m using SDK 14.2. Here&amp;#39;s a gdb stack trace (I have APP_ERROR_CHECK raise a breakpoint):&lt;/p&gt;
&lt;p&gt;#0 app_error_handler_bare (err_code=18) at /home/lee/work/argos/lib/nrf/sys_nrf.c:372&lt;br /&gt;#1 0x0002a20c in advertising_start (this=0x200043f8 &amp;lt;_ble_object&amp;gt;) at /home/lee/work/argos/lib/nrf/ble_nrf.c:165&lt;br /&gt;#2 0x0002a288 in on_connect (this=0x200043f8 &amp;lt;_ble_object&amp;gt;) at /home/lee/work/argos/lib/nrf/ble_nrf.c:185&lt;br /&gt;#3 0x0002a476 in ble_evt_handler (pevt=0x2000fd88, context=0x200043f8 &amp;lt;_ble_object&amp;gt;) at /home/lee/work/argos/lib/nrf/ble_nrf.c:208&lt;br /&gt;#4 0x000271d2 in nrf_sdh_ble_evts_poll (p_context=0x0) at /opt/Nordic/SDK14.2/components/softdevice/common/nrf_sdh_ble.c:285&lt;br /&gt;#5 0x000277d4 in nrf_sdh_evts_poll () at /opt/Nordic/SDK14.2/components/softdevice/common/nrf_sdh.c:378&lt;/p&gt;
&lt;p&gt;So it is ble_advertising_start() itself that&amp;#39;s returning error 0x12 (NRF_ERROR_CONN_COUNT ?).&lt;/p&gt;
&lt;p&gt;Perhaps it would be better to run my on_connect() handler with the scheduler?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Switching advertising type</title><link>https://devzone.nordicsemi.com/thread/127573?ContentTypeID=1</link><pubDate>Tue, 10 Apr 2018 09:20:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0147c274-7127-4103-94cd-b638ba12b855</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Your approach seems correct. Stop advertising, run another advertising_init() function where you change your advertising parameters, and start advertising again.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;When your project crashes, it might be that a function call, returning an err_code != NRF_SUCCESS is passed onto an APP_ERROR_CHECK(err_code), which will reboot your application. Can you try to define &amp;quot;DEBUG&amp;quot; in your preprocessor defines, turn off optimization, and try to set a breakpoint inside&amp;nbsp;app_error_handler(...) on line 65 approximately (depending on what SDK version you use), and see if you can find the .line_num, .p_file_name and .err_code that caused the error. What function call returned the err_code, and what was the err_code?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&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>