DA14531 Name Change Service/Characteristic

I was curious if there's a characteristic to change the GAP device name.

I know there's one to see the name, but I didn't see one to change the name. Is this one I'd have to manually create or is there a simple way to do so?


  • Hi There,

    Thank you for posting your question online.
    Yes, it is possible to change the Device Name. 
    I worked on the ble_app_peripheral example with SDK v6.0.18.
    I created a custom characteristic for the Custom Service 1.
    On user_custs1_impl.c file:

    void user_svc1_dev_name_wr_ind_handler (ke_msg_id_t const msgid,
                                          struct custs1_val_write_ind const *param,
                                          ke_task_id_t const dest_id,
                                          ke_task_id_t const src_id)
    	char new_device_name[NEW_DEVICE_NAME_LENGTH] = "\0";
    	memcpy(&new_device_name, &param->value, param->length);
    	device_info.dev_name.length = (strlen(new_device_name) <= GAP_MAX_NAME_SIZE) ?strlen(new_device_name) : GAP_MAX_NAME_SIZE;
    	memcpy(device_info.dev_name.name, new_device_name, device_info.dev_name.length);

    On user_peripheral.c file:
    void user_catch_rest_hndl(ke_msg_id_t const msgid,
                              void const *param,
                              ke_task_id_t const dest_id,
                              ke_task_id_t const src_id)
            case CUSTS1_VAL_WRITE_IND:
                struct custs1_val_write_ind const *msg_param = (struct custs1_val_write_ind const *)(param);
                switch (msg_param->handle)
                    case SVC1_IDX_CONTROL_POINT_VAL:
                        user_svc1_ctrl_wr_ind_handler(msgid, msg_param, dest_id, src_id);
                    case SVC1_IDX_DEV_NAME_VAL:
                        user_svc1_dev_name_wr_ind_handler(msgid, msg_param, dest_id, src_id);

    With the SmartBond App I connect into my device and I can change the Device name like this:


    Kind Regards,

  • Quick follow up to this actually: what compiler is required for these changes?

  • Hi There,

    Thank you for the reply.
    If you are working on Codeless v6.380.16.55 you will need ARM Compiler v6.
    If you are working on Codeless v6.380.14.22 or any older version you will need ARM Compiler v5.

    Kind Regards,

