This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Is there a code example of how to use uuids_more_available

Hello,

at the moment I try to add some more services to my BLE device. This goes wrong with err_code = 12 (NRF_ERROR_DATA_SIZE). With some search in the devZone I found out, that it is not possible to advertise more than two uuids because of the size limitation. Also I found out, that if I want to have more than two Services, I have to use uuids_more_available. But I didt found a simple code example of how to do that. I tried it like this:

static void advertising_init(void){
uint32_t      err_code;
ble_advdata_t advdata;
	ble_advdata_t scanrsp;
	
	ble_uuid_t adv_uuids[] = {{BLE_UUID_DEVICE_SERVICE, GRL_DEV_SERVICE_UUID_TYPE},{BLE_UUID_SERVICE_COMMAND, GRL_COM_SERVICE_UUID_TYPE}};

// Build and set advertising data.
memset(&advdata, 0, sizeof(advdata));
advdata.name_type             = BLE_ADVDATA_FULL_NAME;
	advdata.include_appearance      = true;
advdata.flags                 = BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE;
	
	memset(&scanrsp, 0, sizeof(scanrsp));
//scanrsp.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]);
//scanrsp.uuids_complete.p_uuids  = adv_uuids;
	scanrsp.uuids_more_available.uuid_cnt = 3; // new
	scanrsp.uuids_more_available.p_uuids  = adv_uuids;
	
	ble_adv_modes_config_t options = {0};
options.ble_adv_fast_enabled  = BLE_ADV_FAST_ENABLED;
options.ble_adv_fast_interval = APP_ADV_INTERVAL;
options.ble_adv_fast_timeout  = APP_ADV_TIMEOUT_IN_SECONDS;

err_code = ble_advertising_init(&advdata, &scanrsp, &options, on_adv_evt, NULL);
APP_ERROR_CHECK(err_code);}

But that doesn`t work. Anyway I get the NRF_ERROR_DATA_SIZE when I come to my services_init() function and try to add my service with sd_ble_uuid_vs_add(&com_base_uuid, &p_com->uuid_type);.

Thanks for any help.

Regards, BTprogrammer

  • No, I`m using the S120 as an peripheral.

  • So sd_ble_gatts_characteristic_add() returns NRF_ERROR_DATA_SIZE? You haven't included that part of the code. NRF_ERROR_DATA_SIZE means Invalid data size(s) supplied. What arguments are you supplying to sd_ble_gatts_characteristic_add()?

  • Hello, yes, I get the err_code=12 when calling sd_ble_characteristic_add(). This is done in the direction_char_add(...) function.

    static uint32_t direction_char_add(ble_command_t * p_com, const ble_command_init_t * p_com_init){
    ble_gatts_char_md_t char_md;
    ble_gatts_attr_md_t cccd_md;
    ble_gatts_attr_t    attr_char_value;
    ble_uuid_t          ble_uuid;
    ble_gatts_attr_md_t attr_md;
    	uint32_t   err_code=0;
    	int i=0;
    
    	for(i=0;i<4;i++)
    	{
    		commandDirection[i]= i;
    	}
    
    memset(&cccd_md, 0, sizeof(cccd_md));
    
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.read_perm);
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.write_perm);
    
    cccd_md.vloc = BLE_GATTS_VLOC_STACK;
    
    memset(&char_md, 0, sizeof(char_md));
    
    char_md.char_props.notify = 1;
    	char_md.char_props.read = 1;
    char_md.p_char_user_desc  = NULL;
    char_md.p_char_pf         = NULL;
    char_md.p_user_desc_md    = NULL;
    char_md.p_cccd_md         = &cccd_md;
    char_md.p_sccd_md         = NULL;
    
    ble_uuid.type = p_com->uuid_type;
    ble_uuid.uuid = BLE_UUID_DEV_COMMAND_DIRECTION_CHAR;
    
    memset(&attr_md, 0, sizeof(attr_md));
    
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);
    
    attr_md.vloc    = BLE_GATTS_VLOC_STACK;
    attr_md.rd_auth = 0;
    attr_md.wr_auth = 0;
    attr_md.vlen    = 1;
    
    memset(&attr_char_value, 0, sizeof(attr_char_value));
    
    attr_char_value.p_uuid    = &ble_uuid;
    attr_char_value.p_attr_md = &attr_md;
    attr_char_value.init_len  = (4*sizeof(uint8_t));
    attr_char_value.init_offs = 0;
    attr_char_value.max_len   = BLE_COMMAND_MAX_DIRECTION_LEN;
    	attr_char_value.p_value = commandDirection;
    
    	err_code = sd_ble_gatts_characteristic_add(p_com->service_handle,
                                           &char_md,
                                           &attr_char_value,
                                           &p_com->direction_handle);
    	
    	if (err_code != NRF_SUCCESS)
    {
        printf("err_code_direction_char_add=%d\r",err_code);
    			return err_code;
    }
    

    }

    So in this function I get the printf "err_code_direction_char_add=12" on the terminal. I had a look on the types of the parameters given to sd_ble_gatts_characteristic_add(...). For me it looks ok...

  • Looks ok. Could you upload your complete project so I can have a test it here? You can also share it confidentially in a private support case through your MyPage account at nordicsemi.com, if you do, please refer to this question.

  • This question was answered through a MyPage support case.

Related