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.

GAPCentralRole_EstablishLink timeout

Using BLE stack 1.4 on a Central device, I don't  get any time out event when calling GAPCentralRole_EstablishLink() while the perif. device is powered down or out of range.I tried to change the TGAP_CONN_EST_SUPERV_TIMEOUT to 200 instead of the default 2000 but still no timeout. I do get an GAP_DEVICE_INIT_DONE_EVENT just after calling the GAPCentralRole_EstablishLink() function but that's it. If the device is in range I get connected and disconnected properly. I don't scan just use a predefined known device address.

Any idea ?

  • You should initiate connection only after scanning so you know that the device is there. The EstablishLink will only work if it sees an advertisement packet, otherwise it will wait to connect to the next available advertisement and there is no timeout involved. The supervision timeout is used after the connection is established.  

    Hope this helps.

  • Hi,

    I have a same problem.
    I am calling EstablishLink after scanning.
    But at that time peripheral device is powered off.
    So what to do to clear the pending link layer request as GAPCentralRole_TerminateLink not working properly because link is not established yet.

    Thanks,
    Ravi
  • You will need to start a timer when initiates a connection:

    Example:

    osal_start_timerEx( simpleBLETaskId, SBP_CONN_TIMEOUT_EVT, 3000);

    this will allows for 3 seconds to get connected. If after 3 second a connection was not established the SBP_CONN_TIMEOUT_EVT event will be fired.

    Then you can handle it like this in SimpleBLECentral_ProcessEvent:

    if ( events & SBP_CONN_TIMEOUT_EVT)
    {
          GAP_TerminateLinkReq( simpleBLETaskId, 0xFFFE, 0 ); // cancel the pending connection request

         // may be start scanning again here

        return ( events ^ SBP_CONN_TIMEOUT_EVT);

    }

    Of course you will have to cancel the pending SBP_CONN_TIMEOUT_EVT event if the connection was established successfully:

    static void simpleBLECentralEventCB( gapCentralRoleEvent_t *pEvent )
    {

     switch ( pEvent->gap.opcode

    {

    case GAP_LINK_ESTABLISHED_EVENT:

    osal_stop_timerEx( simpleBLETaskId, SBP_CONN_TIMEOUT_EVT);

    Hope this help

  • Hi,

    Thanks for your reply.

    If GAP_TerminateLinkReq( simpleBLETaskId, 0xFFFE, 0 ); function is called from event then it results in GAP_LINK_ESTABLISHED_EVENT with pEvent->gap.hdr.status = FAIL.

    I want callback in GAP_LINK_TERMINATED_EVENT.

    Is there any provision for that?

    Thanks,
    Ravi
  • wow, this is an epic fail, you try to connect to a device that goes out of range and your device is bricked?!?

    how come this is not reported as a bug, I would expect to have a GAP_LINK_ESTABLISHED_EVENT event with gap.hdr.status != SUCCESS

    is it fix in the newest stack/software example? I just lost 2 days, thanks TI

    btw thanks, your timeout solution works great
  • Your example is really useful for me to solve the same issue I am facing as an alternative resolution.
    Thanks a lot for your sharing.

    Ji Won