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

Connection handle on sd_ble_gatts_rw_authorize_reply()

Hi,

I have been tryring to identify the characteristic who is requesting a read. To do so, I implemented the read authorization request. Here is my code:

case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST:
        {
            if(p_ble_evt->evt.gatts_evt.params.authorize_request.request.read.handle == p_INN_service->INN_status_handles.value_handle)
            {
                status_information_request();
                INN_SerialFrame_t* SerialFrame;
                SerialFrame = get_serial_frame();
    
                INN_payload.INN_status = SerialFrame->DataField[1];
                INN_payload.error_flags = SerialFrame->DataField[2];

                for(int i = 0; i < 4; i++)
                    INN_payload.progression_state[i] = SerialFrame->DataField[i+3];

                for(int i = 0; i < 4; i++)
                    INN_payload.last_estimated_pos[i] = SerialFrame->DataField[i+7];

                INN_payload.current_nRF_state = SerialFrame->DataField[11];
                INN_payload.last_motor_control_state = SerialFrame->DataField[12];

                for(int i = 0; i < 12; i++)
                    INN_payload.complete_payload[i] = SerialFrame->DataField[i+1];
    
                INN_request_flag = 0;
                ble_gatts_rw_authorize_reply_params_t rw_authorize_reply_params;
                rw_authorize_reply_params.type = BLE_GATTS_AUTHORIZE_TYPE_READ;
                rw_authorize_reply_params.params.read.offset = 0;
                rw_authorize_reply_params.params.read.update = 1;
                rw_authorize_reply_params.params.read.len = 12;
                rw_authorize_reply_params.params.read.p_data = INN_payload.complete_payload;

                uint32_t err_code;
                err_code = sd_ble_gatts_rw_authorize_reply(p_ble_evt->evt.gatts_evt.conn_handle, &rw_authorize_reply_params);
                APP_ERROR_CHECK(err_code);
                
            }
            break;

Basically, on read request I get data via UART (it is static for now and I fill the buffers before the read request fot the test) and I want to send them to my characteristic. The probleme I have is with the sd_ble_gatts_rw_authorize_reply() function. I first tried to use p_ble_evt->evt.gatts_evt.params.authorize_request.request.read.handle as my handle as it was the one containing the handle of the characteristic requesting a read, but it returned the BLE_ERROR_INVALID_CONN_HANDLE error (err_code 12290).

I then used p_ble_evt->evt.gatts_evt.conn_handle, and this time there is no error when I request a read, but nothing is returned to my phone. In debug mode, I saw that conn_handle was empty (0x0000) hence why I am not receiving anything when I read the proper characteristic on nRF Connect for Mobile.

I assume that I must be using p_ble_evt->evt.gatts_evt.conn_handle for the function to properly work but it does not take the value of the concerned characteristic. When I try to force the right handle, it returns an error. What am I missing ?

I am currently working on nRF52840 DK with s140 SoftDevice.

Thanks in advance,

FM

Related