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

event form read request

Hi,

I'm using SDK 15.2 with Nrf52832,

I've implemented a custom service with read, write and notification services.

I would appreciate if you could send me an example of how to get an event of a read request, I understand that its part of the SodtDevice and I can get authorize read event - but it is not clear how...

Shimon

Parents
  • Hi Shimon, 

    Normal read requests are handled without application interaction. If you want to receive an event you need to enable authorization like you indicated (MSC). Below is a diff showing the changes needed to enable this in the ble_app_blinky_example.

    diff --git a/components/ble/ble_services/ble_lbs/ble_lbs.c b/components/ble/ble_services/ble_lbs/ble_lbs.c
    index 1c83a99..5324428 100644
    --- a/components/ble/ble_services/ble_lbs/ble_lbs.c
    +++ b/components/ble/ble_services/ble_lbs/ble_lbs.c
    @@ -60,6 +60,24 @@ static void on_write(ble_lbs_t * p_lbs, ble_evt_t const * p_ble_evt)
         }
     }
     
    +static void on_rw_authorize_request(ble_lbs_t * p_lbs, ble_evt_t const * p_ble_evt)
    +{
    +      ble_gatts_rw_authorize_reply_params_t        reply_params;
    +      ble_gatts_evt_rw_authorize_request_t const * p_evt_rw_auth = &p_ble_evt->evt.gatts_evt.params.authorize_request;
    +
    +      memset (&reply_params, 0, sizeof(ble_gatts_rw_authorize_reply_params_t));
    +
    +      if ( (p_evt_rw_auth->type == BLE_GATTS_AUTHORIZE_TYPE_READ) &&
    +           (p_lbs->button_char_handles.value_handle == p_evt_rw_auth->request.read.handle))
    +      {
    +          reply_params.type = BLE_GATTS_AUTHORIZE_TYPE_READ;
    +          reply_params.params.read.gatt_status = BLE_GATT_STATUS_SUCCESS;
    +
    +          (void) sd_ble_gatts_rw_authorize_reply(p_ble_evt->evt.common_evt.conn_handle, &reply_params);
    +          
    +      }
    +
    +}
     
     void ble_lbs_on_ble_evt(ble_evt_t const * p_ble_evt, void * p_context)
     {
    @@ -71,6 +89,10 @@ void ble_lbs_on_ble_evt(ble_evt_t const * p_ble_evt, void * p_context)
                 on_write(p_lbs, p_ble_evt);
                 break;
     
    +        case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST:
    +            on_rw_authorize_request(p_lbs, p_ble_evt);
    +            break;
    +
             default:
                 // No implementation needed.
                 break;
    @@ -106,6 +128,8 @@ uint32_t ble_lbs_init(ble_lbs_t * p_lbs, const ble_lbs_init_t * p_lbs_init)
         add_char_params.max_len           = sizeof(uint8_t);
         add_char_params.char_props.read   = 1;
         add_char_params.char_props.notify = 1;
    +    add_char_params.is_defered_read   = 1;
    +
     
         add_char_params.read_access       = SEC_OPEN;
         add_char_params.cccd_write_access = SEC_OPEN;
    
    

    If anything is unclear, let me know. 

    Vidar

  • Good day! Do you have an example for read event on gatt client side?

    I used S130 and this code worked fine:

                        ble_uuid_t m_uuid;
        				m_uuid.type = BLE_UUID_TYPE_VENDOR_BEGIN;
        				m_uuid.uuid = LGS_UUID_TYPE_CHAR;
    
        				ble_gattc_handle_range_t handle_range;
        				handle_range.start_handle = 0x0001;
        				handle_range.end_handle = 0xFFFF;
    
        				NRF_LOG_INFO("Reading....\n");
        				ret_code_t err_code = sd_ble_gattc_char_value_by_uuid_read(m_ble_lgs_c.conn_handle,
        						&m_uuid, &handle_range);
        				APP_ERROR_CHECK(err_code);

    and in ble_evt_handler

    case BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP: {
    
    		
    		uint8_t * ble_data_ptr =
    				p_ble_evt->evt.gattc_evt.params.char_val_by_uuid_read_rsp.handle_value->p_value;
    		printf("0x%x\t", *ble_data_ptr);
    		printf("0x%x\r\n", *(ble_data_ptr + 1));
    
    	}

    When I migrate to S132 this part crashes with fatal error

Reply Children
No Data
Related