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.

LAUNCHXL-CC2640R2: Problem to discover a characteristics with GATT_DiscCharsByUUID()

Part Number: LAUNCHXL-CC2640R2

Hi,

Why doesn't GATT_DiscCharsByUUID(pMsg->connHandle, &req, selfEntity) find any handles?

I have created a custom profile with a read-/writeable characteristic.

To discover the characteristic I use the function "multi_role_processGATTDiscEvent(gattMsgEvent_t *pMsg)" which originally discovers the "SIMPLE_SERVICE".

Inside this function I changed the the service uuid and characteristic uuid to my uuids , now the program is able to discover my service but not my characteristic.

I assume the problem occurs at "GATT_DiscCharsByUUID(pMsg->connHandle, &req, selfEntity);" cause the number of attribute handle-UUID pairs (numPairs) found is 0.

However the problem might be a little earlier in the code, because my service end handle is 65535.

For further details please see the code below.

Thanks in advance.

Sebastian

static void multi_role_processGATTDiscEvent(gattMsgEvent_t *pMsg)
{
    ...
    else if (discInfo[connIndex].discState == BLE_DISC_STATE_MTU) // MTU size response received, discover simple service
    {
        ...
        // old: uint8_t uuid[ATT_BT_UUID_SIZE] = { LO_UINT16(SIMPLEPROFILE_SERV_UUID), HI_UINT16(SIMPLEPROFILE_SERV_UUID) }; // uuid = FFF0
        uint8_t My_uuid[ATT_BT_UUID_SIZE] = { LO_UINT16(MY_RW_SERVICE_SERV_UUID), HI_UINT16(MY_RW_SERVICE_SERV_UUID) };      // uuid = BA55
        
        discInfo[connIndex].discState= BLE_DISC_STATE_SVC;

        // Discovery of simple service
        //old: VOID GATT_DiscPrimaryServiceByUUID(pMsg->connHandle, uuid, ATT_BT_UUID_SIZE, selfEntity);
        VOID GATT_DiscPrimaryServiceByUUID(pMsg->connHandle, My_uuid, ATT_BT_UUID_SIZE, selfEntity);
    }
    else if (discInfo[connIndex].discState == BLE_DISC_STATE_SVC) // If we're performing service discovery
    {
      // Service found, store handles
      if (pMsg->method == ATT_FIND_BY_TYPE_VALUE_RSP && pMsg->msg.findByTypeValueRsp.numInfo > 0)
      {
        discInfo[connIndex].svcStartHdl = ATT_ATTR_HANDLE(pMsg->msg.findByTypeValueRsp.pHandlesInfo, 0);        // svcStartHdl = 47
        discInfo[connIndex].svcEndHdl = ATT_GRP_END_HANDLE(pMsg->msg.findByTypeValueRsp.pHandlesInfo, 0);       // svcEndHdl = 65535
      }

      // If procedure is complete
      if (((pMsg->method == ATT_FIND_BY_TYPE_VALUE_RSP) && (pMsg->hdr.status == bleProcedureComplete))  || (pMsg->method == ATT_ERROR_RSP))
      {
        // If we've discovered the service
        if (discInfo[connIndex].svcStartHdl != 0)
        {
          attReadByTypeReq_t req;

          // Discover characteristic --> MY_RW_SERVICE_MYREADWRITE_UUID = 0xDEAD
          discInfo[connIndex].discState = BLE_DISC_STATE_CHAR;
          req.startHandle = discInfo[connIndex].svcStartHdl;
          req.endHandle = discInfo[connIndex].svcEndHdl;
          req.type.len = ATT_BT_UUID_SIZE;
          req.type.uuid[0] = LO_UINT16(MY_RW_SERVICE_MYREADWRITE_UUID);     //old: SIMPLEPROFILE_CHAR1_UUID
          req.type.uuid[1] = HI_UINT16(MY_RW_SERVICE_MYREADWRITE_UUID);     //old: SIMPLEPROFILE_CHAR1_UUID

          // Send characteristic discovery request
          VOID GATT_DiscCharsByUUID(pMsg->connHandle, &req, selfEntity);
        }
      }
    }
    // If we're discovering characteristics
    else if (discInfo[connIndex].discState == BLE_DISC_STATE_CHAR)
    {
      // Characteristic found
      // --> I get ATT_READ_BY_TYPE_RSP but numPairs = 0 !!!
      if ((pMsg->method == ATT_READ_BY_TYPE_RSP) && (pMsg->msg.readByTypeRsp.numPairs > 0))
      {
        // Store handle
        discInfo[connIndex].charHdl = BUILD_UINT16(pMsg->msg.readByTypeRsp.pDataList[3],
                                                   pMsg->msg.readByTypeRsp.pDataList[4]);

        Display_print0(dispHandle, MR_ROW_STATUS1, 0, "my Svc Found");

        Display_print2(dispHandle, 18, 0, "lowbyte3: %d, highbyte4: %d", pMsg->msg.readByTypeRsp.pDataList[3], pMsg->msg.readByTypeRsp.pDataList[4]);

        Display_print1(dispHandle, 22, 0, "charHdl: %d", discInfo[connIndex].charHdl);
      }
    }
}

  • Hello Sebastian,

    I have a few questions that I believe will help us figure this out more efficiently. Can you specify which version of the SDK you are using? I see that you are using multi_host as your base project. Are there any modifications present in the project besides the ones listed? It seems you are using multi_host to connect to seperate peripheral. Are you able to connect to this peripheral using BTool or another Bluetooth device and find the characteristics?

    Regards,

    Jan

  • Hello Jan,

    I use the SDK 4.30.00.08.

    Yes I have also done some other modifications: I did some modifications to insert a new profile like proposed in the "Custom Profile" tutorial, I also added a submenu in  "multi_role_menu.c" and several "DisplayPrint()s".

    Yes I am able to connect to the multi role controller with my phone (I use: Android BLE Scanner). With the BLE Scanner its also possible to discover the characteristic and write/read the value.

    Regards,

    Sebastian

  • Hi Sebastian,

    Can you describe the application set up a bit, so I can get a better picture of what is going on? Can you describe what you intend the overall project to do? You have this multi_role project running on a LaunchPad, correct? Are you trying to connect to a second device? If so, what device are you trying to connect to and what is running on this second device? Are you trying to connect to your multi_role project from another device?

    Sincerely,

    Jan

  •  Hi Jan,

    the overall project should be multiple LaunchPads (CC2640R2) each running the multi role example.

    - The user should be able to connect the LaunchPads in a way he want them to be connected. Some examples are in the Picture:

    - The user is able to send data(write) on a LaunchPad

    - Later I want also a Smartphone/Notebook to connect to the application but at first it would be fine if this network works

    So my current state is that im able to connect the Pads but now I want to send some data (write).

    As mentioned before my approach is to write on a read-/writeable characteristic similar to the method in simpleGattService.

    Regards Sebastian

  • Hello Sebastian,

    Thank you for the thorough explanation. I believe it will prove very helpful in solving this. Can you verify if you are able to find the handles if you use the simple_central project? Or is the behavior present there as well?

    Sincerely,

    Jan

  • Hello Jan,

    you are welcome and also thank you for your help.

    If I let the multirole project or the simple_central project discover the SIMPLEPROFILE_CHAR1_UUID (=0xFFF1) it is successful.

    But if I use the multirole project or the simple_central project discover MY_RW_SERVICE_MYREADWRITE_UUID (=0xDEAD) it is not successful.

    Sincerely,

    Sebastian

  • Hello Sebastian,

    Thank you for performing that test. Can you provide the changes you made to simple_central to discover your UUID? If you have a second LaunchPad, would you be able to flash a second LaunchPad with host_test and use BTool to attempt to connect and discover the characteristics of your project? Let me know if you have any issues running this test.

    Regards,

    Jan

  • Hello Jan,

    the only changes I did to simple_central are:

    - I changed the server uuid: uint8_t uuid[ATT_BT_UUID_SIZE] = { LO_UINT16(0xBA55), HI_UINT16(0xBA55) };

    - and I changed the characteristic uuid: req.type.uuid[0] = LO_UINT16(0xDEAD);
            req.type.uuid[1] = HI_UINT16(0xDEAD);

    Also here is the code:

    static void SimpleCentral_processGATTDiscEvent(gattMsgEvent_t *pMsg)
    {
      if (discState == BLE_DISC_STATE_MTU)
      {
        if (pMsg->method == ATT_EXCHANGE_MTU_RSP)
        {
          //uint8_t uuid[ATT_BT_UUID_SIZE] = { LO_UINT16(SIMPLEPROFILE_SERV_UUID), HI_UINT16(SIMPLEPROFILE_SERV_UUID) };
          uint8_t uuid[ATT_BT_UUID_SIZE] = { LO_UINT16(0xBA55), HI_UINT16(0xBA55) };
    
          discState = BLE_DISC_STATE_SVC;
    
          VOID GATT_DiscPrimaryServiceByUUID(connHandle, uuid, ATT_BT_UUID_SIZE, selfEntity);
        }
      }
      else if (discState == BLE_DISC_STATE_SVC)
      {
        ...
        
            //req.type.uuid[0] = LO_UINT16(SIMPLEPROFILE_CHAR1_UUID);
            //req.type.uuid[1] = HI_UINT16(SIMPLEPROFILE_CHAR1_UUID);
            req.type.uuid[0] = LO_UINT16(0xDEAD);
            req.type.uuid[1] = HI_UINT16(0xDEAD);
    
            VOID GATT_DiscCharsByUUID(connHandle, &req, selfEntity);
          }
        }
      }
      else if (discState == BLE_DISC_STATE_CHAR)
      {
        ...
      }
    }

    I also used host_test and BTool. On the left side I discovered SIMPLEPROFILE_CHAR1_UUID and on the right side I failed to discover MY_RW_SERVICE_MYREADWRITE_UUID.

    So the problem is I didnt get the ATT_ReadByyTypeRsp, but why?

    Sincerely Sebastian

  • HI Sebastian,

    Thank you for the very in-depth information and testing. This is very strange. I am very surprised that host_test is not able to detect your characteristic. I want to ensure that your custom profile is properly set up. Can you place your custom profile/service in the simple_peripheral project as is shown in the SLA Custom Profile lab. I would use the Service Generator to quickly create a template of your custom service. Afterwards attempt to do the bTool test again. You don't have to complete the entire lab, just enough to have the characteristics visible in bTool. I look forward to hearing your results.

    Regards,

    Jan

  • Hi Jan,

    I completely reviewed my custom profile line by line and found my mistake.

    In the global variables definition the UUID array is composed of the TI_BASE_UUID() function but in the SimpleGatt Example the UUID is composed of LO_UINT16() and HI_UINT16().


    Furthermore I had to change the ATT_Bitmasks in the Attributes table to get a Size of 16-bit UUID. (I replaced ATT_UUID_SIZE with ATT_BT_UUID_SIZE)

    So in conclusion I think the problem was that I used 128 bit UUIDs but the SimpleGatt example uses 16 bit UUIDs.

    Again thank you for your help.

    Sincerely Sebastian