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

How to generate different UUID's for service and characteristics

Hello,

I want to generate different UUID for service and for characteristics with different base address for both.

I am updating base address in characteristics_add function and uses this function: err_code = sd_ble_uuid_vs_add(&base_uuid, &char_uuid.type); before, sd_ble_gatts_characteristic_add();

But still I am getting the base address of service only not the upadated characteristics base address.

I am not getting what would be the problem

  • Can you post some more detailed code about how you do this? How are you checking the new UUID? Also, see this thread.

  • Thank you for your reply. This is my code: BLE stack init:

    static void ble_stack_init(void)
    {
    	uint32_t err_code;
    
    	nrf_clock_lf_cfg_t clock_lf_cfg = NRF_CLOCK_LFCLKSRC;
    
    	// Initialize the SoftDevice handler module
    	SOFTDEVICE_HANDLER_INIT(&clock_lf_cfg, NULL);
    
    	ble_enable_params_t ble_enable_params;
    	err_code = softdevice_enable_get_default_config(CENTRAL_LINK_COUNT,
    													PERIPHERAL_LINK_COUNT,
    													&ble_enable_params);
    	APP_ERROR_CHECK(err_code);
    
    	// Check the ram settings against the used number of links
    	CHECK_RAM_START_ADDR(CENTRAL_LINK_COUNT, PERIPHERAL_LINK_COUNT);
    
    	// Enable BLE stack
    	ble_enable_params.gatts_enable_params.service_changed = IS_SRVC_CHANGED_CHARACT_PRESENT;
    	err_code = softdevice_enable(&ble_enable_params);
    	APP_ERROR_CHECK(err_code);
    
    	// Register with the SoftDevice handler module for BLE events
    	err_code = softdevice_ble_evt_handler_set(ble_evt_dispatch);
    	APP_ERROR_CHECK(err_code);
    
    	// Register with the SoftDevice handler module for BLE events
    	err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);
    	APP_ERROR_CHECK(err_code);
    

    For service initialization:

    void temperature_service_init()
    {
        ble_uuid_t service_uuid;
        ble_uuid128_t base_uuid = BLE_UUID_TEMPERATURE_BASE_UUID;
        uint8_t i;
        uint32_t err_code;
    
        service_uuid.uuid = BLE_UUID_TEMPERATURE_SERVICE;
        err_code = sd_ble_uuid_vs_add(&base_uuid, &service_uuid.type);
        APP_ERROR_CHECK(err_code);
    
        m_temperature_service.conn_handle = BLE_CONN_HANDLE_INVALID;
    
        err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY,
                                            &service_uuid,
                                            &m_temperature_service.service_handle);
        APP_ERROR_CHECK(err_code);
    
        temperature_service_char_add(BLE_UUID_TEMPERATURE_CHAR_UUID, 0, true, false, true, 4);
    }
    
    temperature_service_char_add()-->
    
    ble_uuid128_t base_uuid = {{0xa5, 0xa5, 0x00, 0x5b, 0x02, 0x00, 0x23, 0x9b, 0xe1, 0x11, 0x02, 0xd1, 0x00, 0x00, 0x34, 0x12}};
    	ble_uuid_t char_uuid;
    	ble_gatts_char_md_t char_md;
    	ble_gatts_attr_md_t cccd_md;
    	ble_gatts_attr_md_t attr_md;
    	ble_gatts_attr_t attr_char_value;
    	uint8_t value[20] = {0x12,0x34,0x56,0x78};
    	uint32_t err_code = 0;
    
    	char_uuid.uuid = uuid;
    	char_uuid.type = BLE_UUID_TYPE_VENDOR_BEGIN;
    	err_code = sd_ble_uuid_vs_add(&base_uuid, &char_uuid.type);
    	APP_ERROR_CHECK(err_code);
    
    	memset(&char_md, 0, sizeof(char_md));
    	memset(&cccd_md, 0, sizeof(cccd_md));
    	memset(&attr_md, 0, sizeof(attr_md));
    	memset(&attr_char_value, 0, sizeof(attr_char_value));
    
    	if(read_perm == true) {
    		char_md.char_props.read = 1;
    	} else {
    		char_md.char_props.read = 0;
    	}// if(read_perm == true)
    	BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.read_perm);
    	BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
    	if(write_perm == true) {
    		char_md.char_props.write = 1;
    	} else {
    		char_md.char_props.write = 0;
    	}// if(write_perm == true)
    	BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.write_perm);
    	BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);
    
    	cccd_md.vloc = BLE_GATTS_VLOC_STACK;
    	char_md.p_cccd_md = &cccd_md;
    	if(notify_status == true) {
    		char_md.char_props.notify = 1;
    	} else {
    		char_md.char_props.notify = 0;
    	}// if(notify_status == true)
    
    	attr_md.vloc = BLE_GATTS_VLOC_STACK;
    
    	attr_char_value.p_uuid = &char_uuid;
    	attr_char_value.p_attr_md = &attr_md;
    	attr_char_value.max_len = char_length;
    	attr_char_value.init_len = char_length;
    	attr_char_value.p_value = value;
    
    	err_code = sd_ble_gatts_characteristic_add(m_temperature_service.service_handle,
    									   &char_md,
    									   &attr_char_value,
    									   &m_temperature_service.char_handles[handle_num]);
    	APP_ERROR_CHECK(err_code);
    

    I want separate base UUID for service and for characteristics

  • The above code gives only one base UUID, but i need two separate base UUID's for service and characteristics. when I add separate base UUID for characteristics it get crashes. I am checking UUID's directly on mobile app nRF Connect.

  • You say it "crashes", do you mean that you get an error code? Have you checked what the error code is using debugging? I checked your code (incorporated the relevant lines into one of the SDK examples, as I don't have your complete application), and I got two separate base UUIDs showing in nRF Connect.

Related