<?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>Advertise &amp;#39;Connected&amp;#39; when connected</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/49872/advertise-connected-when-connected</link><description>Hello, 
 we are developing an asset tracking solution. The Noridic send out BLE Advertisements to show, that they are still available. These signals are received by Receivers in the room. So far, so common. 
 The special thing in our case is, that the</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 17 Jul 2019 16:47:07 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/49872/advertise-connected-when-connected" /><item><title>RE: Advertise 'Connected' when connected</title><link>https://devzone.nordicsemi.com/thread/199070?ContentTypeID=1</link><pubDate>Wed, 17 Jul 2019 16:47:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5acce275-2de7-4ce4-aba3-8152eef75bee</guid><dc:creator>awneil</dc:creator><description>[quote userid="52812" url="~/f/nordic-q-a/49872/advertise-connected-when-connected/199069"]Maybe you can give me a hint, why I have to keep it scannable[/quote]
&lt;p&gt;No Idea!&lt;/p&gt;
&lt;p&gt;I did encounter the&amp;nbsp;&lt;span&gt;NRF_ERROR_CONN_COUNT in my travels,&amp;nbsp;but it seemed to be due to doing &lt;em&gt;connectable&lt;/em&gt; advertising - which makes sense.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Advertise 'Connected' when connected</title><link>https://devzone.nordicsemi.com/thread/199069?ContentTypeID=1</link><pubDate>Wed, 17 Jul 2019 16:39:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ed68ecd1-bcd4-40a6-bc03-6ba6bc311d62</guid><dc:creator>balomueller</dc:creator><description>&lt;p&gt;It is working! Yeay!&lt;/p&gt;
&lt;p&gt;I completely removed the code for Manufacturer Specific Data, so that was not the problem.&lt;/p&gt;
&lt;p&gt;I had to make a memcpy of advdata and store it as m_advdata. That way, I could re-add the call to&amp;nbsp;ble_advdata_encode().&lt;/p&gt;
&lt;p&gt;Then I had the error&amp;nbsp;NRF_ERROR_CONN_COUNT at&amp;nbsp;sd_ble_gap_adv_start(). I solved that by changing&amp;nbsp;&lt;br /&gt;BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED &lt;br /&gt;to&amp;nbsp;&lt;br /&gt;BLE_GAP_ADV_TYPE_NONCONNECTABLE_SCANNABLE_UNDIRECTED. &lt;br /&gt;Maybe you can give me a hint, why I have to keep it scannable.&lt;/p&gt;
&lt;p&gt;But still, it is good enough for the customer presentation tomorrow! Puh! &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f60a.svg" title="Blush"&gt;&amp;#x1f60a;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Advertise 'Connected' when connected</title><link>https://devzone.nordicsemi.com/thread/199058?ContentTypeID=1</link><pubDate>Wed, 17 Jul 2019 15:52:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:be33ecbb-9ed0-4e0e-b5e2-8d3e25c58366</guid><dc:creator>awneil</dc:creator><description>[quote userid="52812" url="~/f/nordic-q-a/49872/advertise-connected-when-connected/199055"]Could you please also share that code? [/quote]
&lt;p&gt;Sorry, no. But I don&amp;#39;t think it would help - it&amp;#39;s just a flag in a set of entirely proprietary data.&lt;/p&gt;
[quote userid="52812" url="~/f/nordic-q-a/49872/advertise-connected-when-connected/199055"]Can you help, how I can track that error down[/quote]
&lt;p&gt;Sadly not.&lt;/p&gt;
&lt;p&gt;It&amp;#39;s a very unhelpful code from Nordic:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/49799/issue-regarding-nrf52840-long-range-mode/198921#198921"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/49799/issue-regarding-nrf52840-long-range-mode/198921#198921&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;So it&amp;#39;s a matter of guesswork, trial &amp;amp; error to work out exactly which parameter is &amp;quot;invalid&amp;quot;, and what is &amp;quot;invalid&amp;quot; about it.&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;I guess it must still be wanting something to do with the&amp;nbsp;&lt;span&gt;Manufacturer Specific Data ... ?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Advertise 'Connected' when connected</title><link>https://devzone.nordicsemi.com/thread/199055?ContentTypeID=1</link><pubDate>Wed, 17 Jul 2019 15:31:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0b5473da-cb73-44dd-991c-345efb30c045</guid><dc:creator>balomueller</dc:creator><description>&lt;p&gt;Thanks a lot @awneil. Your&amp;nbsp;code is very helpful!&amp;nbsp;&lt;/p&gt;
&lt;p&gt;What I did:&lt;br /&gt;- I replaced my advertising_start() with yours.&lt;br /&gt;- I added a call to advertising_start() on connected in&amp;nbsp;ble_evt_handler()&lt;br /&gt;- I commented out the calls that change the Manufacturer Specific Data (set_adv_mfr_spec_busy and ble_advdata_encode). Could you please also share that code? That would be very helpful. I&amp;#39;m using&amp;nbsp;ble_advertising_advdata_update() right now, which is not very satisfying.&lt;/p&gt;
&lt;p&gt;Result:&lt;br /&gt;- Advertisement starts&lt;br /&gt;- When connected, a&amp;nbsp;NRF_ERROR_INVALID_PARAM occurs on&amp;nbsp;sd_ble_gap_adv_start() in advertising_start().&lt;/p&gt;
&lt;p&gt;Can you help, how I can track that error down?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Advertise 'Connected' when connected</title><link>https://devzone.nordicsemi.com/thread/198912?ContentTypeID=1</link><pubDate>Wed, 17 Jul 2019 10:00:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4d988784-c2ab-479a-9e97-05ddfda63cdf</guid><dc:creator>awneil</dc:creator><description>&lt;p&gt;As noted in the other thread,&amp;nbsp;&lt;span&gt;the Advertising Module doesn&amp;#39;t support non-connectable - so you have to do that bit manually.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;You can still use&amp;nbsp;the Advertising Module to do your &amp;quot;normal&amp;quot;&amp;nbsp; (connectable) advertising (&lt;/span&gt;&lt;span&gt;I use&amp;nbsp;the Advertising Module to&amp;nbsp;initially start advertising).&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp;In my BLE Event Handler, I have:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/**@brief Function for handling BLE events.
 *
 * @param[in]   p_ble_evt   Bluetooth stack event.
 * @param[in]   p_context   Unused.
 */
