<?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>How to do the auto reconnect after I disconnect it</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/65071/how-to-do-the-auto-reconnect-after-i-disconnect-it</link><description>Using nrf52810 SDK 17 ble_app_hrs for my example, and i add some code about the passkey 
 Now the situation is after I enter the passkey on my Iphone nRFconnect app, and if I&amp;#39;m walk out of range 
 I want the phone to reconnect itself after I&amp;#39;m back in</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 25 Aug 2020 13:57:48 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/65071/how-to-do-the-auto-reconnect-after-i-disconnect-it" /><item><title>RE: How to do the auto reconnect after I disconnect it</title><link>https://devzone.nordicsemi.com/thread/266271?ContentTypeID=1</link><pubDate>Tue, 25 Aug 2020 13:57:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7e7575dc-4fb1-4aa1-9f4b-406f239e96c9</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;Continue the discussion about this &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/65181/how-to-change-passkey-by-using-press-a-button"&gt;here&lt;/a&gt;, to keep different questions/subjects separated and more organized.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to do the auto reconnect after I disconnect it</title><link>https://devzone.nordicsemi.com/thread/266269?ContentTypeID=1</link><pubDate>Tue, 25 Aug 2020 13:55:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:82b4f150-49f3-4aff-8e8e-4036740d72cd</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;Usually, these two functions are defined in main.c of nRF5 SDK samples, so you should define those in your main.c as well. E.g. take a look at nRF5_SDK_17.0.0_9d13099\examples\ble_peripheral\ble_app_hids_keyboard\main.c:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/**@brief Function for setting filtered whitelist.
 *
 * @param[in] skip  Filter passed to @ref pm_peer_id_list.
 */
static void whitelist_set(pm_peer_id_list_skip_t skip)
{
    pm_peer_id_t peer_ids[BLE_GAP_WHITELIST_ADDR_MAX_COUNT];
    uint32_t     peer_id_count = BLE_GAP_WHITELIST_ADDR_MAX_COUNT;

    ret_code_t err_code = pm_peer_id_list(peer_ids, &amp;amp;peer_id_count, PM_PEER_ID_INVALID, skip);
    APP_ERROR_CHECK(err_code);

    NRF_LOG_INFO(&amp;quot;\tm_whitelist_peer_cnt %d, MAX_PEERS_WLIST %d&amp;quot;,
                   peer_id_count + 1,
                   BLE_GAP_WHITELIST_ADDR_MAX_COUNT);

    err_code = pm_whitelist_set(peer_ids, peer_id_count);
    APP_ERROR_CHECK(err_code);
}


/**@brief Function for setting filtered device identities.
 *
 * @param[in] skip  Filter passed to @ref pm_peer_id_list.
 */
