Trouble Reconnecting Peripherals after Disconnection.

Hi,

We are developing a new project using the nRF52832 as our controller and nRF5 SDK 17.0.2 as our SDK.

We have integrated the NUS client and NUS peripheral parts from the ble_app_uart_c and ble_app_uart example projects. We've checked the functionality and it works well in the first stage. That is, the device can scan for nearby advertised devices based on the NUS service and connect to them. After the connection, the device acts as a peripheral and can connect with the nRF Connect app, sending and receiving data to and from the app through the connected device. Essentially, the device acts as a gateway between the app and connected peripherals.

Initially, there was no issue with the BLE connection. However, after disconnecting the nearby advertised peripherals, we are unable to connect to the two peripherals again. We can only connect to the same peripheral. What could be the issue?

Device (gateway acting as central and peripheral): NUS client and NUS peripheral integrated ble_app_hrs_rscs_relay example code flashed board . Connected peripheral: Modified NUS client and NUS peripheral integrated ble_app_hrs_rscs_relay example code flashed board , capable of capturing nearby beacon data and sending it to the connected gateway.

When we initially flash the code, we can connect the gateway to two nearby peripherals. However, when a peripheral disconnects, we can't connect to that two peripheral again.but we can connect only one same peripherl . The log output shows this:

SCAN START

12:13:07.819 -> <info> app: Connected to target F0C798AA5E92

12:13:07.819 -> <info> app: Central connected

12:13:07.819 -> <info> app: Attempt to find HRS, RSC, or NUS conn_handle 0x0

12:13:07.819 -> <info> app: NUS client assigned to conn_handle 0x0 (index: 0)

12:13:07.866 -> <info> app: nrf_ble_scan_start : 0
12:13:07.866 -> 

12:13:07.866 -> <info> app: SCAN START

12:13:08.287 -> <info> app: ATT MTU exchange completed.

12:13:08.334 -> <info> app: Ble NUS max data length set to 0xF4(244)

12:13:08.334 -> <info> peer_manager_handler: Connection security failed: role: Central, conn_handle: 0x0, procedure: Bonding, error: 133

12:13:08.334 -> <warning> peer_manager_handler: Disconnecting conn_handle 0.

12:13:08.475 -> <error> nrf_ble_gq: SD GATT procedure (3) failed on connection handle 0 with error: 0x00000008.

12:13:08.475 -> <info> app: DB Discovery instance 0x2000477C available on conn handle: 0

12:13:08.522 -> <info> app: Found 1 services on conn_handle: 0

12:13:08.522 -> <info> app: current instance index 0
12:13:08.522 -> 

12:13:08.522 -> <info> app: Disconnected from instance 0

12:13:08.522 -> <info> app: nrf_ble_scan_start : 0
12:13:08.522 -> 

12:13:08.522 -> <info> app: SCAN START

12:13:08.522 -> <info> app: Device disconnected, conn_handle: 0x0, reason: 0x16

12:13:08.522 -> <info> app: nrf_ble_scan_start : 0
12:13:08.522 -> 

12:13:08.522 -> <info> app: SCAN START

12:13:09.646 -> <info> app: Connected to target F0C798AA5E92

12:13:09.646 -> <info> app: Central connected

12:13:09.646 -> <info> app: Attempt to find HRS, RSC, or NUS conn_handle 0x0

12:13:09.646 -> <info> app: NUS client assigned to conn_handle 0x0 (index: 0)

12:13:09.646 -> <info> app: nrf_ble_scan_start : 0
12:13:09.646 -> 

12:13:09.646 -> <info> app: SCAN START

12:13:10.256 -> <info> app: ATT MTU exchange completed.

12:13:10.303 -> <info> app: Ble NUS max data length set to 0xF4(244)

12:13:10.443 -> <info> peer_manager_handler: Connection security failed: role: Central, conn_handle: 0x0, procedure: Bonding, error: 133

12:13:10.490 -> <warning> peer_manager_handler: Disconnecting conn_handle 0.

12:13:10.678 -> <error> nrf_ble_gq: SD GATT procedure (3) failed on connection handle 0 with error: 0x00000008.

12:13:10.678 -> <info> app: DB Discovery instance 0x2000477C available on conn handle: 0

