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.

How do I prevent reconnection in the BLE stack?

I'm writing firmware for the SensorTag that communicates with an iPhone. I have implemented the BLE HID, which seems to be working fine. Based on internal sensor readings, I would like to enable and disable the keyboard by interrupting and reestablishing the connection.

I am able to break the connection successfully with a call to

GAPRole_TerminateConnection();

This works fine--I see the keyboard reappear on the iOS device, indicating the connection is broken. The problem is that the connection is automatically reestablished after about 1/2 second, and the keyboard vanishes again. This is not happening due to anything I am doing in the code that I added; I've checked that very carefully.

I'm not sure if the iPhone is aggressively reestablishing the channel or if the firmware is reestablishing the channel.

How can I tell the firmware not to reestablish the connection (until I want it too), and not to allow the iPhone to do so, either?

It seemed like I could do this by stopping advertising:

      uint8 initial_advertising_enable = FALSE;
      GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &initial_advertising_enable );

That did not work.

Any other thoughts?

  • Hi Mike,

    In peripheral.c, you will that the device turns on advertising after breaking the connection.

              VOID osal_set_event( gapRole_TaskID, START_ADVERTISING_EVT);

    in case GAP_LINK_TERMINATED_EVENT is sent by the stack in the gapRole_ProcessGAPMsg function.

    Let me know if this helps.


    Regards,

    Zahid 

  • Well, that certainly got me past the first half of the problem. :) Either not making the call to

    VOID osal_set_event( gapRole_TaskID, START_ADVERTISING_EVT);

    in peripheral.c or masking the START_ADVERTISING_EVT and not processing it in

    uint8 osal_set_event( uint8 task_id, uint16 event_flag )

    prevented the reconnection. Now I can't get it to connect again when I want it too, though.

    Working from gapRole_ProcessGAPMsg in peripheral.c since that seems cleaner, I can block the call to osal_set_event. I don't seem to be able to reconnect by simply making this call later, though. Is there some sort of timer I need to reset? Or is there some better way to reestablish the connection at a later point?

    The code I'm using to try to reconnect is:

              VOID GAP_EndDiscoverable( gapRole_TaskID );
              gapRole_AdvEnabled = TRUE;
              VOID osal_set_event( gapRole_TaskID, START_ADVERTISING_EVT);
            gapRole_ConnectionHandle = INVALID_CONNHANDLE;
    

    I've also tried just the call to osal_set_event, as well as a number of other less likely permutations.