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

Full example of read char by UUID

Good day!

Work with nrf51822 central with S130,

I've read this questions and links in answers:

I've read documentation:

Finally all I've done:

main.c

ble_uuid_t m_uuid;
m_uuid.type = m_ble_lgs_c.uuid_type;
m_uuid.uuid = LGS_UUID_SERVICE;

ble_gattc_handle_range_t handle_range;
handle_range.start_handle = 0x0001;
handle_range.end_handle = 0xFFFF;

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 to handle event

static void on_ble_evt(const ble_evt_t * const p_ble_evt) {
	ret_code_t err_code;

	// For readability.
	const ble_gap_evt_t * const p_gap_evt = &p_ble_evt->evt.gap_evt;

	switch (p_ble_evt->header.evt_id) {
	// Upon connection, check which peripheral has connected (HR or RSC), initiate DB
	// discovery, update LEDs status and resume scanning if necessary. */
	case BLE_GAP_EVT_CONNECTED: {
		NRF_LOG_INFO("Connected.\r\n");
		err_code = ble_lgs_c_handles_assign(&m_ble_lgs_c,
				p_gap_evt->conn_handle, NULL);
		APP_ERROR_CHECK(err_code);

		err_code = ble_db_discovery_start(&m_ble_db_discovery,
				p_gap_evt->conn_handle);
		APP_ERROR_CHECK(err_code);

		// Update LEDs status, and check if we should be looking for more
		// peripherals to connect to.
		bsp_board_led_on(CENTRAL_CONNECTED_LED);
		bsp_board_led_off(CENTRAL_SCANNING_LED);
	}
		break;

		// Upon disconnection, reset the connection handle of the peer which disconnected, update
		// the LEDs status and start scanning again.
	case BLE_GAP_EVT_DISCONNECTED: {
		NRF_LOG_INFO("Disconnected.\r\n");
		play_sound(df_DCONNECT);
		scan_start();
	}
		break;

	case BLE_GAP_EVT_ADV_REPORT: {
		on_adv_report(p_ble_evt);
	}
		break;

	case BLE_GAP_EVT_TIMEOUT: {
		// We have not specified a timeout for scanning, so only connection attemps can timeout.
		if (p_gap_evt->params.timeout.src == BLE_GAP_TIMEOUT_SRC_CONN) {
			NRF_LOG_DEBUG("Connection request timed out.\r\n");
		}
	}
		break;

	case BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST: {
		// Accept parameters requested by peer.
		err_code = sd_ble_gap_conn_param_update(p_gap_evt->conn_handle,
				&p_gap_evt->params.conn_param_update_request.conn_params);
		APP_ERROR_CHECK(err_code);
	}
		break;

	case BLE_GATTC_EVT_TIMEOUT: {
		// Disconnect on GATT Client timeout event.
		NRF_LOG_DEBUG("GATT Client Timeout.\r\n");
		err_code = sd_ble_gap_disconnect(p_ble_evt->evt.gattc_evt.conn_handle,
		BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
		APP_ERROR_CHECK(err_code);
	}
		break;

	case BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP: {




		}
			break;


	case BLE_GATTS_EVT_TIMEOUT: {
		// Disconnect on GATT Server timeout event.
		NRF_LOG_DEBUG("GATT Server Timeout.\r\n");
		err_code = sd_ble_gap_disconnect(p_ble_evt->evt.gatts_evt.conn_handle,
		BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
		APP_ERROR_CHECK(err_code);
	}
		break;

#if (NRF_SD_BLE_API_VERSION == 3)
		case BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST:
		{
			err_code = sd_ble_gatts_exchange_mtu_reply(p_ble_evt->evt.gatts_evt.conn_handle,
					NRF_BLE_MAX_MTU_SIZE);
			APP_ERROR_CHECK(err_code);
		}break;
#endif

	default:
		// No implementation needed.
		break;
	}
}

The question is: what to do in case BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP?

Parents Reply Children
No Data
Related