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

BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST problem :

Hello,

I am using CUSTOM service in nrf52 for BLE Communication.In the tutorial, there isn't any BLE READ event but I figured that BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST event is generated when we send request to read the data from the device. But once that event is generated nrf52 hangs or something like that and it gets disconnected. 

Can you tell me the possible reason behind that?

Thanks in advance.

Parents Reply
  • Here is my code:

    static void on_read(ble_cus_t * p_cus, ble_evt_t const * p_ble_evt)
    {
        uint32_t time = 0;
        ret_code_t err_code;
        ble_gatts_evt_rw_authorize_request_t  req = p_ble_evt->evt.gatts_evt.params.authorize_request;
        unsigned char data[5]="Hello";
    
        if(req.type == BLE_GATTS_AUTHORIZE_TYPE_READ){
            ble_gatts_rw_authorize_reply_params_t response;
            response.params.read.gatt_status = BLE_GATT_STATUS_SUCCESS;
            response.type = BLE_GATTS_AUTHORIZE_TYPE_READ;
            response.params.read.update = 1;
            response.params.read.offset = 0;
            response.params.read.len =20;
            response.params.read.p_data = (uint8_t *)data;
    
            response.params.read.gatt_status = (BLE_GATT_STATUS_ATTERR_APP_BEGIN + 2); // Feature not supported
            err_code=sd_ble_gatts_rw_authorize_reply(p_ble_evt->evt.gatts_evt.conn_handle, &response);
            APP_ERROR_CHECK(err_code);
            NRF_LOG_INFO("Reply function responded with: %d", err_code);
        }
    }

    But could not get any value when read command is sent by mobile device. Please guide me.
    Thank you in advance.
Children
  • Hi,

    Try this:

    static void on_read(ble_cus_t * p_cus, ble_evt_t const * p_ble_evt)
    {
        uint32_t time = 0;
        ret_code_t err_code;
        ble_gatts_evt_rw_authorize_request_t  req = p_ble_evt->evt.gatts_evt.params.authorize_request;
        unsigned char data[1]="H";
    
        if(req.type == BLE_GATTS_AUTHORIZE_TYPE_READ){
            ble_gatts_rw_authorize_reply_params_t response;
            response.params.read.gatt_status = BLE_GATT_STATUS_SUCCESS;
            response.type = BLE_GATTS_AUTHORIZE_TYPE_READ;
            response.params.read.update = 1;
            response.params.read.offset = 0;
            response.params.read.len =1;
            response.params.read.p_data = (uint8_t *)data;
    
     
            err_code=sd_ble_gatts_rw_authorize_reply(p_ble_evt->evt.gatts_evt.conn_handle, &response);
            APP_ERROR_CHECK(err_code);
            NRF_LOG_INFO("Reply function responded with: %d", err_code);
        }
    }

    PS: From your function custom_value_char_add(), you are setting max length to 1 byte:

    attr_char_value.max_len = sizeof(uint8_t);

    If it's still not working, then let me know if e.g. sd_ble_gatts_rw_authorize_reply() returned any error codes.

Related