Read character with custom 128 bit UUID

Hello, I am currently working on the nrF52840 module with the soft device s140.

My job is to read the values ​​from different characteristics.

The characteristics are configured via individual 128-bit uuids. (UUID char 1: 470230b9-28cc-4c91-9a73-6dc094564b96)

My approach so far has been:

1. I add the individual uuid with the function sd_ble_uuid_vs_add() and save the type ->

ble_uuid128_t const base_serv_uuid =
	{
			{
					0x96, 0x4B, 0x56, 0x94, 0xC0, 0x6D, 0x73, 0x9A,
					0x91, 0x4C, 0xCC, 0x28,  0xb9, 0x30, 0x02, 0x47
			}
	};
						
ble_uuid_t read_uuid;

err_code = sd_ble_uuid_vs_add(&base_serv_uuid, &read_uuid.type);

2. Then try to read the characteristic with the sd_ble_gattc_char_value_by_uuid_read() function. In doing so, I pass the previously saved type and uuid as follows -> 

const ble_gattc_handle_range_t read_handle_range = {0x0001, 0xffff};

read_uuid.uuid = 0x30b9;
						
err_code = sd_ble_gattc_char_value_by_uuid_read(m_conn_handle, &read_uuid, &read_handle_range);

I get the BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP event but theres no handle as a response in the data package. I also tried discovering my custom chars with 

err_code = sd_ble_gattc_characteristics_discover(m_conn_handle, &read_handle_range);

but I only discover the standard characteristics with device name and so on. But no custom uuid characteristics.

Reading over the handle works fine tho, but I have to implement a version to read over the uuid.

Do I provide the uuid in the wrong format while assigning it to the ble stack or do I have to be aware of something else, like while initializing the ble stack?

Thanks for the help and I am hoping to find a solution to read my custom uuid characteristics.

Parents
  • Hello,

    I suspect that if you check p_ble_evt->evt.gattc_evt.gatt_status on BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP event you can find that p_ble_evt->evt.gattc_evt.gatt_status is BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_FOUND.

    I suspect that your UUID is not formatted correct, e.g. when calling sd_ble_gattc_char_value_by_uuid_read() you need to both have read_uuid.type from sd_ble_uuid_vs_add() and read_uuid.uuid = 0x30b9;

    If still problems you need to look at the byte orders (e.g. MSB and LSB). Some possible useful threads:

    https://devzone.nordicsemi.com/f/nordic-q-a/86291/read-value-from-several-characteristics-as-central-to-a-custom-service 
    https://devzone.nordicsemi.com/f/nordic-q-a/52251/read-added-custom-characteristic-value-from-peripheral/ 
    https://devzone.nordicsemi.com/f/nordic-q-a/20924/sd_ble_gattc_char_value_by_uuid_read---again 

    Best regards,
    Kenneth

  • Hello, thanks for the reply. I have edited my code and it looks like this currently:

    read_char_uuid.uuid = 0x30b9;
    
    ble_uuid128_t const base_read_char_uuid =
    {
    		{
    				0x96, 0x4B, 0x56, 0x94, 0xC0, 0x6D, 0x73, 0x9A,
    				0x91, 0x4C, 0xCC, 0x28, 0xb9, 0x30, 0x02, 0x47
    		}
    };
    
    
    //assign custom uuid to ble stack
    err_code = sd_ble_uuid_vs_add(&base_read_char_uuid, &read_char_uuid.type);
    
    ble_gattc_handle_range_t read_handle_range = {0x0001, 0xffff}; 
    
    //call read function
    err_code = sd_ble_gattc_char_value_by_uuid_read(m_conn_handle, &read_char_uuid, &read_handle_range);
    
    

    With this implementation I don't even get a BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP event. So I can't even check if the attribute is found or not.

    If I change the read_char_uuid.type = 0x01, I get the event but obviously no correct response data. Since I don't even get an event with my read_char_uuid.type from sd_ble_uuid_vs_add(), do you think there is an issue with the base uuid or how should I provide it?

    The UUID for this characteristics is displayed like this on the nrf Connect mobile app: 470230b9-28cc-4c91-9a73-6dc094564b96

    Or should I call the sd_ble_gattc_char_value_by_uuid_read more often with new handle_range.start?

    I tried the things from the posts you mentioned already...

    Thanks for your help

    EDIT: I got the event now and if I check the gattc_status like you mentioned I get the status BLE_GATT_STATUS_ATTERR_INVALID_HANDLE 0x0101.

    Do you know where the problem might be or what does this mean?

Reply
  • Hello, thanks for the reply. I have edited my code and it looks like this currently:

    read_char_uuid.uuid = 0x30b9;
    
    ble_uuid128_t const base_read_char_uuid =
    {
    		{
    				0x96, 0x4B, 0x56, 0x94, 0xC0, 0x6D, 0x73, 0x9A,
    				0x91, 0x4C, 0xCC, 0x28, 0xb9, 0x30, 0x02, 0x47
    		}
    };
    
    
    //assign custom uuid to ble stack
    err_code = sd_ble_uuid_vs_add(&base_read_char_uuid, &read_char_uuid.type);
    
    ble_gattc_handle_range_t read_handle_range = {0x0001, 0xffff}; 
    
    //call read function
    err_code = sd_ble_gattc_char_value_by_uuid_read(m_conn_handle, &read_char_uuid, &read_handle_range);
    
    

    With this implementation I don't even get a BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP event. So I can't even check if the attribute is found or not.

    If I change the read_char_uuid.type = 0x01, I get the event but obviously no correct response data. Since I don't even get an event with my read_char_uuid.type from sd_ble_uuid_vs_add(), do you think there is an issue with the base uuid or how should I provide it?

    The UUID for this characteristics is displayed like this on the nrf Connect mobile app: 470230b9-28cc-4c91-9a73-6dc094564b96

    Or should I call the sd_ble_gattc_char_value_by_uuid_read more often with new handle_range.start?

    I tried the things from the posts you mentioned already...

    Thanks for your help

    EDIT: I got the event now and if I check the gattc_status like you mentioned I get the status BLE_GATT_STATUS_ATTERR_INVALID_HANDLE 0x0101.

    Do you know where the problem might be or what does this mean?

Children
Related