12:13:10.678 -> <info> app: Found 1 services on conn_handle: 0

12:13:10.678 -> <info> app: current instance index 0
12:13:10.678 -> 

12:13:10.678 -> <info> app: Disconnected from instance 0

kindly Please provide your response as soon as possible. Your valuable input is urgently needed. 

Parents
  • Hi, 
    If you look at the log you can find this: 
    12:13:10.443 -> <info> peer_manager_handler: Connection security failed: role: Central, conn_handle: 0x0, procedure: Bonding, error: 133

    Error 133 is BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP. So either the central or the peripheral has responded that pairing is not supported. 

    You can test by disabling bonding and see if the issue still occurs. 

    If it stops, we need to look into which device causing the issue, a sniffer trace can help here. 
    Have you made sure you connect to the correct device not other random device around ? 
    How did you recover from the situation, how did you connect to the 2 devices that you couldn't connect ? 

  • Initially, I mean when the code is flashed into the gateway, I am able to connect to two devices. However, when one of my peripheral devices is disconnected, I cannot connect to a specific device.

    I just modified the peer_manager_init() function like this, but it doesn't solve the issue. I am still confused. What is happening here? When I disconnect the two devices at the same time after the peer_manager_init() function, I am still only able to connect to a specific device. The log shows that the scan starts, but it cannot connect to the other peripheral device.

    Can you please take a look at my gateway code and tell me if it's correct?

     

    /**@brief Function for initializing the Peer Manager.
     */
    static void peer_manager_init(void)
    {
        ble_gap_sec_params_t sec_param;
        ret_code_t err_code;
    
        // Initialize the Peer Manager.
        err_code = pm_init();
        APP_ERROR_CHECK(err_code);
        NRF_LOG_INFO("pm_init : %d\n", err_code);
    
        memset(&sec_param, 0, sizeof(ble_gap_sec_params_t));
    
        // Security parameters for SEC_OPEN (no encryption, no authentication, no bonding).
        sec_param.bond           = 0; // No bonding.
        sec_param.mitm           = 0; // No MITM protection.
        sec_param.lesc           = 0; // No LE Secure Connections.
        sec_param.keypress       = 0; // No keypress notifications.
        sec_param.io_caps        = BLE_GAP_IO_CAPS_NONE; // No I/O capabilities.
        sec_param.oob            = 0; // No Out-of-Band data.
        sec_param.min_key_size   = 7; // Minimum encryption key size (not enforced for SEC_OPEN).
        sec_param.max_key_size   = 16; // Maximum encryption key size (not enforced for SEC_OPEN).
        sec_param.kdist_own.enc  = 0; // Do not distribute encryption keys.
        sec_param.kdist_own.id   = 0; // Do not distribute identity keys.
        sec_param.kdist_peer.enc = 0; // Do not request encryption keys from peer.
        sec_param.kdist_peer.id  = 0; // Do not request identity keys from peer.
    
        // Set the security parameters in the Peer Manager.
        err_code = pm_sec_params_set(&sec_param);
        APP_ERROR_CHECK(err_code);
        NRF_LOG_INFO("pm_sec_params_set : %d\n", err_code);
    
        // Register the Peer Manager event handler.
        err_code = pm_register(pm_evt_handler);
        APP_ERROR_CHECK(err_code);
        NRF_LOG_INFO("pm_register : %d\n", err_code);
    }
    
    

  • Hi, 
    Please read what I wrote in last reply and answer the question. Please capture a sniffer trace. 
    Simply saying "cannot connect to a device" doesn't help the debugging. 

  •  ,

    In here, we changed bonding and security encryption in the peer_manager_init() function, but it did not solve the issue. Initially, I was able to connect the gateway with two peripherals, and the gateway could connect with the nrfconnect app and send/receive data. However, if I disconnected the second connected peripheral from the gateway and powered it again, it would not connect with the gateway. But if I reconnected the first connected peripheral with the gateway, I could connect with it without any issues. The trouble only happens with the second connected peripheral.

    If I restart the gateway, I am able to connect with both peripherals. What could be the issue? I checked the ble_event_handler role and obtained 'CURRENT ROLE: 00'

    19:40:03.950 -> <info> app_timer: RTC: initialized.
    
    19:40:03.950 -> <info> app: nrf_sdh_enable_request : 0
    19:40:03.950 -> 
    
    19:40:03.950 -> <info> app: nrf_sdh_ble_default_cfg_set : 0
    19:40:03.997 -> 
    
    19:40:03.997 -> <info> app: nrf_sdh_ble_enable : 0
    19:40:03.997 -> 
    
    19:40:03.997 -> <info> app:  after nrf sdh ble observer 
    19:40:03.997 -> 
    
    19:40:03.997 -> <info> app: nrf_ble_scan_init : 0
    19:40:03.997 -> 
    
    19:40:03.997 -> <info> app: scan filter init HART_RATE_SERVICE_UUID_IDX : 0
    19:40:03.997 -> 
    
    19:40:03.997 -> <info> app: scan filter init RSCS_SERVICE_UUID_IDX : 0
    19:40:03.997 -> 
    
    19:40:03.997 -> <info> app: scan filter init NUS : 0
    19:40:03.997 -> 
    
    19:40:03.997 -> <info> app: nrf_ble_scan_filters_enable : 0
    19:40:03.997 -> 
    
    19:40:03.997 -> <info> app: nrf_ble_gatt_init : 0
    19:40:03.997 -> 
    
    19:40:03.997 -> <info> app: nrf_ble_gatt_att_mtu_central_set : 0
    19:40:03.997 -> 
    
    19:40:03.997 -> <info> app: nrf_ble_gatt_att_mtu_periph_set : 0
    19:40:03.997 -> 
    
    19:40:03.997 -> <info> app: ble_db_discovery_init :0
    19:40:03.997 -> 
    
    19:40:03.997 -> <info> app: ble_hrs_c_init : 0
    19:40:04.044 -> 
    
    19:40:04.044 -> <info> app: ble_rscs_c_init : 0
    19:40:04.044 -> 
    
    19:40:04.044 -> <info> app: ble_nus_c_init for instance 0: 0
    
    19:40:04.044 -> <info> app: ble_nus_c_init for instance 1: 0
    
    19:40:04.044 -> <info> app: nrf_ble_qwr_init : 0
    19:40:04.044 -> 
    
    19:40:04.044 -> <info> app: nrf_ble_qwr_init : 0
    19:40:04.044 -> 
    
    19:40:04.044 -> <info> app: nrf_ble_qwr_init : 0
    19:40:04.044 -> 
    
    19:40:04.044 -> <info> app: ble_hrs_init : 0
    19:40:04.044 -> 
    
    19:40:04.044 -> <info> app: ble_rscs_init : 0
    19:40:04.044 ->  
    
    19:40:04.044 -> <info> app:  ble_nus_init : 0
    19:40:04.044 -> 
    
    19:40:04.044 -> <info> app: Relay example started.
    
    19:40:04.044 -> <info> app: ADV_SCAN_START
    
    19:40:04.044 -> <info> app: nrf_ble_scan_start : 0
    19:40:04.044 -> 
    
    19:40:04.044 -> <info> app: SCAN START
    
    19:40:04.044 -> <info> app: Fast advertising.
    
    19:40:04.091 -> <info> app: CURRENT ROLE : 00
    
    19:40:05.168 -> <info> app: Connected to target E81D0E54B577
    
    19:40:05.168 -> <info> app: CURRENT ROLE : 02
    
    19:40:05.168 -> <info> app: Central connected
    
    19:40:05.168 -> <info> app: Attempt to find HRS, RSC, or NUS conn_handle 0x0
    
    19:40:05.168 -> <info> app: NUS client assigned to conn_handle 0x0 (index: 0)
    
    19:40:05.168 -> <info> app: nrf_ble_scan_start : 0
    19:40:05.168 -> 
    
    19:40:05.168 -> <info> app: SCAN START
    
    19:40:05.168 -> <info> app: CURRENT ROLE : 02
    
    19:40:05.215 -> <info> app: CURRENT ROLE : 00
    
    19:40:05.215 -> <info> app: CURRENT ROLE : 00
    
    19:40:05.215 -> <info> app: ATT MTU exchange completed.
    
    19:40:05.215 -> <info> app: Ble NUS max data length set to 0xF4(244)
    
    19:40:05.215 -> <info> app: CURRENT ROLE : 02
    
    19:40:05.262 -> <info> app: CURRENT ROLE : 00
    
    19:40:05.262 -> <info> app: CURRENT ROLE : 00
    
    19:40:05.403 -> <info> app: CURRENT ROLE : 00
    
    19:40:05.403 -> <info> app: CURRENT ROLE : 00
    
    19:40:05.403 -> <info> app: CURRENT ROLE : 00
    
    19:40:05.403 -> <info> app: CURRENT ROLE : 00
    
    19:40:05.497 -> <info> app: CURRENT ROLE : 02
    
    19:40:05.778 -> <info> app: CURRENT ROLE : 00
    
    19:40:05.778 -> <info> app: CURRENT ROLE : 00
    
    19:40:05.778 -> <info> app: CURRENT ROLE : 00
    
    19:40:05.778 -> <info> app: CURRENT ROLE : 00
    
    19:40:05.825 -> <info> app: CURRENT ROLE : 00
    
    19:40:05.918 -> <info> app: CURRENT ROLE : 02
    
    19:40:06.199 -> <info> app: CURRENT ROLE : 02
    
    19:40:06.481 -> <info> app: CURRENT ROLE : 02
    
    19:40:06.809 -> <info> app: CURRENT ROLE : 02
    
    19:40:06.949 -> <info> app: Connected to target D37CF00CAD14
    
    19:40:06.949 -> <info> app: CURRENT ROLE : 02
    
    19:40:06.949 -> <info> app: Central connected
    
    19:40:06.996 -> <info> app: Attempt to find HRS, RSC, or NUS conn_handle 0x1
    
    19:40:06.996 -> <info> app: NUS client assigned to conn_handle 0x1 (index: 1)
    
    19:40:07.090 -> <info> app: CURRENT ROLE : 02
    
    19:40:07.253 -> <info> app: CURRENT ROLE : 02
    
    19:40:07.394 -> <info> app: CURRENT ROLE : 02
    
    19:40:07.536 -> <info> app: CURRENT ROLE : 02
    
    19:40:07.585 -> <info> app: CURRENT ROLE : 02
    
    19:40:07.585 -> <info> app: ATT MTU exchange completed.
    
    19:40:07.585 -> <info> app: Ble NUS max data length set to 0xF4(244)
    
    19:40:07.585 -> <info> app: CURRENT ROLE : 02
    
    19:40:07.667 -> <info> app: CURRENT ROLE : 02
    
    19:40:07.720 -> <info> app: HRS discovered on conn_handle 0x0
    
    19:40:07.720 -> <info> app: ENTER PM EVENT HANDLER: evt_id=5
    
    19:40:07.720 -> <info> app: ENTER PM EVENT HANDLER: evt_id=1
    
    19:40:07.720 -> <info> app: Running Speed and Cadence service discovered on conn_handle 0x0
    
    19:40:07.720 -> <info> app: ENTER PM EVENT HANDLER: evt_id=5
    
    19:40:07.720 -> <info> app: current instance index 0
    19:40:07.720 -> 
    
    19:40:07.720 -> <info> app: Discovery complete ble_nus_c_evt_handler
    
    19:40:07.720 -> <info> app: Connected to device with Nordic UART Service.
    
    19:40:07.720 -> <info> app: DB Discovery instance 0x2000477C available on conn handle: 0
    
    19:40:07.764 -> <info> app: Found 3 services on conn_handle: 0
    
    19:40:07.764 -> <info> app: CURRENT ROLE : 02
    
    19:40:07.814 -> <info> app: CURRENT ROLE : 02
    
    19:40:07.850 -> <info> app: CURRENT ROLE : 02
    
    19:40:07.935 -> <info> app: CURRENT ROLE : 02
    
    19:40:08.077 -> <info> app: CURRENT ROLE : 02
    
    19:40:08.177 -> <info> app: CURRENT ROLE : 02
    
    19:40:08.260 -> <info> app: CURRENT ROLE : 02
    
    19:40:08.474 -> <info> app: CURRENT ROLE : 02
    
    19:40:08.521 -> <info> app: CURRENT ROLE : 02
    
    19:40:08.568 -> <info> app: CURRENT ROLE : 02
    
    19:40:08.661 -> <info> app: CURRENT ROLE : 02
    
    19:40:08.708 -> <info> app: CURRENT ROLE : 02
    
    19:40:08.849 -> <info> app: current instance index 1
    19:40:08.849 -> 
    
    19:40:08.849 -> <info> app: Discovery complete ble_nus_c_evt_handler
    
    19:40:08.849 -> <info> app: Connected to device with Nordic UART Service.
    
    19:40:08.849 -> <info> app: DB Discovery instance 0x20004D4C available on conn handle: 1
    
    19:40:08.849 -> <info> app: Found 3 services on conn_handle: 1
    
    19:40:08.896 -> <info> app: CURRENT ROLE : 02
    
    19:40:09.458 -> <info> app: CURRENT ROLE : 02
    
    19:40:36.485 -> <info> app: current instance index 1
    19:40:36.485 -> 
    
    19:40:36.485 -> <info> app: Disconnected from instance 1
    
    19:40:36.485 -> <info> app: Scanning filters disabled.
    
    19:40:36.485 -> <info> app: NUS UUID filter set.
    
    19:40:36.485 -> <info> app: Scanning filters enabled.
    
    19:40:36.485 -> <info> app: nrf_ble_scan_start : 0
    19:40:36.485 -> 
    
    19:40:36.485 -> <info> app: SCAN START
    
    19:40:36.485 -> <info> app: CURRENT ROLE : 02
    
    19:40:36.532 -> <info> app: Device disconnected, conn_handle: 0x1, reason: 0x8
    
    19:40:36.532 -> <info> app: nrf_ble_scan_start : 0
    19:40:36.532 -> 
    
    19:40:36.532 -> <info> app: SCAN START
    
    19:40:36.532 -> <info> app: CURRENT ROLE : 00
    
    19:40:36.532 -> <info> app: CURRENT ROLE : 00
    
    19:40:36.532 -> <info> app: CURRENT ROLE : 00
    
    19:40:36.532 -> <info> app: CURRENT ROLE : 00
    
    
    thw log output shows this for the further clarifications . 

    static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
    {   
       
        uint16_t conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
        uint16_t role        = ble_conn_state_role(conn_handle);
        NRF_LOG_INFO("CURRENT ROLE : %02X",role);
        //NRF_LOG_INFO("enter in ble evt handler \n ");
        // Based on the role this device plays in the connection, dispatch to the right handler.
        if (role == BLE_GAP_ROLE_PERIPH || ble_evt_is_advertising_timeout(p_ble_evt))
        {
            //NRF_LOG_INFO("ble gap role peripherel  \n ");
            ble_hrs_on_ble_evt(p_ble_evt, &m_hrs);
            ble_rscs_on_ble_evt(p_ble_evt, &m_rscs);
            ble_nus_on_ble_evt(p_ble_evt, &m_nus);  // Adding this line for NUS peripheral handling
            on_ble_peripheral_evt(p_ble_evt);
        }
        else if ((role == BLE_GAP_ROLE_CENTRAL) || (p_ble_evt->header.evt_id == BLE_GAP_EVT_ADV_REPORT))
        {
            //NRF_LOG_INFO("ble gap role central   \n ");
           // ble_hrs_c_on_ble_evt(p_ble_evt, &m_hrs_c);
           // ble_rscs_c_on_ble_evt(p_ble_evt, &m_rscs_c);
            for (uint8_t i = 0; i < NRF_SDH_BLE_CENTRAL_LINK_COUNT; i++)
            {
              ble_nus_c_on_ble_evt(p_ble_evt, &m_ble_nus_c_arr[i]);
            }
            //ble_nus_c_on_ble_evt(p_ble_evt,&m_ble_nus_c);   // need to check this operation is neccesssary 
            on_ble_central_evt(p_ble_evt);
        }
    }
    

    Your response is more valuable

