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.

CC2642R-Q1: Example Modify the name of a Bluetooth device

Part Number: CC2642R-Q1
Other Parts Discussed in Thread: SYSCONFIG, CC1352R

My purpose is to change the device name during the operation of the device. After calling the interface GGS_SetParameter, I can see that the device name on the app side has not changed, as shown in the figure below. What is the problem?

  • Hi,

    Try closing the app then turn off on smart phone Bluetooth. After that try again. What SDK version are you using?

    -kel

  • I closed the app and restarted the Bluetooth of the phone. The device name I read was still BT618

  • The device name is set at syscfg. Not sure if you can change it again during operation. Anyway wait for a TI Engineer to reply.

    -kel

  • Hey Linqian,

    As Kel has pointed out, the device name is set via SysConfig, so I would rather change the name there. However, the code snippet you share should work ok. When the mobile phone scans, it will show the Local Name that is set in the advertisement/scan response payloads. I was able to verify this with the LightBlue mobile application. You will see the device name update after connecting to the device.

    Perhaps what you are looking for is a way to update the advertisement or scan response payload. This can also be done in SysConfig under Broadcaster configuration.

  • Yes, device names can be configured in SysConfig. However, my requirement is to change the name of the device during its operation, as indicated by the red box in my picture. The scenario is: Changing the device name through the AT command, thank you

    In addition, if the device Name displayed on the app side is Local Name, what should I do if I change the Local Name at any time during the running of the program?

  • The scenario is: Changing the device name through the AT command, thank you

    I understand what you meant AT command is an external command to set the device name. 

    If I remember correctly what is displayed at IOS Light Blue App is the device name. At nRF Connect App is the scan response. Maybe it is reversed. Both are set at initialization SimplePeripheral_Init()

    If I were to do what you are trying, setting a new device name. I would save the new device name at SNV. Then restart the device. After that read the SNV containing the new device name and set it at initialization using below code

    GGS_SetParameter(GGS_DEVICE_NAME_ATT, GAP_DEVICE_NAME_LEN, NEWattDeviceName);

    But, if this code does not work as you have tested it that is a problem

    -kel

  • According to the phenomenon, simply changing attDeviceName has no effect. Should I change the content of parameter advData1 or scanResData1 to be useful? If so, which API should I change

  • Hi,

    I am using CC1352R Launchpad and SDKv6.20 testing.

    Using IOS LightBlue App changing the device name works using this code below, called at SimplePeripheral_init().

    GGS_SetParameter(GGS_DEVICE_NAME_ATT, GAP_DEVICE_NAME_LEN, "Simple Device");

    Using Android nRF Connect what you see is the scanResData1[] below. This code can be found at ti_ble_config.c, which is modified by the syscfg.

    uint8_t scanResData1[] =
    {
      0x12,
      GAP_ADTYPE_LOCAL_NAME_COMPLETE,
      'S',
      'i',
      'm',
      'p',
      'l',
      'e',
      ' ',
      'P',
      'e',
      'r',
      'i',
      'p',
      'h',
      'e',
      'r',
      'a',
      'l',
    
      0x02,
      GAP_ADTYPE_POWER_LEVEL,
      0,
    
      0x05,
      GAP_ADTYPE_SLAVE_CONN_INTERVAL_RANGE,
      LO_UINT16(80),
      HI_UINT16(80),
      LO_UINT16(104),
      HI_UINT16(104),
    
    };

    scanResData1 is set using this code below, which is called in SimplePeripheral_processGapMessage()

    // Load scan response data for set #1 that is statically allocated by the app
            status = GapAdv_loadByHandle(advHandleLegacy, GAP_ADV_DATA_TYPE_SCAN_RSP,
                                         sizeof(scanResData1), scanResData1);

    So, if you are using Android nRF Connect you need to change the scanResData1.

    However, if you have custom app normally what you would program to see is the device name.

    -kel

  • I don't think you understand what I mean. What I want is to update the device name after the initialization and after the system is up and running. I tried to change the device name in the program, but it didn't actually work. I don't know what the problem is.

  • Hi,

    This code works to change the scanResData[]. So, if you are using Android nRF Connect App, you should be able to see the change.

    /*********************************************************************
     * @fn      SimplePeripheral_processGapMessage
     *
     * @brief   Process an incoming GAP event.
     *
     * @param   pMsg - message to process
     */
    static void SimplePeripheral_processGapMessage(gapEventHdr_t *pMsg)
    {
      uint8_t scanResData2[] =
      {
        0x11,
        GAP_ADTYPE_LOCAL_NAME_COMPLETE,
        'S',
        'i',
        'm',
        'p',
        'l',
        'e',
        ' ',
        'S',
        'p',
        'i',
        'd',
        'e',
        'r',
        'm',
        'a',
        'n',
    
        0x02,
        GAP_ADTYPE_POWER_LEVEL,
        0,
    
        0x05,
        GAP_ADTYPE_SLAVE_CONN_INTERVAL_RANGE,
        LO_UINT16(80),
        HI_UINT16(80),
        LO_UINT16(104),
        HI_UINT16(104),
    
      };
      switch(pMsg->opcode)
      {
        case GAP_DEVICE_INIT_DONE_EVENT:
        {
          bStatus_t status = FAILURE;
    
          gapDeviceInitDoneEvent_t *pPkt = (gapDeviceInitDoneEvent_t *)pMsg;
    
          if(pPkt->hdr.status == SUCCESS)
          {
            // Store the system ID
            uint8_t systemId[DEVINFO_SYSTEM_ID_LEN];
    
            // use 6 bytes of device address for 8 bytes of system ID value
            systemId[0] = pPkt->devAddr[0];
            systemId[1] = pPkt->devAddr[1];
            systemId[2] = pPkt->devAddr[2];
    
            // set middle bytes to zero
            systemId[4] = 0x00;
            systemId[3] = 0x00;
    
            // shift three bytes up
            systemId[7] = pPkt->devAddr[5];
            systemId[6] = pPkt->devAddr[4];
            systemId[5] = pPkt->devAddr[3];
    
            // Set Device Info Service Parameter
            DevInfo_SetParameter(DEVINFO_SYSTEM_ID, DEVINFO_SYSTEM_ID_LEN, systemId);
    
            Display_printf(dispHandle, SP_ROW_STATUS_1, 0, "Initialized");
    
            BLE_LOG_INT_TIME(0, BLE_LOG_MODULE_APP, "APP : ---- got GAP_DEVICE_INIT_DONE_EVENT", 0);
            // Setup and start Advertising
            // For more information, see the GAP section in the User's Guide:
            // http://software-dl.ti.com/lprf/ble5stack-latest/
    
            BLE_LOG_INT_INT(0, BLE_LOG_MODULE_APP, "APP : ---- call GapAdv_create set=%d,%d\n", 0, 0);
            // Create Advertisement set #1 and assign handle
            status = GapAdv_create(&SimplePeripheral_advCallback, &advParams1,
                                   &advHandleLegacy);
            SIMPLEPERIPHERAL_ASSERT(status == SUCCESS);
    
            // Load advertising data for set #1 that is statically allocated by the app
            status = GapAdv_loadByHandle(advHandleLegacy, GAP_ADV_DATA_TYPE_ADV,
                                         sizeof(advData1), advData1);
            SIMPLEPERIPHERAL_ASSERT(status == SUCCESS);
    
            // Load scan response data for set #1 that is statically allocated by the app
    #if 0
            status = GapAdv_loadByHandle(advHandleLegacy, GAP_ADV_DATA_TYPE_SCAN_RSP,
                                         sizeof(scanResData1), scanResData1);
    #endif
            status = GapAdv_loadByHandle(advHandleLegacy, GAP_ADV_DATA_TYPE_SCAN_RSP,
                                                 sizeof(scanResData2), scanResData2);
            SIMPLEPERIPHERAL_ASSERT(status == SUCCESS);
    
            // Set event mask for set #1
            status = GapAdv_setEventMask(advHandleLegacy,
                                         GAP_ADV_EVT_MASK_START_AFTER_ENABLE |
                                         GAP_ADV_EVT_MASK_END_AFTER_DISABLE |
                                         GAP_ADV_EVT_MASK_SET_TERMINATED);
    
            // Enable legacy advertising for set #1
            status = GapAdv_enable(advHandleLegacy, GAP_ADV_ENABLE_OPTIONS_USE_MAX , 0);
            SIMPLEPERIPHERAL_ASSERT(status == SUCCESS);
    
            BLE_LOG_INT_INT(0, BLE_LOG_MODULE_APP, "APP : ---- call GapAdv_create set=%d,%d\n", 1, 0);
            // Create Advertisement set #2 and assign handle
            status = GapAdv_create(&SimplePeripheral_advCallback, &advParams2,
                                   &advHandleLongRange);
            SIMPLEPERIPHERAL_ASSERT(status == SUCCESS);
    
            // Load advertising data for set #2 that is statically allocated by the app
            status = GapAdv_loadByHandle(advHandleLongRange, GAP_ADV_DATA_TYPE_ADV,
                                         sizeof(advData2), advData2);
            SIMPLEPERIPHERAL_ASSERT(status == SUCCESS);
    
            // Set event mask for set #2
            status = GapAdv_setEventMask(advHandleLongRange,
                                         GAP_ADV_EVT_MASK_START_AFTER_ENABLE |
                                         GAP_ADV_EVT_MASK_END_AFTER_DISABLE |
                                         GAP_ADV_EVT_MASK_SET_TERMINATED);
    
            BLE_LOG_INT_TIME(0, BLE_LOG_MODULE_APP, "APP : ---- GapAdv_enable", 0);
            // Enable long range advertising for set #2
            status = GapAdv_enable(advHandleLongRange, GAP_ADV_ENABLE_OPTIONS_USE_MAX , 0);
            SIMPLEPERIPHERAL_ASSERT(status == SUCCESS);
    
            // Display device address
            Display_printf(dispHandle, SP_ROW_IDA, 0, "%s Addr: %s",
                           (addrMode <= ADDRMODE_RANDOM) ? "Dev" : "ID",
                           Util_convertBdAddr2Str(pPkt->devAddr));
    
            if (addrMode > ADDRMODE_RANDOM)
            {
              SimplePeripheral_updateRPA();
    
              // Create one-shot clock for RPA check event.
              Util_constructClock(&clkRpaRead, SimplePeripheral_clockHandler,
                                  READ_RPA_PERIOD, 0, true,
                                  (UArg) &argRpaRead);
            }
            tbm_setItemStatus(&spMenuMain, SP_ITEM_AUTOCONNECT, TBM_ITEM_NONE);
          }
    
          break;
        }

    This command is called during initialization after GAP_DEVICE_INIT_DONE_EVENT

    status = GapAdv_loadByHandle(advHandleLegacy, GAP_ADV_DATA_TYPE_SCAN_RSP,
                                                 sizeof(scanResData2), scanResData2);

    During operation maybe this will work in an event, by calling Event_post() or SimplePeripheral_enqueueMsg().

    -kel

  • Yes, it's possible to change the name of the device in the event GAP_DEVICE_INIT_DONE_EVENT, but, but, but, I mean how do you change the name of the device in another task, like the one I posted, and why doesn't GAP_DEVICE_INIT_DONE_EVENT trigger?

  • why doesn't GAP_DEVICE_INIT_DONE_EVENT trigger

    It does during initialization. I have only known the device name and scanResData[] set during initialization. So as I have suggested earlier if I would do it I would save the new device name or scanResData[] in SNV. Reset the device and read the contents of the SNV during initialization and set it as new device name or scanResData[].

    Another you can try is set new device name or scanResData[] during running operation in an event. The program is event driven. You need to learn how this works and try the same. This method I do not know if it will work.

    /*********************************************************************
     * @fn      SimplePeripheral_processAppMsg
     *
     * @brief   Process an incoming callback from a profile.
     *
     * @param   pMsg - message to process
     *
     * @return  None.
     */
    static void SimplePeripheral_processAppMsg(spEvt_t *pMsg)
    {
      bool dealloc = TRUE;
    
      if (pMsg->event <= APP_EVT_EVENT_MAX)
      {
        BLE_LOG_INT_STR(0, BLE_LOG_MODULE_APP, "APP : App msg status=%d, event=%s\n", 0, appEventStrings[pMsg->event]);
      }
      else
      {
        BLE_LOG_INT_INT(0, BLE_LOG_MODULE_APP, "APP : App msg status=%d, event=0x%x\n", 0, pMsg->event);
      }
    
      switch (pMsg->event)
      {
        case SP_CHAR_CHANGE_EVT:
          SimplePeripheral_processCharValueChangeEvt(*(uint8_t*)(pMsg->pData));
          break;
    
        case SP_KEY_CHANGE_EVT:
          SimplePeripheral_handleKeys(*(uint8_t*)(pMsg->pData));
          break;
    
        case SP_ADV_EVT:
          SimplePeripheral_processAdvEvent((spGapAdvEventData_t*)(pMsg->pData));
          break;
    
        case SP_PAIR_STATE_EVT:
          SimplePeripheral_processPairState((spPairStateData_t*)(pMsg->pData));
          break;
    
        case SP_PASSCODE_EVT:
          SimplePeripheral_processPasscode((spPasscodeData_t*)(pMsg->pData));
          break;
    
        case SP_PERIODIC_EVT:
          SimplePeripheral_performPeriodicTask();
          break;
    
        case SP_READ_RPA_EVT:
          SimplePeripheral_updateRPA();
          break;
    
        case SP_SEND_PARAM_UPDATE_EVT:
        {
          // Extract connection handle from data
          uint16_t connHandle = *(uint16_t *)(((spClockEventData_t *)pMsg->pData)->data);
    
          SimplePeripheral_processParamUpdate(connHandle);
    
          // This data is not dynamically allocated
          dealloc = FALSE;
          break;
        }
    
        case SP_CONN_EVT:
          SimplePeripheral_processConnEvt((Gap_ConnEventRpt_t *)(pMsg->pData));
          break;
    
        default:
          // Do nothing.
          break;
      }
    
      // Free message data if it exists and we are to dealloc
      if ((dealloc == TRUE) && (pMsg->pData != NULL))
      {
        ICall_free(pMsg->pData);
      }
    }

    -kel

  • So you are saying that updating parameters such as device name requires a device reboot to achieve this? What about updating the broadcast interval? Do you need to restart the device as well?

  • What about updating the broadcast interval?

    You do not need to restart the device. You need to stop the advertisement before you modify the broadcasting interval. I have done this before.

    So you are saying that updating parameters such as device name requires a device reboot to achieve this?

    I have not done this. But I think this will work. 

    -kel