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.

Failing to discover more than one characteristic handle

Hi All,

I'm trying to discover two characteristic handles, one after the other using the below code -

static void simpleBLEGATTDiscoveryEvent( gattMsgEvent_t *pMsg )
{
attReadByTypeReq_t req;

if ( simpleBLEDiscState == BLE_DISC_STATE_SVC )
{
// Service found, store handles
if ( pMsg->method == ATT_FIND_BY_TYPE_VALUE_RSP &&
pMsg->msg.findByTypeValueRsp.numInfo > 0 )
{
simpleBLESvcStartHdl = pMsg->msg.findByTypeValueRsp.handlesInfo[0].handle;
simpleBLESvcEndHdl = pMsg->msg.findByTypeValueRsp.handlesInfo[0].grpEndHandle;
}

// If procedure complete
if ( ( pMsg->method == ATT_FIND_BY_TYPE_VALUE_RSP &&
pMsg->hdr.status == bleProcedureComplete ) ||
( pMsg->method == ATT_ERROR_RSP ) )
{
if ( simpleBLESvcStartHdl != 0 )
{
// Discover characteristic
simpleBLEDiscState = BLE_DISC_STATE_CHAR;

req.startHandle = simpleBLESvcStartHdl;
req.endHandle = simpleBLESvcEndHdl;
req.type.len = ATT_BT_UUID_SIZE;
req.type.uuid[0] = LO_UINT16(SIMPLEPROFILE_CHAR1_UUID);
req.type.uuid[1] = HI_UINT16(SIMPLEPROFILE_CHAR1_UUID);

// GATT_ReadUsingCharUUID( simpleBLEConnHandle, &req, simpleBLETaskId );
GATT_DiscCharsByUUID( simpleBLEConnHandle, &req, simpleBLETaskId );
}
}
}
else if ( simpleBLEDiscState == BLE_DISC_STATE_CHAR )
{
if (simpleBLECharHdl == 0)
{
// Characteristic-1 found, store handle
if ( pMsg->method == ATT_READ_BY_TYPE_RSP &&
pMsg->msg.readByTypeRsp.numPairs > 0 )
{
// simpleBLECharHdl = BUILD_UINT16( pMsg->msg.readByTypeRsp.dataList[0],
// pMsg->msg.readByTypeRsp.dataList[1] );
simpleBLECharHdl = BUILD_UINT16( pMsg->msg.readByTypeRsp.dataList[(pMsg->msg.readByTypeRsp.len-4)],
pMsg->msg.readByTypeRsp.dataList[(pMsg->msg.readByTypeRsp.len-3)] );


LCD_WRITE_STRING( "Char-1 Svc Found", HAL_LCD_LINE_1 );
simpleBLEDiscState = BLE_DISC_STATE_AUTH;

req.startHandle = simpleBLESvcStartHdl;
req.endHandle = simpleBLESvcEndHdl;
req.type.len = ATT_BT_UUID_SIZE;
req.type.uuid[0] = LO_UINT16(SIMPLEPROFILE_CHAR2_UUID);
req.type.uuid[1] = HI_UINT16(SIMPLEPROFILE_CHAR2_UUID);

GATT_DiscCharsByUUID( simpleBLEConnHandle, &req, simpleBLETaskId );
}
}
}
else if ( simpleBLEDiscState == BLE_DISC_STATE_AUTH )
{
if (simpleBLEAuthHdl == 0)
{
// Characteristic-6 found, store handle
if ( pMsg->method == ATT_READ_BY_TYPE_RSP &&
pMsg->msg.readByTypeRsp.numPairs > 0 )
{
simpleBLEAuthHdl = BUILD_UINT16( pMsg->msg.readByTypeRsp.dataList[(pMsg->msg.readByTypeRsp.len-4)],
pMsg->msg.readByTypeRsp.dataList[(pMsg->msg.readByTypeRsp.len-3)] );

LCD_WRITE_STRING( "Auth Svc Found", HAL_LCD_LINE_1 );
simpleBLEProcedureInProgress = FALSE;

simpleBLEDiscState = BLE_DISC_STATE_IDLE;
}
}
}
}

If I discover only one handle - either it is "SIMPLEPROFILE_CHAR1_UUID" or "SIMPLEPROFILE_CHAR2_UUID" but if I try to discover "SIMPLEPROFILE_CHAR2_UUID" after "SIMPLEPROFILE_CHAR1_UUID" then I always get "pMsg->msg.readByTypeRsp.numPairs == 0" for the second handle. 

Can anyone help me with my problem. Is there any way to discover multiple characteristic handles one after the other?

I'm fighting with this issue from long time and I couldn't figure out any solution.

