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

How to do reads from characteristic with read and write access?

I'm trying to create a service with 2 characteristics.
One is a MTU to send large amounts of data from my peripheral via notifications to the host and the other is a RW characteristic, with a max len of 4 bytes, that I'll use for my "protocol".
I added the characteristics and it works fine for sending the large (MTU) data up to the host and I receive data from the host in the protocol characteristic, but I don't know how to respond to a read of the data from my protocol characteristic.

here is how I create my service:

err_code = sd_ble_uuid_vs_add(&base_uuid, &(m_MyService_ctx.uuid_type));
APP_ERROR_CHECK(err_code);

ble_uuid.type = m_MyService_ctx.uuid_type;
ble_uuid.uuid = AMT_SERVICE_UUID;

// Add service.
err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &service_handle);
APP_ERROR_CHECK(err_code);

// Add MTU characteristic.
ble_add_char_params_t amt_params;
memset(&amt_params, 0, sizeof(amt_params));

amt_params.uuid = AMTS_CHAR_UUID;
amt_params.uuid_type = m_MyService_ctx.uuid_type;
amt_params.max_len = NRF_SDH_BLE_GATT_MAX_MTU_SIZE;
amt_params.char_props.notify = 1;
amt_params.cccd_write_access = SEC_OPEN;
amt_params.is_var_len = 1;

err_code = characteristic_add(service_handle, &amt_params, &(m_MyService_ctx.amts_char_handles));
APP_ERROR_CHECK(err_code);

//
// Add My Protocol characteristic.
//
ble_add_char_params_t MyProtocol_params;
memset(&MyProtocol_params, 0, sizeof(MyProtocol_params));

MyProtocol_params.uuid = MY_PROTOCOL_CHAR_UUID;
MyProtocol_params.uuid_type = m_MyService_ctx.uuid_type;
MyProtocol_params.max_len = MY_PROTOCOL_MAX_LEN;
MyProtocol_params.char_props.read = 1;
MyProtocol_params.char_props.write = 1;
//MyProtocol_params.cccd_write_access = SEC_OPEN;
MyProtocol_params.write_access = SEC_OPEN;
MyProtocol_params.read_access = SEC_OPEN;

err_code = characteristic_add(service_handle, &MyProtocol_params, &(m_MyService_ctx.MyProtocol_char_handles));
APP_ERROR_CHECK(err_code);

m_MyService_ctx.evt_handler = MyService_evt_handler;

BT_mtu_set(MyService_MTU_Params.att_mtu);
BT_data_len_ext_set(MyService_MTU_Params.data_len_ext_enabled);

MyService_conn_evt_len_ext_set(MyService_MTU_Params.conn_evt_len_ext_enabled);

 

Could you help me with this please?

Related