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

Return success/failure on BLE characteristic write (nRf52832)

Hi, I want to create one system. When master writes data of Nordic, I receive callback with BLE_GATTS_EVT_WRITE case. Here I want to write return to master with success/ failure based on write data, How we can control of write success/failure from Nordic?

Thanks

Parents Reply
  • static void on_write_auth(ble_evt_t const * p_ble_evt) {
    	ret_code_t err_code = NRF_SUCCESS;
    	ble_gatts_rw_authorize_reply_params_t auth_reply;
    	uint8_t * p_data = (uint8_t *)(p_ble_evt->evt.gatts_evt.params.authorize_request.request.write.data);
    	uint16_t len = p_ble_evt->evt.gatts_evt.params.authorize_request.request.write.len;
    
    	uint16_t char_UUID = p_ble_evt->evt.gatts_evt.params.authorize_request.request.write.uuid.uuid;
    	uint16_t offset = p_ble_evt->evt.gatts_evt.params.authorize_request.request.write.offset;
    
    	err_code = parse_ble_data(char_UUID, p_data, len, offset);
    
    	if (err_code == NRF_SUCCESS) {
    		auth_reply.type = BLE_GATTS_AUTHORIZE_TYPE_WRITE;
    		auth_reply.params.write.gatt_status = BLE_GATT_STATUS_SUCCESS;
    		auth_reply.params.write.update = 1;
    		auth_reply.params.write.len = len;
    		auth_reply.params.write.offset = offset;
    		auth_reply.params.write.p_data = p_data;
    	} else {
    		auth_reply.type = BLE_GATTS_AUTHORIZE_TYPE_WRITE;
    		auth_reply.params.write.gatt_status = BLE_GATT_STATUS_ATTERR_WRITE_NOT_PERMITTED;
    	}
    	err_code = sd_ble_gatts_rw_authorize_reply(p_ble_evt->evt.gatts_evt.conn_handle, &auth_reply);
    	APP_ERROR_CHECK(err_code);
    }

Children
Related