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: After connected, discover the correct service

Part Number: LAUNCHXL-CC2640R2

Hi,

I am running Multi-role project on CC2640R2 LaunchPad which is running as Central.

I am trying to figure out how to find the service after connected to the Peripheral.

These were what I did:

1. Use 'Light Blue' application on iPad to create a 'Find Me' immediately alert service (UUID: 0x1802)

2. In 'static void multi_role_processGATTDiscEvent(gattMsgEvent_t *pMsg)' function, I modified the code to look for UUID 0x1802, as followings:

VOID GATT_DiscPrimaryServiceByUUID(pMsg->connHandle, 0x1802, ATT_BT_UUID_SIZE, selfEntity);

3. I used BTN to trigger 'Scan' and saw the 'Immediately Alert Service' found (UUID: 0x1802), as the following message (I added this message):

UUID: 1802, Name: Find Me 1, Addr: 0x7921F3A6726D

4. In 'static void multi_role_processGATTDiscEvent(gattMsgEvent_t *pMsg)' function, I did see the 'ATT_EXCHANGE_MTU_RSP' event (method). In other words, 'if (pMsg->method == ATT_EXCHANGE_MTU_RSP)' was TRUE.

But, in the next state: 'BLE_DISC_STATE_SVC', the 'pMsg->method' was getting: ATT_ERROR_RSP. The 'discInfo[connIndex].svcStartHdl' = 0 too.

In other words, LaunchPad did not find the service.

Don't know why. I think I already put the correct UUID 0x1802 and the service should have been found. Indeed, I also modified code to try other service, like: Health Thermometer (UUID: 0x1809). But, I got the same problem.

What were my problems for this issue?

I looked the following link and did not get enough information for my problem.

Here is the part of code:

    else if (discInfo[connIndex].discState == BLE_DISC_STATE_MTU)
    {
      // MTU size response received, discover simple service
      if (pMsg->method == ATT_EXCHANGE_MTU_RSP)
      {
        // Advance state
        discInfo[connIndex].discState= BLE_DISC_STATE_SVC;
        // Discovery of simple service
         VOID GATT_DiscPrimaryServiceByUUID(pMsg->connHandle, 0x1802, ATT_BT_UUID_SIZE, selfEntity);
     }
    }
    // If we're performing service discovery
    else if (discInfo[connIndex].discState == BLE_DISC_STATE_SVC)
    {
      // 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);
        discInfo[connIndex].svcEndHdl = ATT_GRP_END_HANDLE(pMsg->msg.findByTypeValueRsp.pHandlesInfo, 0);
      }
      // 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
          discInfo[connIndex].discState = BLE_DISC_STATE_CHAR;
          req.startHandle = discInfo[connIndex].svcStartHdl;
          req.endHandle = discInfo[connIndex].svcEndHdl;
          // Steven Cao, 2/11/2019
          req.type.len = sizeof(iNxCmdChar.charValueUUID);
          memcpy((void *)req.type.uuid, (const void *)iNxCmdChar.charValueUUID, sizeof(iNxCmdChar.charValueUUID));
          // Send characteristic discovery request
          VOID GATT_DiscCharsByUUID(pMsg->connHandle, &req, selfEntity);
        }
      }
    }

Thanks,

Steven

  • Hi Steven,

    It looks like you are giving an int as parameter (green text). I'd be surprised if this compiles without warnings. You should be giving in the pointer to an array that holds the UUID. Search for usages of the function to see how it's used in other examples.

    If that doesn't work, can you attach a sniffer log of what is happening over the air? It's hard to know here if it's the phone or the multirole project that isn't doing its job.

    Best regards,
    Aslak
  • Hi Aslak,
    Thanks for the reply.

    Yes, you are right. That was part of the problem. I changed the code like the followings:
    *************************************************************************
    const uint8 uuid[] = {0x02, 0x18};
    VOID GATT_DiscPrimaryServiceByUUID(pMsg->connHandle, uuid, ATT_BT_UUID_SIZE, selfEntity);
    *************************************************************************
    I did go much further. But, it would still fail inside the last state, BLE_DISC_STATE_CHAR. See below code.
    In other words, it could not find the Characteristic.

    The 'pMsg->method == ATT_READ_BY_TYPE_RSP' check is Good.
    But, 'pMsg->msg.readByTypeRsp.numPairs ' is always 0 so the condition check failed.
    Why?
    The 'Immediately Alert' service has one Characteristic.
    Why is '.numPair' 0?

    I also tried different services, like: Health Thermometer, which has multiple Characteristics but still got the same problem.

    What is my problem here?

    *************************************************************************
    // If we're discovering characteristics
    else if (discInfo[connIndex].discState == BLE_DISC_STATE_CHAR)
    {
    // Characteristic found
    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, "Simple Svc Found");
    }
    }
    **************************************************************************

    Thanks,

    Steven
  • Hi Steven,

    I would suggest that either the UUID isn't what you expect it to be, you initialize it wrong in the request, or the phone doesn't actually have any characteristics. Did you try using BTool or a phone scanner app to verify the GATT Server you are connecting to?

    BTool is basically a GUI version of what you are trying to do, the commands and events are almost one to one, so you can use it to test and verify the central procedures you want to be doing.

    You would also be helped by using a packet sniffer to verify what you thing is happening is happening over the air. www.ti.com/.../PACKET-SNIFFER could be of some use.

    Best regards,
    Aslak