<?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>central and peripheral mode connection disconnecting in nrf52840</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/61801/central-and-peripheral-mode-connection-disconnecting-in-nrf52840</link><description>hai , 
 in my apllication i am using nrf52840 , i merged a code code of peripheral and central (app_blinky example) 
 i need to connect a peripheral to central (with esp32 ), i can able to connect. 
 i should with connect with another nrf ( which acts</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sat, 30 May 2020 07:09:29 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/61801/central-and-peripheral-mode-connection-disconnecting-in-nrf52840" /><item><title>RE: central and peripheral mode connection disconnecting in nrf52840</title><link>https://devzone.nordicsemi.com/thread/252504?ContentTypeID=1</link><pubDate>Sat, 30 May 2020 07:09:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:61733c9e-e842-456a-beb4-5fcdf30d0c7f</guid><dc:creator>sowmiya</dc:creator><description>&lt;p&gt;after this starting advertising_start();&lt;/p&gt;
&lt;p&gt;function to reconnect with esp32.&lt;/p&gt;
&lt;p&gt;for me sometimes again connecting with esp32 but most times it is not disconnecting from DEVICE(C) and to reconnect with esp32 ..&lt;/p&gt;
&lt;p&gt;whats the mistake here ...could u explain??&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: central and peripheral mode connection disconnecting in nrf52840</title><link>https://devzone.nordicsemi.com/thread/252502?ContentTypeID=1</link><pubDate>Sat, 30 May 2020 06:44:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9015b893-a782-4176-91f2-7ee0ff1fd485</guid><dc:creator>sowmiya</dc:creator><description>&lt;p&gt;hello,&lt;/p&gt;
&lt;p&gt;i tried with ble app-blinky example merged with central and peripheral.&lt;/p&gt;
&lt;p&gt;at first i can&amp;nbsp;able to&amp;nbsp;connect with ESP32(A - acts as central) and RELAY (B - acts as peripheral role)&lt;/p&gt;
&lt;p&gt;then i send a message from ESP32(A) TO RELAY(B)&amp;nbsp;&lt;/p&gt;
&lt;p&gt;When its get the message from esp32(A) then RELAY (B - already in peripheral role now after getting message i need to switch over the role to central ) to connect with another NRF(C -acts as peripheral)&lt;/p&gt;
&lt;p&gt;after this message should pass to NRF(C) then when C gives a acknowledgment to RELAY(B - again switch to Peripheral mode ) to connect with ESP32(A)&lt;/p&gt;
&lt;p&gt;for this , every time i am disconnect the role using&amp;nbsp;&lt;/p&gt;
&lt;p&gt;err_code = sd_ble_gap_disconnect(m_conn_handle,&lt;br /&gt; BLE_HCI_LOCAL_HOST_TERMINATED_CONNECTION);&lt;/p&gt;
&lt;p&gt;but sometimes its not getting disconnecting gives me a fatal error.&lt;/p&gt;
&lt;p&gt;i am searching to connecting the modes without disconnecting the roles every time.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;can you please explain me how to work on this???&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;int main(void)
{
 ret_code_t err_code;
    // Initialize.
     log_init();
     leds_init();
      timers_init();
 power_management_init();
    ble_stack_init();
 
    gap_params_init();
    gatt_init();
    services_init();
    advertising_init();
   conn_params_init();
 
     db_discovery_init();
     lbs_c_init();

    // Start execution.
    NRF_LOG_INFO(&amp;quot;Blinky example started pheriperal.&amp;quot;);
    advertising_start();

    // Enter main loop.
    for (;;)
    {
   idle_state_handle();

    }
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;//ble stack initiate

static void ble_stack_init(void)
{
//printf(&amp;quot;ble_stack_init\n&amp;quot;);
    ret_code_t err_code;

    err_code = nrf_sdh_enable_request();
    APP_ERROR_CHECK(err_code);

    // Configure the BLE stack using the default settings.
    // Fetch the start address of the application RAM.
    uint32_t ram_start = 0;
    err_code = nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &amp;amp;ram_start);
    APP_ERROR_CHECK(err_code);

    // Enable BLE stack.
    err_code = nrf_sdh_ble_enable(&amp;amp;ram_start);
    APP_ERROR_CHECK(err_code);


     // Register handlers for BLE and SoC events.
     NRF_SDH_BLE_OBSERVER(m_ble_observer, APP_BLE_OBSERVER_PRIO, ble_evt_handler, NULL);
    NRF_SDH_BLE_OBSERVER(m_ble_observer_re, APP_BLE_OBSERVER_PRIO, ble_evt_handler_relay, NULL);
   
}

&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;event handler&amp;nbsp; for peripheral using flag to&amp;nbsp; play each role&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;
static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
{
      if(periperal_central_role == false)
      { 

        // printf(&amp;quot;inside peripheral role----\n&amp;quot;);
           on_ble_peripheral_evt(p_ble_evt);

       }

      else if(periperal_central_role == true)
       {
        // printf(&amp;quot;inside Central role----\n&amp;quot;);
           on_ble_central_evt(p_ble_evt);

       }
       

&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;at first it should go to on_ble_peripheral_evt() to connect with esp32&lt;pre class="ui-code" data-mode="text"&gt; void on_ble_peripheral_evt(ble_evt_t const * p_ble_evt)
{
    ret_code_t err_code;
  //  printf(&amp;quot;peripheral event handler\n&amp;quot;);
    ble_gap_evt_t const * p_gap_evt = &amp;amp;p_ble_evt-&amp;gt;evt.gap_evt;

    switch (p_ble_evt-&amp;gt;header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
           NRF_LOG_INFO(&amp;quot;Connected with peripheral--------&amp;quot;);
           scan_start();
          
      //   NRF_LOG_INFO(&amp;quot;BLE peroi %d&amp;quot;, p_gap_evt-&amp;gt;params.connected.role);  
           // bsp_board_led_on(CONNECTED_LED);
           // bsp_board_led_off(ADVERTISING_LED);
            m_conn_handle = p_ble_evt-&amp;gt;evt.gap_evt.conn_handle;
            err_code = nrf_ble_qwr_conn_handle_assign(&amp;amp;m_qwr, m_conn_handle);
            APP_ERROR_CHECK(err_code);
             data_ret_fun();
            err_code = app_button_enable();
            APP_ERROR_CHECK(err_code);
            break;

        case BLE_GAP_EVT_DISCONNECTED:
            NRF_LOG_INFO(&amp;quot;Disconnected peri-------&amp;quot;);
            bsp_board_led_off(CONNECTED_LED);
            m_conn_handle = BLE_CONN_HANDLE_INVALID;
            err_code = app_button_disable();
            APP_ERROR_CHECK(err_code);
            advertising_start();
            break;

        case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
            // Pairing not supported
            err_code = sd_ble_gap_sec_params_reply(m_conn_handle,
                                                   BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP,
                                                   NULL,
                                                   NULL);
            APP_ERROR_CHECK(err_code);
            break;

        case BLE_GAP_EVT_PHY_UPDATE_REQUEST:
        {
            NRF_LOG_DEBUG(&amp;quot;PHY update request.&amp;quot;);
            ble_gap_phys_t const phys =
            {
                .rx_phys = BLE_GAP_PHY_AUTO,
                .tx_phys = BLE_GAP_PHY_AUTO,
            };
            err_code = sd_ble_gap_phy_update(p_ble_evt-&amp;gt;evt.gap_evt.conn_handle, &amp;amp;phys);
            APP_ERROR_CHECK(err_code);
        } break;

        case BLE_GATTS_EVT_SYS_ATTR_MISSING:
            // No system attributes have been stored.
            err_code = sd_ble_gatts_sys_attr_set(m_conn_handle, NULL, 0, 0);
            APP_ERROR_CHECK(err_code);
            break;

       case BLE_GATTC_EVT_TIMEOUT:
            // Disconnect on GATT Client timeout event.
            NRF_LOG_DEBUG(&amp;quot;GATT Client Timeout.&amp;quot;);
            err_code = sd_ble_gap_disconnect(p_ble_evt-&amp;gt;evt.gattc_evt.conn_handle,
                                             BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
            APP_ERROR_CHECK(err_code);
            break;



        case BLE_GATTS_EVT_TIMEOUT:
            // Disconnect on GATT Server timeout event.
            NRF_LOG_DEBUG(&amp;quot;GATT Server Timeout.&amp;quot;);
            err_code = sd_ble_gap_disconnect(p_ble_evt-&amp;gt;evt.gatts_evt.conn_handle,
                                             BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
            APP_ERROR_CHECK(err_code);
            break;  

        default:
         
  
            // No implementation needed.
            break;
    }
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;once connect getting message from esp32 and then switch over to central role to connect with another device - NRF(C - acts as peripheral) here i have shown how i disconnected and connecting to device (c)&amp;nbsp; , i tried without disconnecting from peripheral role used&amp;nbsp; ble_gap_connect fun to connect with device (c) but its not worked , when disconnect using ble_gap_disconnect.&lt;/p&gt;
&lt;p&gt;after i scan_init AND on_ble_central_evt - its connected with DEVICE NRF(C)&lt;pre class="ui-code" data-mode="text"&gt;static void led_write_handler(uint16_t conn_handle, ble_lbs_t * p_lbs, uint8_t *data_ptr,ble_evt_t const * p_ble_evt)
{
            chk_flag = true;
   
           ret_code_t err_code;

          printf(&amp;quot;DATA:%s\n&amp;quot;,data_ptr);

              process_msg(data_ptr) ;     

 if(periperal_central_role == false &amp;amp;&amp;amp; chk_flag == true) 
 {
  periperal_central_role = true;
         printf(&amp;quot;inside fun call of central\n&amp;quot;);
/* err_code = sd_ble_gap_connect(p_addr,
                                  p_scan_params,
                                  p_conn_params,
                                  con_cfg_tag); */


         ret_code_t err_code;
          err_code = sd_ble_gap_disconnect(m_conn_handle,
                                            BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);

 if(err_code  ==  NRF_SUCCESS)
  {
 printf(&amp;quot;sucess\n&amp;quot;);


 scan_init();  
  
 on_ble_central_evt(p_ble_evt);

 }&lt;/pre&gt;i am geting a mac id of devcie(C) from the message got from esp32 , then with the mac id i have to connect with device (C), for this connection i used the below fun&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt; void scan_init(void)
{
    ret_code_t          err_code;
    nrf_ble_scan_init_t init_scan;

    memset(&amp;amp;init_scan, 0, sizeof(init_scan));
if(periperal_central_role == true)
{
printf(&amp;quot;inside central scan\n&amp;quot;);
    init_scan.connect_if_match = true;
    init_scan.conn_cfg_tag     = APP_BLE_CONN_CFG_TAG;

err_code = nrf_ble_scan_init(&amp;amp;m_scan, &amp;amp;init_scan, scan_evt_handler_central);
    APP_ERROR_CHECK(err_code);
   
err_code = nrf_ble_scan_filter_set(&amp;amp;m_scan, SCAN_ADDR_FILTER, m_addr);
    APP_ERROR_CHECK(err_code);
         if(err_code == NRF_SUCCESS)
    {
     printf(&amp;quot;nrf_ble_scan_filter_set\n&amp;quot;);
    }
    else
    {
     printf(&amp;quot;nrf_ble_scan_filter_notttttt ok-----\n&amp;quot;);
    }  

     err_code = nrf_ble_scan_filters_enable(&amp;amp;m_scan, NRF_BLE_SCAN_ADDR_FILTER, false);
    APP_ERROR_CHECK(err_code);
      if(err_code == NRF_SUCCESS)
    {
     printf(&amp;quot;nrf_ble_scan_filters_enable\n&amp;quot;);
    }
    else
    {
     printf(&amp;quot;nrf_ble_scan_not ok-----\n&amp;quot;);
    }
}
else if(periperal_central_role == false)
{
 printf(&amp;quot;inside periperal scan\n&amp;quot;);
      init_scan.connect_if_match = false;
    init_scan.conn_cfg_tag     = APP_BLE_CONN_CFG_TAG;
    init_scan.p_scan_param     = &amp;amp;m_scan_param;
    err_code = nrf_ble_scan_init(&amp;amp;m_scan, &amp;amp;init_scan, scan_evt_handler_peri);
    APP_ERROR_CHECK(err_code);

}
   
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;when getting the ack from DEVICE (C) I switching over the role to peripheral in RELAY(B)&lt;/p&gt;
&lt;p&gt;void central_msg_handler(void * p_context)&lt;br /&gt;{&lt;br /&gt; ret_code_t err_code;&lt;br /&gt;printf(&amp;quot;handle -------centrl---\n&amp;quot;);&lt;br /&gt;err_code = ble_lbs_led_status_send(&amp;amp;m_ble_lbs_c, button_action);&lt;br /&gt; if (err_code != NRF_SUCCESS &amp;amp;&amp;amp;&lt;br /&gt; err_code != BLE_ERROR_INVALID_CONN_HANDLE &amp;amp;&amp;amp;&lt;br /&gt; err_code != NRF_ERROR_INVALID_STATE)&lt;br /&gt; {&lt;/p&gt;
&lt;p&gt;sprintf(collect_data, &amp;quot;{\&amp;quot;MSTS\&amp;quot;:\&amp;quot;%s\&amp;quot;,\&amp;quot;MAC\&amp;quot;:\&amp;quot;%02X%02X%02X%02X%02X%02X\&amp;quot;}&amp;quot;,&amp;quot;0&amp;quot;, m_addr_c[0], m_addr_c[1],&lt;br /&gt;m_addr_c[2], m_addr_c[3],&lt;br /&gt; m_addr_c[4], m_addr_c[5]);&lt;br /&gt; coaster_msg_suc = true ;&lt;br /&gt; APP_ERROR_CHECK(err_code);&lt;br /&gt; printf(&amp;quot;data ret %s\n&amp;quot;,collect_data);&lt;br /&gt; }&lt;br /&gt; if (err_code == NRF_SUCCESS)&lt;br /&gt; {&lt;br /&gt; coaster_msg_suc = true ;&lt;br /&gt; sprintf(collect_data, &amp;quot;{\&amp;quot;MSTS\&amp;quot;:\&amp;quot;%s\&amp;quot;,\&amp;quot;MAC\&amp;quot;:\&amp;quot;%02X%02X%02X%02X%02X%02X\&amp;quot;}&amp;quot;,&amp;quot;1&amp;quot;, m_addr_c[0], m_addr_c[1],&lt;br /&gt; m_addr_c[2], m_addr_c[3],&lt;br /&gt; m_addr_c[4], m_addr_c[5]);&lt;br /&gt; printf(&amp;quot;data ret %s\n&amp;quot;,collect_data);&lt;br /&gt; printf(&amp;quot;sucess return------------\n&amp;quot;);&lt;/p&gt;
&lt;p&gt;}&lt;br /&gt; mode_chnage_peripheral();&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;void mode_chnage_peripheral()&lt;br /&gt;{&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;ret_code_t err_code;&lt;br /&gt;err_code = sd_ble_gap_disconnect(m_conn_handle,&lt;br /&gt; BLE_HCI_LOCAL_HOST_TERMINATED_CONNECTION);err_code = sd_ble_gap_adv_stop(m_adv_handle);&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: central and peripheral mode connection disconnecting in nrf52840</title><link>https://devzone.nordicsemi.com/thread/251899?ContentTypeID=1</link><pubDate>Wed, 27 May 2020 10:27:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cb21b1a3-1845-40e8-8a52-485e29d8cbc2</guid><dc:creator>Joakim Jakobsen</dc:creator><description>&lt;p&gt;Yes, it is possible to do this.&lt;/p&gt;
&lt;p&gt;The S140 softdevice supports up to 20 concurrent connections. &lt;br /&gt;We already have sample code for this in our nRF5 SDK. You can take a look at the Multi-link example is referred to in my last reply or the relay example.&lt;br /&gt;Relay example: &lt;br /&gt;&amp;quot;The application combines a collector part on one end and a sensor part on the other to show how the SoftDevice can be used to make a device simultaneously function as central and peripheral device. &amp;quot;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: central and peripheral mode connection disconnecting in nrf52840</title><link>https://devzone.nordicsemi.com/thread/251843?ContentTypeID=1</link><pubDate>Wed, 27 May 2020 08:15:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f4e4aa86-b2b6-428e-a4a0-48f2e1be8bc7</guid><dc:creator>sowmiya</dc:creator><description>&lt;p&gt;actually my application is&amp;nbsp; with esp32(A) , relay_NRF(B) , nrf(C)&lt;/p&gt;
&lt;p&gt;relay(B) - merged code (with central and peripheral)&lt;/p&gt;
&lt;p&gt;STEP 1 : A and B DEVICE should be always in connected mode&amp;nbsp;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;in this ESP32- A(acts as central ) and relay _NRF- B(in peripheral mode )&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;STEP 2 :&amp;nbsp; a data should send from A TO B , then B (relay_NRF )should connect with NRF - C(peripheral) from central mode in relay(B) without disconnecting from ESP32 (A).&lt;/p&gt;
&lt;p&gt;Is it possible to always connect with ESP32(A) as well relay_NRF should connect with another NRF - C(which is peripheral)??&lt;/p&gt;
&lt;p&gt;if you have any code kindly share the code ..&lt;/p&gt;
&lt;p&gt;Thank you&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: central and peripheral mode connection disconnecting in nrf52840</title><link>https://devzone.nordicsemi.com/thread/251834?ContentTypeID=1</link><pubDate>Wed, 27 May 2020 07:51:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6ee876f5-4585-4ee4-a056-b5942400b984</guid><dc:creator>Joakim Jakobsen</dc:creator><description>&lt;p&gt;Hi.&lt;/p&gt;
&lt;p&gt;I suggest that you take a look at the &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v16.0.0/ble_sdk_app_multilink.html"&gt;BLE Multi-link Example&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The BLE Multi-link Central example application shows how one central can be connected to several peripherals simultaneously. &lt;/p&gt;
&lt;p&gt;Br, &lt;br /&gt;Joakim&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>