This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LP-EM-CC2340R5: Changing of BLE Device Name during runtime

Part Number: LP-EM-CC2340R5
Other Parts Discussed in Thread: SYSCONFIG

Tool/software:

We are using the BLE5 example project "Data Stream". I would like to adapt it to our requirements. It is working well so far. When switching on or initializing, i.e. during runtime, I would like to change the device name from "Data Stream" to, for example, "Hello 1001". I would like each BLE device to have its own name and number. How can I do this? It would be ideal if you could show me the place in the project or have an example code that fits the "Data Stream" project.

  • Hello Ali,

    Thanks for reaching out.

    So, if you want to change the device advertisement name, you can do it through SysConfig as shown in the image below.

    If you need to modify this during runtime, you can see that the name is being stored in "attDeviceName" variable which is part of the parameters stored in appMainParams (of type BLEAppUtil_GeneralParams_t ). You can see this definition in app_main.c

    Please make sure the name is no longer than GAP_DEVICE_NAME_LEN, which is 21 characters.

    BR,

    David.

  • Dear David

    I changed the variable  on unit app_main.c (see below), but the adversiting name "Data Stream" remains when pairing.

    void appMain(void)
    {
    #if !defined(Display_DISABLE_ALL)
        MenuModule_params_t params = {
          .mode = MenuModule_Mode_PRINTS_ONLY
        };

        if(MenuModule_init(NULL, &params) != SUCCESS)
        {
        // TODO: Call Error Handler
        }
    #endif // #if !defined(Display_DISABLE_ALL)

        attDeviceName[0] = 'T';
        attDeviceName[1] = 'E';
        attDeviceName[2] = 'S';
        attDeviceName[3] = 'T';
        attDeviceName[4] = '1';
        attDeviceName[5] = '2';
        attDeviceName[6] = '3';
        attDeviceName[7] = '4';
        attDeviceName[8] = '5';
        attDeviceName[9] = '6';
        attDeviceName[10] = '7';
        attDeviceName[11] = '8';

        // Call the BLEAppUtil module init function
        BLEAppUtil_init(&criticalErrorHandler, &App_StackInitDoneHandler,
                        &appMainParams, &appMainPeriCentParams);
    }

  • Hello Ali,

    Could you please try modifying it in SysConfig first. My guess here is that whatever modification you are doing is being overwritten by what is defined in SysConfig.

    BR,

    David.

  • Hello David,

    thanks for the feedback.

    If I change it via sysconfig, the new device name works fine.

    I also tried to change the variable scanResData1 (see below) on runtime. In this case, the message "Unknown device" appears when pairing on Windows PC.

        attDeviceName[0] = 'T';
        attDeviceName[1] = 'E';
        attDeviceName[2] = 'S';
        attDeviceName[3] = 'T';

        scanResData1 [0] = 'T';
        scanResData1 [1] = 'E';
        scanResData1 [2] = 'S';
        scanResData1 [3] = 'T';

        // Call the BLEAppUtil module init function
        BLEAppUtil_init(&criticalErrorHandler, &App_StackInitDoneHandler,
                        &appMainParams, &appMainPeriCentParams);

    Apparently, after initializing with BLEAppUtil_init, these variables are discarded somewhere and the settings are adopted from SysConfig. But that doesn't make sense because every device must have a sequential device name that is only known at runtime. Where else in this project can I change the device naming at runtime?
    Best Regards

    Ali

  • Hello Ali,

    Understood. If you look inside the BLEAppUtil_init() function, you can see that the GGS_SetParameter() function is being used (see ble_stack_api.c), where the pAttDeviceName is the pvalue 3rd parameter. Please look into the GAP GATT Service section of the User`s Guide for more info about it.

    BR,

    David.

  • Hello David,

    I don´t see the GGS_SetParameter() function inside of BLEAppUtil_init (see below). Remember, I'm using the sample program "Data Stream". Where do I have to change which variable on runtime?

    void BLEAppUtil_init(ErrorHandler_t errorHandler, StackInitDone_t initDoneHandler,
                         BLEAppUtil_GeneralParams_t *initGeneralParams,
                         BLEAppUtil_PeriCentParams_t *initPeriCentParams)
    {
        // Register the application error handler
        errorHandlerCb = errorHandler;

        // Register the init done handler - will be called from the GAP_DEVICE_INIT_DONE_EVENT
        appInitDoneHandler = initDoneHandler;

        // Assign the BLEAppUtil parameters from the user to the local parameters
        BLEAppUtilLocal_GeneralParams = initGeneralParams;
        BLEAppUtilLocal_PeriCentParams = initPeriCentParams;

        // Create a message queue for message to be sent to BLEAppUtil
        BLEAppUtil_createQueue();

        // Create BLE stack task
        bleStack_createTasks();

        // Create local app task
        BLEAppUtil_createBLEAppUtilTask();

        // Construct a mutex that will be used by the following functions:
        // BLEAppUtil_registerEventHandler
        // BLEAppUtil_unRegisterEventHandler
        // BLEAppUtil_callEventHandler
        pthread_mutex_init(&mutex, NULL);
    }

    Kind regards

    Ali

  • Hello Ali,

    Understood. You can change the advertisement data and scan response data (specifically the GAP_ADTYPE_LOCAL_NAME_COMPLETE field). Please take a look at our training material here (Advertising Task 2 – Change the Advertisement Data). In addition, you can also take a look at our User's Guide section for Changing Adv parameters.

    You can also leverage this e2e thread (however it is for a different family of devices the approach is very similar).

    BR,

    David.

  • Dear David,

    thanks for your help. Now I found out where my mistake was. Do not touch the array elements 0 and 1 of the variable scanResData1. The following example works correctly. :)

        attDeviceName[0] = 'T';
        attDeviceName[1] = 'E';
        attDeviceName[2] = 'S';
        attDeviceName[3] = 'T';

        scanResData1 [2] = 'T';
        scanResData1 [3] = 'E';
        scanResData1 [4] = 'S';
        scanResData1 [5] = 'T';

    // Call the BLEAppUtil module init function
        BLEAppUtil_init(&criticalErrorHandler, &App_StackInitDoneHandler,
                        &appMainParams, &appMainPeriCentParams);

    Best regards

    Ali