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.

CC2640R2F: Can the simple_central display device name during scanning and connection?

Part Number: CC2640R2F

Hi,

I am learning to use the Bluetooth function of CC2640R2. I am a stranger of TI development board. I follow the board CC2640R2 SDK 2.40.00.32 of SimpleLink-Academy 2.40.03.00. There is scanning and advertising tutor. The scanning part task-2 shows how to print the scanning result. It can print the address, RSSI, advertising type and advertising data.

My question is can it print the advertiser device name. I change the simple_peripheral project name to my_peripheral, but I want to display the name when I use simple_central to scan, just like the task-2 of scanning example. The code shows That gapCentralRoleEvent_t object is the key thing, which includes deviceInfo object. This is in the file of central.h in the profile folder of the simple_central project. However, I can not fine device name information from the deviceInfo object. Can anyone tell me how to get the advertiser's device name using simple_central project?

Thank you very much.

  • Hi Robert,

    Per default the TI example project have the device name in the advertising data ( see definition of advertData[] in simple_peripheral.c and project_zero.c). In this case, you can find the GAP_ADTYPE_LOCAL_NAME_COMPLETE flag in the advetisement data.

    For an example of a function that goes through advertisement data looking for a flag and associated data, see SimpleCentral_findSvcUuid() in simple_central.c

    If the device is not advertising its name, this mehod won't help.
  • Hi, Marie,

    Your answer makes me a little confuse. I check the advertData[] in simple_peripheral.c. There is no device name data. I show the code in below:

    static uint8_t advertData[] =
    {
      // Flags: this field sets the device to use general discoverable
      // mode (advertises indefinitely) instead of general
      // discoverable mode (advertise for 30 seconds at a time)
      0x02,   // length of this data
      GAP_ADTYPE_FLAGS,
      DEFAULT_DISCOVERABLE_MODE | GAP_ADTYPE_FLAGS_BREDR_NOT_SUPPORTED,
    
      // service UUID, to notify central devices what services are included
      // in this peripheral
      0x03,   // length of this data
      GAP_ADTYPE_16BIT_MORE,      // some of the UUID's, but not all
      LO_UINT16(SIMPLEPROFILE_SERV_UUID),
      HI_UINT16(SIMPLEPROFILE_SERV_UUID)
    };

    However, the device name is in the scanRspData[] and attDeviceName[GAP_DEVICE_NAME_LEN]. The device is advertising its name, if I use my mobile phone to scan the device, I can see it. However, the simple_central project does not show me any simple_peripheral device name. I think it use the device MAC address + UUID to recognize different devices, but not the device name.

    I also check the SimpleCentral_findSvcUuid() in simple_central.c. The code is very short. I can only find that it try to search the UUID, but I can not find any code for searching device name of the simple_peripheral. I also put this code in below:

    static bool SimpleCentral_findSvcUuid(uint16_t uuid, uint8_t *pData,uint8_t dataLen)
    {
      uint8_t adLen;
      uint8_t adType;
      uint8_t *pEnd;

      pEnd = pData + dataLen - 1;

      // While end of data not reached
      while (pData < pEnd)
      {
        // Get length of next AD item
        adLen = *pData++;
        if (adLen > 0)
        {
          adType = *pData;

          // If AD type is for 16-bit service UUID
          if ((adType == GAP_ADTYPE_16BIT_MORE) ||
              (adType == GAP_ADTYPE_16BIT_COMPLETE))
          {
            pData++;
            adLen--;

            // For each UUID in list
            while (adLen >= 2 && pData < pEnd)
            {
              // Check for match
              if ((pData[0] == LO_UINT16(uuid)) && (pData[1] == HI_UINT16(uuid)))
              {
                // Match found
                return TRUE;
              }

              // Go to next
              pData += 2;
              adLen -= 2;
            }

            // Handle possible erroneous extra byte in UUID list
            if (adLen == 1)
            {
              pData++;
            }
          }
          else
          {
            // Go to next item
            pData += adLen;
          }
        }
      }

      // Match not found
      return FALSE;
    }

    Is there any other evidence to show that the Simple_central can get device name?

    Regards, Robert

  • Hi Robert,

    Sorry, I meant the scanRspData[] array. (Both advertisement and scan response data packets are treated the same in the simple_central application.)

    In SimpleCentral_findSvcUuid() the packet is parsed for the GAP_ADTYPE_16BIT_MORE and GAP_ADTYPE_16BIT_COMPLETE flags. In your case you need to search for the GAP_ADTYPE_LOCAL_NAME_COMPLETE flag.
  • Hi, Marie,

    Thanks for your explain. I know what do you mead and the GAP_ADTYPE_LOCAL_NAME_COMPLETE flag can check whether the advertisement data type. However, I still do not know how to get the device name. In the SimpleCentral_findSvcUuid(), the UUID value looks like from pData[0] and pData[1]. Could you tell me where I can find the device name from? I am a stranger of TI development board. I need more detail. Sorry about my foolish.
  • Hi Robert,

    The pData array contains the whole advertisement/scan response packet (all triplets of length, flag and data). The data will follow the flag. I.e. the nam ewill come after the GAP_ADTYPE_LOCAL_NAME_COMPLETE .

    For more information on advertisement data you can check out the BLE Scanning and advertising SimpleLink Academy lab: dev.ti.com/.../
  • Hi, Marie,

    Maybe I have not understand the code. I guess in SimpleCentral_findSvcUuid(), the GAP_ADTYPE_16BIT_COMPLETE flag just check the UUID is transformed correct or not. Then, the pData[0] and pData[1] are the UUID values. Because the UUID from simple_peripheral is 16 bits, so there are only 2 byes to match. Please check whether my concept is correct or not.

    If I am right, GAP_ADTYPE_LOCAL_NAME_COMPLETE is not enough for me to get the device name. Do you think if I change code below can get the device name?

    if (adType == GAP_ADTYPE_LOCAL_NAME_COMPLETE)
    { Display_print1(dispHandle, 5, 0, "Peripheral name: %s", Util_convertBytes2Str(pData));
    }

    I don't think I can display the device name to PC UART. The pData[] is just a pointer parameter of the function. It is called by SimpleCentral_processRoleEvent() function. In this function, it pass pEvent->deviceInfo.pEvtData to the pData[] of SimpleCentral_findSvcUuid(). My question is that in SimpleCentral_processRoleEvent(), the "deviceInfo.pEvtData" is UUID; the "deviceInfo.dataLen" is the information length. Then, what "deviceInfo.??" is the device name which I can use to build a function to display?

    I hope you realize my knowledge limitation and understand my question.

    Regards, Robert
  • Hi Robert,

    SimpleCentral_findSvcUuid cycles through the whole advertisement/scan response data packet and looks for a match.

    The data always contains a triplet - length - flag - data. E.g. from simple peripheral:

    // Scan Response Data
    static uint8_t scanRspData[] =
    {
      // complete name
      17,   // length of this data
      GAP_ADTYPE_LOCAL_NAME_COMPLETE,
      'S',
      'i',
      'm',
      'p',
      'l',
      'e',
      'P',
      'e',
      'r',
      'i',
      'p',
      'h',
      'e',
      'r',
      'a',
      'l',

    SimpleCentral_findSvcUuid() jumps [length of this data] for each iteration, and checks the flag which is always stored in the next byte after the length.

    If your function finds the correct flag, you can use the length byte to know how long the local name is. 

    You can allocate some memory to hold the local name, either statically (expand the deviceInfo struct) or dynamically.