static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
{
    ret_code_t err_code = NRF_SUCCESS;

    switch (p_ble_evt-&amp;gt;header.evt_id)
    {
        case BLE_GAP_EVT_DISCONNECTED:
            NRF_LOG_INFO(&amp;quot;GAP EV: Disconnected.&amp;quot;);

            g_conn_handle = BLE_CONN_HANDLE_INVALID;

            advertising_stop();
            advertising_start();
            break;

        case BLE_GAP_EVT_CONNECTED:
            NRF_LOG_INFO(&amp;quot;GAP EV: Connected.&amp;quot;);

            g_conn_handle = p_ble_evt-&amp;gt;evt.gap_evt.conn_handle;

            advertising_start();
            break;
&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;my&amp;nbsp;&lt;strong&gt;advertising_start()&lt;/strong&gt; decides whether to start Connectable or Non-Connectable advertsing, based on the&amp;nbsp;&lt;strong&gt;g_conn_handle:&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;strong&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/**@brief Function for starting advertising - connectable or not, as appropriate.
 *
 * @note Must not be already advertising.
 */
void 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( g_conn_handle == BLE_CONN_HANDLE_INVALID )
    {   // No connection - Do Connectable Advertising
        NRF_LOG_INFO( &amp;quot;Start Connectable adv:&amp;quot; );
        adv_params.properties.type = BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED;
    }
    else
    {   // Connected - Do Non Connectable Advertising
        NRF_LOG_INFO( &amp;quot;Start Non-conn Non-scan adv:&amp;quot; );
        adv_params.properties.type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED;
    }

    // Update the Advertising Data to use the latest Manufacturer-Specific Data
    set_adv_mfr_spec_busy();
    err_code = ble_advdata_encode( &amp;amp;m_advdata, m_advertising.enc_advdata, &amp;amp;m_advertising.adv_data.adv_data.len );
    APP_ERROR_CHECK(err_code);

    // 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;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Note that I am updating the&amp;nbsp;Manufacturer-Specific Data in the Advertising Data each time I (re-)start - just omit that if you&amp;nbsp;don&amp;#39;t want it.&lt;/p&gt;
&lt;p&gt;One of the things in my&amp;nbsp;&lt;span&gt;Manufacturer-Specific Data is a flag which identifies whether the unit is busy (ie, already connected) or &lt;span style="font-size:12px;"&gt;not - so that things other don&amp;#39;t try to connect while the device is already connected.&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;This is because not all Centrals pas the &amp;#39;connectable&amp;#39; flag to the application.&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: Advertise 'Connected' when connected</title><link>https://devzone.nordicsemi.com/thread/198818?ContentTypeID=1</link><pubDate>Tue, 16 Jul 2019 22:04:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:18734fca-d1f6-4db3-ad0d-29e2165625fa</guid><dc:creator>balomueller</dc:creator><description>&lt;p&gt;Yes, I&amp;#39;m using the Advertising Module.&lt;/p&gt;
&lt;p&gt;Switching to non-connectable would be preferable.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Advertise 'Connected' when connected</title><link>https://devzone.nordicsemi.com/thread/198806?ContentTypeID=1</link><pubDate>Tue, 16 Jul 2019 20:12:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:38cd7391-1db4-485b-bcdb-204a830ab656</guid><dc:creator>awneil</dc:creator><description>&lt;p&gt;Are you using the Advertising Module?&lt;/p&gt;
&lt;p&gt;Do you want to continue connectable advertising, or switch to non-connectable?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Advertise 'Connected' when connected</title><link>https://devzone.nordicsemi.com/thread/198802?ContentTypeID=1</link><pubDate>Tue, 16 Jul 2019 19:27:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1e0b442d-9df9-4d07-b432-6df4f9dba8f8</guid><dc:creator>balomueller</dc:creator><description>&lt;p&gt;Especially&amp;nbsp;one question is still not solved in my head: How can I prevent the chip from stopping the advertisement when connected?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Advertise 'Connected' when connected</title><link>https://devzone.nordicsemi.com/thread/198801?ContentTypeID=1</link><pubDate>Tue, 16 Jul 2019 19:24:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4f0539fe-dedf-4f65-ab34-77bd0b579869</guid><dc:creator>balomueller</dc:creator><description>&lt;p&gt;Hello awneil,&lt;/p&gt;
&lt;p&gt;I read your thread back and forth and again. I understand that with the proposed code, it is possible to change the Advertisement Type. I&amp;#39;m still a bit lost though. Could you please give a little more detailed answer to my question?&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Advertise 'Connected' when connected</title><link>https://devzone.nordicsemi.com/thread/198748?ContentTypeID=1</link><pubDate>Tue, 16 Jul 2019 13:37:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:27bd638c-b419-4405-9b22-1b0b9b2e89a6</guid><dc:creator>awneil</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/47391/sdk-15-3-0-restart-non-connectable-advertising-after-timeout"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/47391/sdk-15-3-0-restart-non-connectable-advertising-after-timeout&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>