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

Get connected device name in Generic Access Service from ble central

Hi all,

I would like to get the complete name from the connected peripheral by reading the device name characteristic (0x2A00) in the Generic Access Service (0x1800). I am using SDK 15.2.0 with soft device s132 v6.1.1.

I have tried to call sd_ble_gattc_char_value_by_uuid_read in BLE_GAP_EVT_CONNECTED event, and then get the device name through p_ble_evt->evt.gattc_evt.params.char_val_by_uuid_read_rsp.handle_value in BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP event. But it never runs inside the event BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP.  I have tested another way by using p_ble_evt->evt.gatts_evt.params.write.data but it didn't get the device name.

So I would like to know how I can do that.

Many thanks in advance.

  • Does sd_ble_gattc_char_value_by_uuid_read(..) return NRF_SUCCESS? If it does, could you provide a sniffer trace? If not, what does it return?

    Best regards,

    Simon

  • I did this once by discovering the characteristic using the discovery module, storing the value handle and then calling sd_ble_gattc_read() using that value handle. It worked like a charm.

  • Hi Simon,
    Thank for your reply. I haven't used sniffer, so I will try later. Is there any other way to check it

  • Hi Andy,
    Thank for your reply. Could you explain more detail about how you do.
    What are the references I must put in "handle" and "offset".
    Where I have to call sd_ble_gattc_read(), in BLE_GAP_EVT_CONNECTED event or in EVT_DISCOVERY_COMPLETE event.
    And how to get the value.
    Many thanks in advance.

  • On your discovery event handler you do this:

    if ((p_evt->evt_type == BLE_DB_DISCOVERY_COMPLETE) &&
    	(p_evt->params.discovered_db.srv_uuid.uuid == gap_profile_s_uuid.uuid) &&
    	(p_evt->params.discovered_db.srv_uuid.type == gap_profile_s_uuid.type)) {
    
    	NRF_LOG_INFO("Found GAP profile service");
    
    	// Find the CCCD Handles of the device name characteristic
    	for (uint8_t i = 0; i < p_evt->params.discovered_db.char_count; i++) {
    		if ((p_evt->params.discovered_db.charateristics[i].characteristic.uuid.uuid == device_name_c_uuid.uuid) &&
    			(p_evt->params.discovered_db.charateristics[i].characteristic.uuid.type == device_name_c_uuid.type)) {
    
    			NRF_LOG_INFO("Found device name characteristic");
    			device_name_handle = p_evt->params.discovered_db.charateristics[i].characteristic.handle_value;
    
    			// Break out of for loop
    			break;
    		}
    	}
    }

    Then you can use the device_name_handle in sd_ble_gattc_read(). In the offset just write 0. Where you call sd_ble_gattc_read() is up to you, and it doesn't really matter.

    To get the device name data, you need to do this in you BLE event handler:

    case BLE_GATTC_EVT_READ_RSP:;
    	ble_gattc_evt_read_rsp_t const * p_read_rsp = &p_ble_evt->evt.gattc_evt.params.read_rsp;
    
    	NRF_LOG_INFO("Read length: %d, Read offset: %d", p_read_rsp->len, p_read_rsp->offset);
    
    	// We are reading the device name
    	if (p_read_rsp->handle == device_name_handle) {
    		for (uint8_t i = 0; i < p_read_rsp->len; i++) {
    			device_name[i + p_read_rsp->offset] = p_read_rsp->data[i];
    		}
    		device_name_length = p_read_rsp->len + p_read_rsp->offset;
    	}
    	break;

Related