This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

S140 ble_app_hrs_rscs_relay error

Hi , 

I tried to use the sample code of central and peripheral project "ble_app_hrs_rscs_relay" , to add a new service to connect with light and button peripheral by "lbs_c_init();"
which copied code from blinky_c project and added ble_lbs_c.c and ble_lbs_c.h in library. 

The peripheral device Nordic_Blinky can be connected to it but it showed the error code "<error> nrf_ble_gq: SD GATT procedure (2) failed on connection handle 0 with error: 0x00000007", any idea to solve it?

Peripheral: nRF52840DK , FW: ble_app_blinky_c_pca10056_s140

Central and Peripheral: nRF52840DK , FW: ble_app_hrs_rscs_relay_pca10056_s140

SDK: nRF5_SDK_17.0.2

Thanks.

Patrick

  • Based on your error codes it seems like you procedure NRF_BLE_GQ_REQ_GATTC_WRITE failed with NRF_ERROR_INVALID_PARAM. Check your service declaration and check what you are trying to write to it and if it has write permissions.

  • Hi Susheel,

    Thanks for your reply , the problem is fixed by adding ble_lbs_c_on_ble_evt() in the ble_evt_handler(). However I found another issue , I added the new service lbs.c from blinky client sample, and trigger to send the event when received button state change ,

    static void lbs_c_evt_handler(ble_lbs_c_t * p_lbs_c, ble_lbs_c_evt_t * p_lbs_c_evt)
    {
        switch (p_lbs_c_evt->evt_type)
        {
            case BLE_LBS_C_EVT_DISCOVERY_COMPLETE:
            {
                ret_code_t err_code;
    
                NRF_LOG_INFO("LED Button service discovered on conn_handle 0x%x.", p_lbs_c_evt->conn_handle);
    
                err_code = ble_lbs_c_handles_assign(p_lbs_c,
                                                    p_lbs_c_evt->conn_handle,
                                                    &p_lbs_c_evt->params.peer_db);
    
                err_code = app_button_enable();
                APP_ERROR_CHECK(err_code);
    
                // LED Button service discovered. Enable notification of Button.
                err_code = ble_lbs_c_button_notif_enable(p_lbs_c);
                APP_ERROR_CHECK(err_code);
            } break; // BLE_LBS_C_EVT_DISCOVERY_COMPLETE
    
            case BLE_LBS_C_EVT_BUTTON_NOTIFICATION:
            {
                ret_code_t err_code;
    
                NRF_LOG_INFO("Button state changed on peer to 0x%x.", p_lbs_c_evt->params.button.button_state);
                if (p_lbs_c_evt->params.button.button_state)
                {
                    //bsp_board_led_on(LEDBUTTON_LED); //by Patrick
                     NRF_LOG_INFO("Button ON");
                }
                else
                {
                    //bsp_board_led_off(LEDBUTTON_LED); //by Patrick
                    NRF_LOG_INFO("Button OFF");
                }
                
                //send button change notification to EBS by patrick
                NRF_LOG_INFO("Send button state change.");
                err_code = ble_lbs_on_button_send(&m_lbs, p_lbs_c_evt->params.button.button_state);
                if (err_code != NRF_SUCCESS &&
                    err_code != BLE_ERROR_INVALID_CONN_HANDLE &&
                    err_code != NRF_ERROR_INVALID_STATE &&
                    err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
                {
                    APP_ERROR_CHECK(err_code);
                }
                //end
            } break; // BLE_LBS_C_EVT_BUTTON_NOTIFICATION
    
            default:
                // No implementation needed.
                break;
        }
    }

    uint32_t ble_lbs_on_button_send(ble_lbs_t * p_lbs, uint8_t button_state)//send to EBS added by Patrick
    {
        uint32_t err_code;
    
        // Send value if connected and notifying
        if (p_lbs->conn_handle != BLE_CONN_HANDLE_INVALID)
        {
            ble_gatts_hvx_params_t params;
            uint16_t len = sizeof(button_state);
    
            memset(&params, 0, sizeof(params));
            
            params.type   = BLE_GATT_HVX_NOTIFICATION;
            params.handle = p_lbs->button_char_handles.value_handle;
            params.p_data = &button_state;
            params.p_len  = &len;
            NRF_LOG_DEBUG("gatts_hvx handle = %d, params.p_data = %d , len = %d, connection = %d \r\n",p_lbs->button_char_handles.value_handle, button_state, len, p_lbs->conn_handle);
    
            err_code=sd_ble_gatts_hvx(p_lbs->conn_handle, &params);
    
        }
        else
        {
            err_code = NRF_ERROR_INVALID_STATE;
        }
    
    }

    it shown error "<error> app: ERROR 2 [NRF_ERROR_SOFTDEVICE_NOT_ENABLED]"  once the sd_ble_gatts_hvx() command executed.

    Any hints to solve this issue?

    Thanks

    Patrick

  • Patrickcyc said:
    it shown error "<error> app: ERROR 2 [NRF_ERROR_SOFTDEVICE_NOT_ENABLED]"  once the sd_ble_gatts_hvx() command executed.

    Something is wrong with the (p_lbs->conn_handle != BLE_CONN_HANDLE_INVALID). If you have not initialized the conn_handle with BLE_CONN_HANDLE_INVALID before the connection and after the disconnection, then probably it has some garbage value which still makes the above condition pass?

    Please double check the logic around initialization and changes to p_lbs->conn_handle

Related