Reply
  •  ,

    In here, we changed bonding and security encryption in the peer_manager_init() function, but it did not solve the issue. Initially, I was able to connect the gateway with two peripherals, and the gateway could connect with the nrfconnect app and send/receive data. However, if I disconnected the second connected peripheral from the gateway and powered it again, it would not connect with the gateway. But if I reconnected the first connected peripheral with the gateway, I could connect with it without any issues. The trouble only happens with the second connected peripheral.

    If I restart the gateway, I am able to connect with both peripherals. What could be the issue? I checked the ble_event_handler role and obtained 'CURRENT ROLE: 00'

    19:40:03.950 -> <info> app_timer: RTC: initialized.
    
    19:40:03.950 -> <info> app: nrf_sdh_enable_request : 0
    19:40:03.950 -> 
    
    19:40:03.950 -> <info> app: nrf_sdh_ble_default_cfg_set : 0
    19:40:03.997 -> 
    
    19:40:03.997 -> <info> app: nrf_sdh_ble_enable : 0
    19:40:03.997 -> 
    
    19:40:03.997 -> <info> app:  after nrf sdh ble observer 
    19:40:03.997 -> 
    
    19:40:03.997 -> <info> app: nrf_ble_scan_init : 0
    19:40:03.997 -> 
    
    19:40:03.997 -> <info> app: scan filter init HART_RATE_SERVICE_UUID_IDX : 0
    19:40:03.997 -> 
    
    19:40:03.997 -> <info> app: scan filter init RSCS_SERVICE_UUID_IDX : 0
    19:40:03.997 -> 
    
    19:40:03.997 -> <info> app: scan filter init NUS : 0
    19:40:03.997 -> 
    
    19:40:03.997 -> <info> app: nrf_ble_scan_filters_enable : 0
    19:40:03.997 -> 
    
    19:40:03.997 -> <info> app: nrf_ble_gatt_init : 0
    19:40:03.997 -> 
    
    19:40:03.997 -> <info> app: nrf_ble_gatt_att_mtu_central_set : 0
    19:40:03.997 -> 
    
    19:40:03.997 -> <info> app: nrf_ble_gatt_att_mtu_periph_set : 0
    19:40:03.997 -> 
    
    19:40:03.997 -> <info> app: ble_db_discovery_init :0
    19:40:03.997 -> 
    
    19:40:03.997 -> <info> app: ble_hrs_c_init : 0
    19:40:04.044 -> 
    
    19:40:04.044 -> <info> app: ble_rscs_c_init : 0
    19:40:04.044 -> 
    
    19:40:04.044 -> <info> app: ble_nus_c_init for instance 0: 0
    
    19:40:04.044 -> <info> app: ble_nus_c_init for instance 1: 0
    
    19:40:04.044 -> <info> app: nrf_ble_qwr_init : 0
    19:40:04.044 -> 
    
    19:40:04.044 -> <info> app: nrf_ble_qwr_init : 0
    19:40:04.044 -> 
    
    19:40:04.044 -> <info> app: nrf_ble_qwr_init : 0
    19:40:04.044 -> 
    
    19:40:04.044 -> <info> app: ble_hrs_init : 0
    19:40:04.044 -> 
    
    19:40:04.044 -> <info> app: ble_rscs_init : 0
    19:40:04.044 ->  
    
    19:40:04.044 -> <info> app:  ble_nus_init : 0
    19:40:04.044 -> 
    
    19:40:04.044 -> <info> app: Relay example started.
    
    19:40:04.044 -> <info> app: ADV_SCAN_START
    
    19:40:04.044 -> <info> app: nrf_ble_scan_start : 0
    19:40:04.044 -> 
    
    19:40:04.044 -> <info> app: SCAN START
    
    19:40:04.044 -> <info> app: Fast advertising.
    
    19:40:04.091 -> <info> app: CURRENT ROLE : 00
    
    19:40:05.168 -> <info> app: Connected to target E81D0E54B577
    
    19:40:05.168 -> <info> app: CURRENT ROLE : 02
    
    19:40:05.168 -> <info> app: Central connected
    
    19:40:05.168 -> <info> app: Attempt to find HRS, RSC, or NUS conn_handle 0x0
    
    19:40:05.168 -> <info> app: NUS client assigned to conn_handle 0x0 (index: 0)
    
    19:40:05.168 -> <info> app: nrf_ble_scan_start : 0
    19:40:05.168 -> 
    
    19:40:05.168 -> <info> app: SCAN START
    
    19:40:05.168 -> <info> app: CURRENT ROLE : 02
    
    19:40:05.215 -> <info> app: CURRENT ROLE : 00
    
    19:40:05.215 -> <info> app: CURRENT ROLE : 00
    
    19:40:05.215 -> <info> app: ATT MTU exchange completed.
    
    19:40:05.215 -> <info> app: Ble NUS max data length set to 0xF4(244)
    
    19:40:05.215 -> <info> app: CURRENT ROLE : 02
    
    19:40:05.262 -> <info> app: CURRENT ROLE : 00
    
    19:40:05.262 -> <info> app: CURRENT ROLE : 00
    
    19:40:05.403 -> <info> app: CURRENT ROLE : 00
    
    19:40:05.403 -> <info> app: CURRENT ROLE : 00
    
    19:40:05.403 -> <info> app: CURRENT ROLE : 00
    
    19:40:05.403 -> <info> app: CURRENT ROLE : 00
    
    19:40:05.497 -> <info> app: CURRENT ROLE : 02
    
    19:40:05.778 -> <info> app: CURRENT ROLE : 00
    
    19:40:05.778 -> <info> app: CURRENT ROLE : 00
    
    19:40:05.778 -> <info> app: CURRENT ROLE : 00
    
    19:40:05.778 -> <info> app: CURRENT ROLE : 00
    
    19:40:05.825 -> <info> app: CURRENT ROLE : 00
    
    19:40:05.918 -> <info> app: CURRENT ROLE : 02
    
    19:40:06.199 -> <info> app: CURRENT ROLE : 02
    
    19:40:06.481 -> <info> app: CURRENT ROLE : 02
    
    19:40:06.809 -> <info> app: CURRENT ROLE : 02
    
    19:40:06.949 -> <info> app: Connected to target D37CF00CAD14
    
    19:40:06.949 -> <info> app: CURRENT ROLE : 02
    
    19:40:06.949 -> <info> app: Central connected
    
    19:40:06.996 -> <info> app: Attempt to find HRS, RSC, or NUS conn_handle 0x1
    
    19:40:06.996 -> <info> app: NUS client assigned to conn_handle 0x1 (index: 1)
    
    19:40:07.090 -> <info> app: CURRENT ROLE : 02
    
    19:40:07.253 -> <info> app: CURRENT ROLE : 02
    
    19:40:07.394 -> <info> app: CURRENT ROLE : 02
    
    19:40:07.536 -> <info> app: CURRENT ROLE : 02
    
    19:40:07.585 -> <info> app: CURRENT ROLE : 02
    
    19:40:07.585 -> <info> app: ATT MTU exchange completed.
    
    19:40:07.585 -> <info> app: Ble NUS max data length set to 0xF4(244)
    
    19:40:07.585 -> <info> app: CURRENT ROLE : 02
    
    19:40:07.667 -> <info> app: CURRENT ROLE : 02
    
    19:40:07.720 -> <info> app: HRS discovered on conn_handle 0x0
    
    19:40:07.720 -> <info> app: ENTER PM EVENT HANDLER: evt_id=5
    
    19:40:07.720 -> <info> app: ENTER PM EVENT HANDLER: evt_id=1
    
    19:40:07.720 -> <info> app: Running Speed and Cadence service discovered on conn_handle 0x0
    
    19:40:07.720 -> <info> app: ENTER PM EVENT HANDLER: evt_id=5
    
    19:40:07.720 -> <info> app: current instance index 0
    19:40:07.720 -> 
    
    19:40:07.720 -> <info> app: Discovery complete ble_nus_c_evt_handler
    
    19:40:07.720 -> <info> app: Connected to device with Nordic UART Service.
    
    19:40:07.720 -> <info> app: DB Discovery instance 0x2000477C available on conn handle: 0
    
    19:40:07.764 -> <info> app: Found 3 services on conn_handle: 0
    
    19:40:07.764 -> <info> app: CURRENT ROLE : 02
    
    19:40:07.814 -> <info> app: CURRENT ROLE : 02
    
    19:40:07.850 -> <info> app: CURRENT ROLE : 02
    
    19:40:07.935 -> <info> app: CURRENT ROLE : 02
    
    19:40:08.077 -> <info> app: CURRENT ROLE : 02
    
    19:40:08.177 -> <info> app: CURRENT ROLE : 02
    
    19:40:08.260 -> <info> app: CURRENT ROLE : 02
    
    19:40:08.474 -> <info> app: CURRENT ROLE : 02
    
    19:40:08.521 -> <info> app: CURRENT ROLE : 02
    
    19:40:08.568 -> <info> app: CURRENT ROLE : 02
    
    19:40:08.661 -> <info> app: CURRENT ROLE : 02
    
    19:40:08.708 -> <info> app: CURRENT ROLE : 02
    
    19:40:08.849 -> <info> app: current instance index 1
    19:40:08.849 -> 
    
    19:40:08.849 -> <info> app: Discovery complete ble_nus_c_evt_handler
    
    19:40:08.849 -> <info> app: Connected to device with Nordic UART Service.
    
    19:40:08.849 -> <info> app: DB Discovery instance 0x20004D4C available on conn handle: 1
    
    19:40:08.849 -> <info> app: Found 3 services on conn_handle: 1
    
    19:40:08.896 -> <info> app: CURRENT ROLE : 02
    
    19:40:09.458 -> <info> app: CURRENT ROLE : 02
    
    19:40:36.485 -> <info> app: current instance index 1
    19:40:36.485 -> 
    
    19:40:36.485 -> <info> app: Disconnected from instance 1
    
    19:40:36.485 -> <info> app: Scanning filters disabled.
    
    19:40:36.485 -> <info> app: NUS UUID filter set.
    
    19:40:36.485 -> <info> app: Scanning filters enabled.
    
    19:40:36.485 -> <info> app: nrf_ble_scan_start : 0
    19:40:36.485 -> 
    
    19:40:36.485 -> <info> app: SCAN START
    
    19:40:36.485 -> <info> app: CURRENT ROLE : 02
    
    19:40:36.532 -> <info> app: Device disconnected, conn_handle: 0x1, reason: 0x8
    
    19:40:36.532 -> <info> app: nrf_ble_scan_start : 0
    19:40:36.532 -> 
    
    19:40:36.532 -> <info> app: SCAN START
    
    19:40:36.532 -> <info> app: CURRENT ROLE : 00
    
    19:40:36.532 -> <info> app: CURRENT ROLE : 00
    
    19:40:36.532 -> <info> app: CURRENT ROLE : 00
    
    19:40:36.532 -> <info> app: CURRENT ROLE : 00
    
    
    thw log output shows this for the further clarifications . 

    static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
    {   
       
        uint16_t conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
        uint16_t role        = ble_conn_state_role(conn_handle);
        NRF_LOG_INFO("CURRENT ROLE : %02X",role);
        //NRF_LOG_INFO("enter in ble evt handler \n ");
        // Based on the role this device plays in the connection, dispatch to the right handler.
        if (role == BLE_GAP_ROLE_PERIPH || ble_evt_is_advertising_timeout(p_ble_evt))
        {
            //NRF_LOG_INFO("ble gap role peripherel  \n ");
            ble_hrs_on_ble_evt(p_ble_evt, &m_hrs);
            ble_rscs_on_ble_evt(p_ble_evt, &m_rscs);
            ble_nus_on_ble_evt(p_ble_evt, &m_nus);  // Adding this line for NUS peripheral handling
            on_ble_peripheral_evt(p_ble_evt);
        }
        else if ((role == BLE_GAP_ROLE_CENTRAL) || (p_ble_evt->header.evt_id == BLE_GAP_EVT_ADV_REPORT))
        {
            //NRF_LOG_INFO("ble gap role central   \n ");
           // ble_hrs_c_on_ble_evt(p_ble_evt, &m_hrs_c);
           // ble_rscs_c_on_ble_evt(p_ble_evt, &m_rscs_c);
            for (uint8_t i = 0; i < NRF_SDH_BLE_CENTRAL_LINK_COUNT; i++)
            {
              ble_nus_c_on_ble_evt(p_ble_evt, &m_ble_nus_c_arr[i]);
            }
            //ble_nus_c_on_ble_evt(p_ble_evt,&m_ble_nus_c);   // need to check this operation is neccesssary 
            on_ble_central_evt(p_ble_evt);
        }
    }
    

    Your response is more valuable

Children
No Data
Related