<?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>A question about the part that detects disconnection in the standby state of ble_peripheral and central</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/99794/a-question-about-the-part-that-detects-disconnection-in-the-standby-state-of-ble_peripheral-and-central</link><description>hi. 
 I am reviewing nRF operation with the following specifications. 
 ------------------------------------------------------------------------------- 
 
 - nRF5832-DK 
 - nRF_SDK17.1.0 
 - example 
 1) peripheral : ble_peripheral - ble_app_uart 
 2</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 26 May 2023 08:10:15 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/99794/a-question-about-the-part-that-detects-disconnection-in-the-standby-state-of-ble_peripheral-and-central" /><item><title>RE: A question about the part that detects disconnection in the standby state of ble_peripheral and central</title><link>https://devzone.nordicsemi.com/thread/427684?ContentTypeID=1</link><pubDate>Fri, 26 May 2023 08:10:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9c96eac0-38a2-4b8b-8158-86f306c30adb</guid><dc:creator>Hieu</dc:creator><description>&lt;p&gt;Hi pkr2258,&lt;/p&gt;
[quote user="pkr2258"]Did you have a good vacation?[/quote]
&lt;p&gt;I had a relaxing time.&amp;nbsp;Thank you for asking &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;.&lt;/p&gt;
[quote user="pkr2258"]- When the central and peripherals are connected, we are going to use the function of checking the connection status while transmitting and receiving periodically.[/quote]
&lt;p&gt;I am not certain what function you plan to use to check the status of the connection. In the nRF5 SDK, the connection status is managed by the SoftDevice. The SoftDevice informed the application of changes in connection by sending &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s132.api.v7.2.0/structble__evt__t.html"&gt;events&lt;/a&gt; to the application&amp;#39;s &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/group__nrf__sdh__ble.html"&gt;SoftDevice Handler&lt;/a&gt;. Two key events that help you monitor a connection are&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s132.api.v7.2.0/group___b_l_e___g_a_p___e_n_u_m_e_r_a_t_i_o_n_s.html#ggada486dd3c0cce897b23a887bed284fefaa0b4789724d202a13a5e7eab85c52957"&gt;BLE_GAP_EVT_CONNECTED&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s132.api.v7.2.0/group___b_l_e___g_a_p___e_n_u_m_e_r_a_t_i_o_n_s.html#ggada486dd3c0cce897b23a887bed284fefa057001bbd6ea9e615f19ef93cc0831ee"&gt;&lt;span&gt;BLE_GAP_EVT_DISCONNECTED&lt;/span&gt;&lt;/a&gt;.&lt;/p&gt;
[quote user="pkr2258"]- It is understood as checking the connection status at the time period defined in #deine below.[/quote]
&lt;p&gt;As explained above, the SoftDevice is in charge of monitoring the connection.&lt;/p&gt;
&lt;p&gt;Those defines are used in used in &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s140.api.v7.2.0/group___b_l_e___g_a_p___f_u_n_c_t_i_o_n_s.html#ga7fa1d11a93b9738f7695ec3d6758da86"&gt;sd_ble_gap_ppcp_set()&lt;/a&gt;&amp;nbsp;as Connection Intervals parameter.&amp;nbsp;They&amp;nbsp;&lt;em&gt;could&lt;/em&gt; be indicator of how often the &amp;quot;connection status&amp;quot; is checked, because peers in a connection only check with each other in Connection Events, which are 1x Connection Interval apart.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;However, sd_ble_gap_ppcp_set() only sets the&amp;nbsp;&lt;span style="text-decoration:underline;"&gt;&lt;em&gt;preferred&lt;/em&gt;&lt;/span&gt; Connection Interval of the Peripheral. &lt;br /&gt;It is not guaranteed the Connection Interval of the&amp;nbsp;connection. The Central device has the final decision about it.&lt;/p&gt;
&lt;p&gt;To get the Connection Interval of an active connection, you need to get it from the parameters of the gap events&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s132.api.v7.2.0/group___b_l_e___g_a_p___e_n_u_m_e_r_a_t_i_o_n_s.html#ggada486dd3c0cce897b23a887bed284fefaa0b4789724d202a13a5e7eab85c52957"&gt;BLE_GAP_EVT_CONNECTED&lt;/a&gt;&amp;nbsp;and&amp;nbsp;.&lt;/p&gt;
[quote user="pkr2258"]2.1 Set TX Power as &amp;quot;BLE_GAP_TX_POWER_ROLE_ADV&amp;quot; when trying to register. &lt;span style="color:rgba(0, 0, 255, 1);"&gt;( Implemented successfully so far )&lt;/span&gt;&lt;br /&gt; -&amp;gt; sd_ble_gap_tx_power_set (BLE_GAP_TX_POWER_ROLE_ADV, m_advertising.adv_handle, TX_POWER_LEVEL)[/quote]
&lt;p&gt;This seems correct. However, if I remember correctly, multiple Advertising Sets are not yet implemented in the nRF5 SDK, so please note that you only have one advertising set.&lt;/p&gt;
[quote user="pkr2258"]2.2 When registration is completed, try to lower the receiving sensitivity with &amp;quot;BLE_GAP_TX_POWER_ROLE_CONN&amp;quot;.&lt;br /&gt; I can&amp;#39;t find which handler to connect to the sd_ble_gap_tx_power_set() function.&lt;br /&gt; Which handler should be used?&lt;br /&gt;&lt;br /&gt; -&amp;gt; sd_ble_gap_tx_power_set&lt;br /&gt; (BLE_GAP_TX_POWER_ROLE_CONN, any handler here?, TX_POWER_LEVEL);[/quote]
&lt;p&gt;The handle of a connection is given as part of the BLE_GAP_EVT_CONNECTED&amp;nbsp;event in &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s140.api.v7.2.0/structble__gap__evt__t.html"&gt;ble_evt_t.gap_evt.conn_handle&lt;/a&gt;.&lt;/p&gt;
[quote user="pkr2258"]&lt;div&gt;2.3 When registration is completed and the connection status of central and peripheral is checked at a specific interval,&lt;br /&gt; If the status check fails, we are going to implement something that raises the TX Power.&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;So, I would like to know the part where the connection is checked, not the part where the connection is completely disconnected.&lt;br /&gt; In which function will it be performed?&lt;/div&gt;[/quote]
&lt;p&gt;I finally see your point here. However, I am afraid the SoftDevice does not give such timing event.&lt;/p&gt;
&lt;p&gt;Technically, you can register &lt;a href="https://infocenter.nordicsemi.com/topic/sds_s132/SDS/s1xx/radio_notif/radio_notification.html?cp=5_7_3_0_10"&gt;Radio Notifications&lt;/a&gt; like I explained in this DevZone question: &amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/99006/callback-before-the-ble-event"&gt;callback before the BLE event&lt;/a&gt;. However, please note that the Radio Notifications add processing burden onto the SoftDevice and may affect performance, and there are caveats as I explained in that DevZone question.&lt;/p&gt;
&lt;p&gt;Knowing when the check happen also does not help you catch the disconnection before it happens, because everything is handled in the SoftDevice.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;For your purpose, perhaps you are more interested in RSSI monitoring. Please&amp;nbsp;look up the keyword &amp;quot;rssi&amp;quot; in the&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s132.api.v7.2.0/group___b_l_e___g_a_p___f_u_n_c_t_i_o_n_s.html"&gt;SoftDevice BLE GAP function documentation&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Hieu&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: A question about the part that detects disconnection in the standby state of ble_peripheral and central</title><link>https://devzone.nordicsemi.com/thread/427623?ContentTypeID=1</link><pubDate>Fri, 26 May 2023 01:23:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6b377d36-8576-4006-b30f-d0ed54f9abbe</guid><dc:creator>pkr2258</dc:creator><description>&lt;p&gt;hi,&lt;/p&gt;
&lt;p&gt;Did you have a good vacation?&lt;/p&gt;
&lt;p&gt;I couldn&amp;#39;t write the question in detail. A bit more detailed...&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;1. When central and peripheral are connected, basic connection status check&lt;/p&gt;
&lt;p&gt;- When the central and peripherals are connected, we are going to use the function of checking the connection status while transmitting and receiving periodically.&lt;/p&gt;
&lt;p&gt;- It is understood as checking the connection status at the time period defined in #deine below.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define MIN_CONN_INTERVAL               MSEC_TO_UNITS(20, UNIT_1_25_MS)             /**&amp;lt; Minimum acceptable connection interval (20 ms), Connection interval uses 1.25 ms units. */
#define MAX_CONN_INTERVAL               MSEC_TO_UNITS(75, UNIT_1_25_MS)             /**&amp;lt; Maximum acceptable connection interval (75 ms), Connection interval uses 1.25 ms units. */&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;2.&amp;nbsp;&lt;/span&gt;&lt;span&gt;TX Power roles&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;2.1 Set TX Power as &amp;quot;BLE_GAP_TX_POWER_ROLE_ADV&amp;quot; when trying to register. &lt;span style="color:#0000ff;"&gt;( Implemented successfully so far )&lt;/span&gt;&lt;br /&gt; -&amp;gt; sd_ble_gap_tx_power_set (BLE_GAP_TX_POWER_ROLE_ADV, m_advertising.adv_handle, TX_POWER_LEVEL)&lt;br /&gt;&lt;br /&gt; &lt;br /&gt; 2.2 When registration is completed, try to lower the receiving sensitivity with &amp;quot;BLE_GAP_TX_POWER_ROLE_CONN&amp;quot;.&lt;br /&gt; I can&amp;#39;t find which handler to connect to the sd_ble_gap_tx_power_set() function.&lt;br /&gt; Which handler should be used?&lt;br /&gt;&lt;br /&gt; -&amp;gt; sd_ble_gap_tx_power_set&lt;br /&gt; (BLE_GAP_TX_POWER_ROLE_CONN, any handler here?, TX_POWER_LEVEL);&lt;br /&gt;&lt;br /&gt; 2.3 When registration is completed and the connection status of central and peripheral is checked at a specific interval,&lt;br /&gt; If the status check fails, we are going to implement something that raises the TX Power.&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;So, I would like to know the part where the connection is checked, not the part where the connection is completely disconnected.&lt;br /&gt; In which function will it be performed?&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/**@brief GAP TX Power roles.
 */
