I want to read characteristics (central needs read data from peripheral whenever he want ) but don’t want to use notification.
I am trying this with authorization but it can not generate BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST event. I just didn’t get what are the exactly settings required for that. I made changes in led service characteristics as follows.
What are the exactly changes I have to done here?
OR
Is there any example available where such solution used?
uint32_t ble_lbs_init(ble_lbs_t * p_lbs, const ble_lbs_init_t * p_lbs_init ) { uint32_t err_code; ble_uuid_t ble_uuid; ble_add_char_params_t add_char_params; ble_gatts_attr_md_t attr_md; // Initialize service structure. p_lbs->led_write_handler = p_lbs_init->led_write_handler; // Add service. ble_uuid128_t base_uuid = {LBS_UUID_BASE}; err_code = sd_ble_uuid_vs_add(&base_uuid, &p_lbs->uuid_type); VERIFY_SUCCESS(err_code); ble_uuid.type = p_lbs->uuid_type; ble_uuid.uuid = LBS_UUID_SERVICE; err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &p_lbs->service_handle); VERIFY_SUCCESS(err_code); // Add LED characteristic. memset(&add_char_params, 0, sizeof(add_char_params)); add_char_params.uuid = LBS_UUID_LED_CHAR; add_char_params.uuid_type = p_lbs->uuid_type; add_char_params.init_len = sizeof(uint8_t); add_char_params.max_len = sizeof(uint8_t); add_char_params.char_props.read = 1; add_char_params.char_props.write = 1; attr_md.rd_auth = 1; add_char_params.read_access = SEC_OPEN; add_char_params.write_access = SEC_OPEN; err_code = characteristic_add(p_lbs->service_handle, &add_char_params, &p_lbs->led_char_handles); } void ble_lbs_on_ble_evt(ble_evt_t const * p_ble_evt, void * p_context) { ble_lbs_t * p_lbs = (ble_lbs_t *)p_context; switch (p_ble_evt->header.evt_id) { case BLE_GATTS_EVT_WRITE: on_write(p_lbs, p_ble_evt); break; case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST: on_read(p_lbs, p_ble_evt); break; default: // No implementation needed. break; } } static void on_read(ble_lbs_t * p_lbs, ble_evt_t const * p_ble_evt) { uint32_t err_code; uint8_t update_data = 0xAB; ble_gatts_rw_authorize_reply_params_t reply_params; memset(&reply_params, 0, sizeof(reply_params)); reply_params.type = BLE_GATTS_AUTHORIZE_TYPE_READ; reply_params.params.read.p_data = &update_data; reply_params.params.read.len = sizeof(update_data); reply_params.params.read.offset = 0; reply_params.params.read.update = 0; reply_params.params.read.gatt_status = NRF_SUCCESS; sd_ble_gatts_rw_authorize_reply(p_ble_evt->evt.gap_evt.conn_handle, &reply_params); }
Thanks in advance.
Regards,
Pooja