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

How to get UUID of Characteristic from a ble_evt_t?

Hello:

I am writing a BLE profile involving several characteristics. One of the characteristics is an operation code (read/write) tunnel.

Each time a BLE central device writes to the BLE peripheral (nRF51 10028 board), I would like to check the characteristic being written to, so that the application can properly respond to whatever operation is requested by the central.

I figure that I would do this by getting the UUID of the characteristic that was written. Any write to a characteristic will trigger a BLE event (in the on_ble_evt() event handler in main.c) with a header.evt_uid of BLE_GATTS_EVT_WRITE.

How would I go about getting the UUID of the characteristic being written (i.e., the one triggering the BLE event handler, which throws the BLE_GATTS_EVT_WRITE)?

Is this the right way to model a central-peripheral, command-response relationship? Is checking the UUID of the written characteristic the best way to respond to written commands?


static void command_characterstic_write_evt_dispatch(ble_evt_t * p_ble_evt)
{
//Get characteristic UUID and handle actions from there (or check respective value of each characteristic (compared to previous value) and do proper action). 
ble_uuid_t evt_uuid = p_ble_evt->evt.gattc_evt.params.char_val_by_uuid_read_rsp;
SEGGER_RTT_printf(0,"\n Updated characteristic with handle (UUID) %o", evt_uuid);
switch(evt_uuid)
{
	case BLE_UUID_COMMAND_BUFFER_TUNNEL_CHARACTERISTIC_UUID: 

	default:
		break;
} }

Where the characteristic UUID is 0x2000 or BLE_UUID_COMMAND_BUFFER_TUNNEL_CHARACTERISTIC_UUID

Parents
  • If i understoond your question correctly, then the answer would be no. The proper way is setting your own custom service with your characteristics. That way you can set up to get a callback when you have written something to any of your characteristics. You can set up a single handler for many characteristics and just check the value that you have written, or you can set up a different handler for every characteristic. That is up to you. How to set up your own service with characteristics can be found here: BLE Services, BLE Characteristics

  • Thank you for responding. Sorry if I did not make my situation clear.

    I am writing my own service with three different characteristics. Each characteristic has its own UUID (0x2000, 0x2001, and 0x2002). And I do have a function that responds to BLE_GATTS_EVT_WRITE's, as in, anytime a characteristic is update, either from a central or the peripheral device (on which I am running this application), the evt_write dispatch method (provided above) is invoked.

    My objective right now is to be able to get the UUID of the characteristic being written.I was just inquiring as to if it was possible to get the UUID of the written characteristic from the ble_evt_t that is provided by the on_ble_evt(ble_evt_t * p_ble_evt) method in the main.c

Reply
  • Thank you for responding. Sorry if I did not make my situation clear.

    I am writing my own service with three different characteristics. Each characteristic has its own UUID (0x2000, 0x2001, and 0x2002). And I do have a function that responds to BLE_GATTS_EVT_WRITE's, as in, anytime a characteristic is update, either from a central or the peripheral device (on which I am running this application), the evt_write dispatch method (provided above) is invoked.

    My objective right now is to be able to get the UUID of the characteristic being written.I was just inquiring as to if it was possible to get the UUID of the written characteristic from the ble_evt_t that is provided by the on_ble_evt(ble_evt_t * p_ble_evt) method in the main.c

Children
No Data
Related