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

Need help with understanding sd_ble_gattc_hv_confirm input parameters

Let us say we have a struct

typedef struct
{
    uint16_t                    conn_handle;    /**< Handle of the current connection (as provided by the BLE stack, is BLE_CONN_HANDLE_INVALID if not in a connection).*/
    uint16_t                    service_handle; /**< Handle of Our Service (as provided by the BLE stack). */
    // OUR_JOB: Step 2.D, Add handles for the characteristic attributes to our struct
    ble_gatts_char_handles_t    char_handles;
    // Done with step 2.D
}ble_os_t;

Using this struct I have initialized a variable as

ble_os_t *p_our_service

Next I call the SoftDevice function to update a characteristic value (It has both notify and indicate turned on)

    char_md.char_props.notify   = 1;
    char_md.char_props.indicate = 1;
   


ble_gatts_hvx_params_t hvx_params;
  memset(&hvx_params, 0, sizeof(hvx_params));

  hvx_params.handle = p_our_service->char_handles.value_handle;
  hvx_params.type   = BLE_GATT_HVX_NOTIFICATION;
  hvx_params.offset = 1;
  hvx_params.p_len  = &len;
  hvx_params.p_data = (uint16_t*)sensor_value;
  sd_ble_gatts_hvx(p_our_service->conn_handle, &hvx_params);
  err_code = sd_ble_gattc_hv_confirm(p_our_service->conn_handle, p_our_service->char_handles.value_handle);

I get a response that NRF_ERROR_INVALID_STATE for  sd_ble_gattc_hv_confirm.

Have I passed the parameters correctly or am I doing it wrong? Please help me out.

Parents Reply
  • Could you please help me on what the function will be by taking the example of this custom service tutorial:

    https://devzone.nordicsemi.com/nordic/short-range-guides/b/bluetooth-low-energy/posts/ble-services-a-beginners-tutorial

    ?

    Is it ble_our_service_on_ble_evt() ?

    I have not understood the "in response to the BLE_GATTC_EVT_HVX event" part clearly.

    It still gives me the same result. 

    void ble_our_service_on_ble_evt(ble_evt_t const * p_ble_evt, void * p_context)
    {
      	ble_os_t * p_our_service =(ble_os_t *) p_context;  
    		// OUR_JOB: Step 3.D Implement switch case handling BLE events related to our service. 
             uint32_t            err_code;
             
             err_code = sd_ble_gattc_hv_confirm(p_our_service->conn_handle, p_our_service->char_handles.value_handle);
      //APP_ERROR_CHECK(err_code);
      //if(err_code=="NRF_SUCCESS")
      switch (err_code)
        {
            case NRF_SUCCESS:
            {
                cat = 1;
                NRF_POWER->SYSTEMOFF = 1;
            } break;
            case BLE_ERROR_INVALID_CONN_HANDLE:
            {
                cat = 2;
            } break;
            case NRF_ERROR_INVALID_STATE:
            {
                cat = 3;
               // NRF_POWER->SYSTEMOFF = 1;
            } break;
            case BLE_ERROR_INVALID_ATTR_HANDLE:
            {
                cat = 4;
            } break;
            default:
                cat = 5;
                break;
    
            }
      }

Children
Related