static void identities_set(pm_peer_id_list_skip_t skip)
{
    pm_peer_id_t peer_ids[BLE_GAP_DEVICE_IDENTITIES_MAX_COUNT];
    uint32_t     peer_id_count = BLE_GAP_DEVICE_IDENTITIES_MAX_COUNT;

    ret_code_t err_code = pm_peer_id_list(peer_ids, &amp;amp;peer_id_count, PM_PEER_ID_INVALID, skip);
    APP_ERROR_CHECK(err_code);

    err_code = pm_device_identities_list_set(peer_ids, peer_id_count);
    APP_ERROR_CHECK(err_code);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to do the auto reconnect after I disconnect it</title><link>https://devzone.nordicsemi.com/thread/265906?ContentTypeID=1</link><pubDate>Mon, 24 Aug 2020 08:31:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cd694bb5-6a5a-441d-b211-232d96356bae</guid><dc:creator>mirsaider</dc:creator><description>&lt;p&gt;and also another question, how can I replace typing password by using press a button, thanks a lot.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to do the auto reconnect after I disconnect it</title><link>https://devzone.nordicsemi.com/thread/265884?ContentTypeID=1</link><pubDate>Mon, 24 Aug 2020 07:34:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:27965c7f-a6f5-4ca2-9f7a-ada05540698e</guid><dc:creator>mirsaider</dc:creator><description>&lt;p&gt;I&amp;#39;ve try and try to solve some erro, but undefined reference to `identities_set&amp;#39;,&amp;nbsp;undefined reference to `whitelist_set&amp;#39;, i don&amp;#39;t know how to solve it, can you try it for me, thanks a lot.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to do the auto reconnect after I disconnect it</title><link>https://devzone.nordicsemi.com/thread/265831?ContentTypeID=1</link><pubDate>Fri, 21 Aug 2020 16:30:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bf5ad9ac-a135-4e8d-b20d-b279ba57cb90</guid><dc:creator>JPMorganJeremy</dc:creator><description>&lt;p&gt;The HRS example will automatically advertise upon disconnection, all peripherals in the SDK will unless&amp;nbsp;&lt;strong&gt;p_advertising-&amp;gt;adv_modes_config.ble_adv_on_disconnect_disabled&amp;nbsp;&lt;/strong&gt;is set to false. The reason you aren&amp;#39;t reconnecting when walking back in range is simply because the nrfConnect app doesn&amp;#39;t attempt to reconnect to a disconnected peer.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;If you ran the peripheral HRS on one development kit, and the central HRS on another development kit, you would automatically reconnect without any added code. Though, the advertising upon disconnection is not directed, meaning any central will be able to connect to it once it starts advertising. If you wanted the HRS peripheral to ONLY reconnect to the central it was just connected to before the disconnection, you could enable directed advertising, as well as a whitelist, with these lines of code added to &lt;strong&gt;advertising_init()&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    init.config.ble_adv_whitelist_enabled          = true;
    init.config.ble_adv_directed_enabled           = true;
    init.config.ble_adv_directed_interval          = APP_ADV_INTERVAL_DIRECTED;
    init.config.ble_adv_directed_timeout           = APP_ADV_DURATION_DIRECTED;&lt;/pre&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Then add these two case statements to the &lt;strong&gt;on_adv_evt &lt;/strong&gt;handler which will provide the information&lt;/p&gt;
&lt;p&gt;of the bonded peer to reconnect to upon disconnection&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;        case BLE_ADV_EVT_WHITELIST_REQUEST:
        {
            ble_gap_addr_t whitelist_addrs[BLE_GAP_WHITELIST_ADDR_MAX_COUNT];
            ble_gap_irk_t  whitelist_irks[BLE_GAP_WHITELIST_ADDR_MAX_COUNT];
            uint32_t       addr_cnt = BLE_GAP_WHITELIST_ADDR_MAX_COUNT;
            uint32_t       irk_cnt  = BLE_GAP_WHITELIST_ADDR_MAX_COUNT;

            err_code = pm_whitelist_get(whitelist_addrs, &amp;amp;addr_cnt,
                                        whitelist_irks,  &amp;amp;irk_cnt);
            APP_ERROR_CHECK(err_code);

            // Set the correct identities list (no excluding peers with no Central Address Resolution).
            identities_set(PM_PEER_ID_LIST_SKIP_NO_IRK);

            // Apply the whitelist.
            err_code = ble_advertising_whitelist_reply(&amp;amp;m_advertising,
                                                       whitelist_addrs,
                                                       addr_cnt,
                                                       whitelist_irks,
                                                       irk_cnt);
            APP_ERROR_CHECK(err_code);
        } break; 

        case BLE_ADV_EVT_PEER_ADDR_REQUEST:
        {
            pm_peer_data_bonding_t peer_bonding_data;

            // Only Give peer address if we have a handle to the bonded peer.
            if (m_peer_id != PM_PEER_ID_INVALID)
            {
                err_code = pm_peer_data_bonding_load(m_peer_id, &amp;amp;peer_bonding_data);
                if (err_code != NRF_ERROR_NOT_FOUND)
                {
                    APP_ERROR_CHECK(err_code);

                    // Manipulate identities to exclude peers with no Central Address Resolution.
                    identities_set(PM_PEER_ID_LIST_SKIP_ALL);

                    ble_gap_addr_t * p_peer_addr = &amp;amp;(peer_bonding_data.peer_ble_id.id_addr_info);
                    err_code = ble_advertising_peer_addr_reply(&amp;amp;m_advertising, p_peer_addr);
                    APP_ERROR_CHECK(err_code);
                }
            }
        } break;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;And this case statement to the &lt;strong&gt;pm_evt_handler,&amp;nbsp;&lt;/strong&gt;which adds bonded peers to the whitelist&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;pre class="ui-code" data-mode="text"&gt;case PM_EVT_PEER_DATA_UPDATE_SUCCEEDED:

            if (     p_evt-&amp;gt;params.peer_data_update_succeeded.flash_changed
                     &amp;amp;&amp;amp; (p_evt-&amp;gt;params.peer_data_update_succeeded.data_id == PM_PEER_DATA_ID_BONDING))
                {
                    // Note: You should check on what kind of white list policy your application should use.

                    whitelist_set(PM_PEER_ID_LIST_SKIP_NO_ID_ADDR);
                }
                break;&lt;/pre&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Now, when your HRS peripheral disconnects, it will attempt to connect to the peer it was just connected to, and only that peer.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>