Reply Children
  • Thanks for your time so far, I really appreciate it.

    Two more questions about your solution: 1) would your solution be applicable to the data pump firmware? 2) as far as I can tell there's two names attached to a "barebones" chip if you will: CLv2 and CodeLess. I believe your solution changes the CodeLess name. Do you know how to change the other name as well?

    Also, is there documentation that includes changing names? A quick search yielded no results.

  • Hi There,

    Thank you for the reply.
    1) Yes, a custom at command to change the Device Name can be used on the datapump firmware.
    2) No, there is only one name being used, which is the CLv2-CodeLess, the CLv2 is also the Short Device name which is being placed on the Advertising Data, while the CLv2-CodeLess is the full Device Name which is placed on the Scan Response Data and saved on the device_info struct.

    I worked on the CodeLess SDK v6.380.16.55 and followed the instructions mentioned on the CodeLess User Manual  6. Adding Custom Commands.
    The custom AT command I created is the AT+DEVNAME.
    On the user_at_commands.c file you can find the user_at_devname function:

    char new_device_name[GAP_MAX_NAME_SIZE] = "\0";
    bool flag_devname= false;
    // Custom AT command to change the Device Name
    #ifdef USE_AT_DEVNAME
    void user_at_devname(struct at_cmd_params_t* arg, char* reply_string)
    	char zeroed[GAP_MAX_NAME_SIZE] = "0";
    	//Empty the new_device_name array
    	memcpy(new_device_name, &zeroed, GAP_MAX_NAME_SIZE);
    	//If AT+DEVNAME
    	if( arg->arg_count ==0)
    		//We only printed out the name, so keep flag_devname = false;
    		flag_devname = false; 
    		//Print the existing Device Name
    		arch_sprintf(reply_string, "%s", device_info.dev_name.name);
    		arg->success_flag = true;
    	else //else if AT+DEVNAME=
    		//We will change the Device Name (short and long) so change flag_devname= true
    		flag_devname= true;
    		//Empty the device_info struct 
    		memcpy(device_info.dev_name.name, &zeroed, GAP_MAX_NAME_SIZE);
    		//Save the New device name into the new_device_name variable
    		memcpy(&new_device_name, &arg->cmd_buffer[arg->arg_index[0]], GAP_MAX_NAME_SIZE);
    		device_info.dev_name.length = (strlen(new_device_name) <= GAP_MAX_NAME_SIZE) ?strlen(new_device_name) : GAP_MAX_NAME_SIZE;
    		//Save the New device name into the device_info struct
    		memcpy(device_info.dev_name.name, new_device_name, device_info.dev_name.length);
    		/* Set the Device Name to the codeless_env struct  */	
    	   memcpy(&codeless_env.resp_data, &device_info.dev_name.name, device_info.dev_name.length);
         codeless_env.resp_data_len = strlen(new_device_name);
    		 // Instantiate the advertising update message to be sent
        struct gapm_update_advertise_data_cmd *cmd = KE_MSG_ALLOC(GAPM_UPDATE_ADVERTISE_DATA_CMD,
        cmd->operation = GAPM_UPDATE_ADVERTISE_DATA;
    		//Set the Advertising Data as specifiec in user_app_init custom callback function
    		#ifdef USE_AT_BINARY_MODE
        const uint8_t advertisement_data[] =
        uint8_t advertisement_data[] =
        { // Complete list of 128bit service UUIDs
        #ifdef USE_AT_BINARY_MODE 
            17, GAP_AD_TYPE_COMPLETE_LIST_128_BIT_UUID, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
             0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
             3, GAP_AD_TYPE_MORE_16_BIT_UUID, 0xF5, 0xFE, //SUOTA Service
          // Bluetooth Device Name
             5, GAP_AD_TYPE_SHORTENED_NAME, 
        #ifndef USE_AT_BINARY_MODE
        for (uint8_t i = 0; i < 16; i++) {
                advertisement_data[2 + i] = codeless_const_env.adv_service_uuid[i]; 
    		 //Save the advertisemnt_data into the codeless_env struct
        memcpy(&codeless_env.adv_data, &advertisement_data, sizeof(advertisement_data));
         //Save the Advertisment  data length into the codeless_env struct
        codeless_env.adv_data_len = sizeof(advertisement_data);
    		// Update the Advertising data 
        cmd->adv_data_len = codeless_env.adv_data_len;
        memcpy(cmd->adv_data, codeless_env.adv_data, codeless_env.adv_data_len);
     		/* Set the Device Name to Scan response data and show it */
        // Send the message
    		//Print the New name
    		arch_sprintf(reply_string, "%s", device_info.dev_name.name);
    		arg->success_flag = true;

    However, when disconnected or when we use the AT+ADVSTOP and AT+ADVSTART commands we restart advertising via the user_advertise custom callback function.
    I modified the user_disconnect and the user_at_advstart functions in order to use the new device name set by the AT+DEVNAME command. 
    Please see the screenshots below on how the AT command is being used:
    By default the Device Name is CLv2-CodeLess and you can see on the Advertising Data the Short Name: CLv2.
    When you use the AT+DEVNAME without any arguments, then it will print out the existing Device Name. When you use the AT+DEVNAME with arguments, it will use the arguments you used as the new Device Name:

    After that I can see on the SmartBond App:

    As you can see the first 4 characters are saved on the Advertising Data on the Short Name.
    When we Connect, the Device Name is shown in the first Service (Generic Access 0x1800) on the Characteristic Device Name:

    If you use the AT+DEVNAME command while connected, it will change the Device Name as well:

    After that, you should be able to see on the SmartBond App:

    Finally, when we disconnect we will keep advertising with the last name we used on the AT+DEVNAME command.
    If you use the AT+ADVSTOP command to stop advertising, change the Device Name via the AT+DEVNAME command and start advertising with the AT+ADVSTART command, you should see the new device name.


    Kind Regards,

  • This is interesting, I see two names only: CLv2 and CodeLess, never a CLv2-CodeLess. This is on 14531 v_6.380.14.22 by the way. I'll have to investigate why that is. I wanted to figure out a way to rename both.