Arjun

  • added "else" block to retry (resend the GATT_DiscCharsByUUID( simpleBLEConnHandle, &req, simpleBLETaskId )) the handle if "( pMsg->method == ATT_READ_BY_TYPE_RSP && pMsg->msg.readByTypeRsp.numPairs > 0 )" fails and then I got the valid response on second iteration. So it fixed my problem but I do not understand why the first iteration fails.

    Arjun

  • Somehow my original response got deleted. I think I clicked "edit" but then didn't finish editing it?  Anyhow I posted this on March 5th.  Reposting:

    Hello TI,

    I am having this same issue and am completely unable to figure out why this is happening. My code is functioning as follows:

    1. Discover the service we're looking for by calling GATT_DiscPrimaryServiceByUUID()
    2. Once we resolve the Service start and end handles, perform a read-by-UUID of characteristic A using GATT_ReadUsingCharUUID()
    3. Once we understand the value of the characteristic, perform a write to characteristic B
      1. Since there is no WriteByUUID API method (for some reason), discover characteristic B's handles using GATT_DiscCharsByUUID()
      2. At this point the stack fails to give me the correct response. I am calling GATT_DiscCharsByUUID() with the following parameters:
        1. req.startHandle = iPairSvcStartHdl;
        2. req.endHandle = iPairSvcEndHdl;
        3. req.type.len = ATT_UUID_SIZE;
        4. memcpy(req.type.uuid, pairCommandUUID, ATT_UUID_SIZE)
        5. GATT_DiscCharsByUUID( rcConnHandle, &req, rcTaskId);

    When the call returns, I receive an ATT_READ_BY_TYPE_RSP response in my ProcessGATTMsg. When I inspect this packet, no matter how many times I retry, the numPairs is ALWAYS zero.



    I tried the solution in Arjun Veneshetty's second response, implementing the "else" block to retry, but the same error keeps occurring - I never receive an ATT_READ_BY_TYPE_RSP message back from the Peripheral where numPairs>0. The numPairs is ALWAYS 0.

    I used BTool to execute the same request on my Peripheral with the EXACT SAME parameters in the AttReadByType Request, and it returned successfully. Is this a bug in the TI Stack? I am completely stuck as I am unable to resolve the characteristic handle I need to write to.

  • Hello All,

    I am experiencing the exact same problem as accurately described by both Arjun and John in the previous threads.   I have also tried Arjun's workaround and, like John's attempt, it didn't work.   I am fairly new to CC26xx development, but this seems like a fairly fundamental issue to me, and I am surprised that it has not yet been resolved (John's post was a year ago, and Arjun's nearly three).   I guess most developers are working on peripheral devices, so central device issues don't come up as often and/or are treated with lower priority?   However, I am completely stuck on this one, and am really desperate for an answer.   Can anyone possibly help?

    Best regards,

    Caleb.

  • Hey
    i tried using this method and when i try to read the data using
    ""LCD_WRITE_STRING_VALUE("Char 1:", pMsg->msg.readByTypeRsp.pDataList[0], 10, LCD_PAGE4);"
    its showing
    Char1: 30
    i had not defind it anywhere like this.
    Can u guide where m going wrong.
  • Try this -

    1. req.startHandle = 0x00;
    2. req.endHandle = 0xFFFF;

    And also please check the return value of "GATT_DiscCharsByUUID()" if it has any.

    Arjun

  • Hi Arjun,

    Thanks for the response.  

    Firstly, I tried extending the handle limits, as you suggest, but the result was that the system went into limbo, and eventually the connection broke.   I'm guessing the server within the peripheral device was taking too long to search through the specified handle range, and some timeout occurred.  

    I also tried your second suggestion (GATT_DiscCharsByUUID), but this delivered only those attributes associated with the first characteristic.

    Anyway, I don't think that the handle range is the problem, since I'm able to individually discover all the characteristics within the range returned through discovery of the associated service BUT, only the very first characteristic after service discovery.   I was able to manually find each 'characteristic handle' (distinct from 'attribute handle') by changing the code so that each characteristic in turn is the first searched for, then breaking the code after it is discovered and using the debugger to interrogate the returned characteristic handle.  I then hard-coding each of the handles for the six characteristics (which are available for my particular BLE peripheral), enabling me to successfully access all the characteristics.   This is a work-around which gets me out of my current fix, but is not a satisfactory long term solution since these characteristic handles are probably not stable.   If you, or anyone else, can offer me further advice, it would be gratefully received.

    Best regards,

    Caleb.

  • Hello,

    probably I am experiencing same issues working with GATT_DiscCharsByUUID() function on BLE Central application.

    Most of functions work as expected ( e.g. GATT_DiscAllCharDescs() ).

    DiscCharsByUUID() return a successful status and after I will receive only the procedure completed event

    ( i.e. pMsg->hdr.status == bleProcedureComplete) not more. I cannot find all characteristics.

    Welcome advices

    Thanks

    Alex