enum BLE_GAP_TX_POWER_ROLES
{
  BLE_GAP_TX_POWER_ROLE_ADV       = 1,           /**&amp;lt; Advertiser role. */
  BLE_GAP_TX_POWER_ROLE_CONN      = 3,           /**&amp;lt; Connection role. */
};
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;thank.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: A question about the part that detects disconnection in the standby state of ble_peripheral and central</title><link>https://devzone.nordicsemi.com/thread/425997?ContentTypeID=1</link><pubDate>Tue, 16 May 2023 20:09:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:40f0b2fe-11ea-4d70-8acb-29d8bcd39fa1</guid><dc:creator>Hieu</dc:creator><description>&lt;p&gt;Hi pkr2258,&lt;/p&gt;
&lt;p&gt;In the nRF5 SDK, the SoftDevice sends&amp;nbsp;events to the application, including ones&amp;nbsp;concerning the connection. The auto restart of scanning and advertising is done by handling of the event &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s132.api.v7.2.0/group___b_l_e___g_a_p___e_n_u_m_e_r_a_t_i_o_n_s.html#ggada486dd3c0cce897b23a887bed284fefa057001bbd6ea9e615f19ef93cc0831ee"&gt;BLE_GAP_EVT_DISCONNECTED&lt;/a&gt;.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/ble_sdk_app_nus_c.html"&gt;the&amp;nbsp;ble_app_uart_c&amp;nbsp;central example&lt;/a&gt;,&amp;nbsp;the &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/group__ble__nus__c.html"&gt;NUS Client module&lt;/a&gt; handles BLE_GAP_EVT_DISCONNECTED, and sends a &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/group__ble__nus__c.html#gga4953e2052eedb1198b5d9663a78c3389ac2487b0565695fe41e92ad7305c63ccf"&gt;BLE_NUS_C_EVT_DISCONNECTED&lt;/a&gt;&amp;nbsp;event to the application. The application then&amp;nbsp;handles this event and restart scanning in main.c&lt;/p&gt;
&lt;p&gt;ble_nus_c.c&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void ble_nus_c_on_ble_evt(ble_evt_t const * p_ble_evt, void * p_context)
{
    ble_nus_c_t * p_ble_nus_c = (ble_nus_c_t *)p_context;

    ...

    switch (p_ble_evt-&amp;gt;header.evt_id)
    {
        ...

        case BLE_GAP_EVT_DISCONNECTED:
            if (p_ble_evt-&amp;gt;evt.gap_evt.conn_handle == p_ble_nus_c-&amp;gt;conn_handle
                    &amp;amp;&amp;amp; p_ble_nus_c-&amp;gt;evt_handler != NULL)
            {
                ble_nus_c_evt_t nus_c_evt;

                nus_c_evt.evt_type = BLE_NUS_C_EVT_DISCONNECTED;

                p_ble_nus_c-&amp;gt;conn_handle = BLE_CONN_HANDLE_INVALID;
                p_ble_nus_c-&amp;gt;evt_handler(p_ble_nus_c, &amp;amp;nus_c_evt);
            }
            break;

        default:
            // No implementation needed.
            break;
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;main.c&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/**@brief Callback handling Nordic UART Service (NUS) client events.
 *
 * @details This function is called to notify the application of NUS client events.
 *
 * @param[in]   p_ble_nus_c   NUS client handle. This identifies the NUS client.
 * @param[in]   p_ble_nus_evt Pointer to the NUS client event.
 */

/**@snippet [Handling events from the ble_nus_c module] */
static void ble_nus_c_evt_handler(ble_nus_c_t * p_ble_nus_c, ble_nus_c_evt_t const * p_ble_nus_evt)
{
    ret_code_t err_code;

    switch (p_ble_nus_evt-&amp;gt;evt_type)
    {
        ...

        case BLE_NUS_C_EVT_DISCONNECTED:
            NRF_LOG_INFO(&amp;quot;Disconnected.&amp;quot;);
            scan_start();
            break;
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;In &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/ble_sdk_app_nus_eval.html"&gt;the&amp;nbsp;ble_app_uart peripheral example&lt;/a&gt;, the advertising is restarted by &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/group__ble__advertising.html"&gt;the Advertising Module&lt;/a&gt; in ble_advertising.c&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/**@brief Function for handling the Disconnected event.
 *
 * @param[in] p_advertising Advertising module instance.
 * @param[in] p_ble_evt Event received from the BLE stack.
 */
static void on_disconnected(ble_advertising_t * const p_advertising, ble_evt_t const * p_ble_evt)
{
    uint32_t ret;

    p_advertising-&amp;gt;whitelist_temporarily_disabled = false;

    if (p_ble_evt-&amp;gt;evt.gap_evt.conn_handle == p_advertising-&amp;gt;current_slave_link_conn_handle &amp;amp;&amp;amp;
        p_advertising-&amp;gt;adv_modes_config.ble_adv_on_disconnect_disabled == false)
    {
       ret = ble_advertising_start(p_advertising, BLE_ADV_MODE_DIRECTED_HIGH_DUTY);
       if ((ret != NRF_SUCCESS) &amp;amp;&amp;amp; (p_advertising-&amp;gt;error_handler != NULL))
       {
           p_advertising-&amp;gt;error_handler(ret);
       }
    }
}

void ble_advertising_on_ble_evt(ble_evt_t const * p_ble_evt, void * p_context)
{
    ble_advertising_t * p_advertising = (ble_advertising_t *)p_context;

    switch (p_ble_evt-&amp;gt;header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
            on_connected(p_advertising, p_ble_evt);
            break;

        // Upon disconnection, whitelist will be activated and direct advertising is started.
        case BLE_GAP_EVT_DISCONNECTED:
            on_disconnected(p_advertising, p_ble_evt);
            break;

        // Upon terminated advertising (time-out), the next advertising mode is started.
        case BLE_GAP_EVT_ADV_SET_TERMINATED:
            on_terminated(p_advertising, p_ble_evt);
            break;

        default:
            break;
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Please be informed that I will&amp;nbsp;have a holiday and days off from tomorrow. I will return later next week and continue to support you if you have any further questions. My apology for the inconvenience.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Hieu&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>