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.

GAPRole_TerminateConnection() is not working

I am using GAPRole_TerminateConnection()  to terminate the BLE connection in my code. But the BLE connection is not disconnecting. I am testing it with a phone and still I can write and read characteristics after calling that API.

I debugged the code and found that the GAPRole_TerminateConnection() returning a value of 2 which is an INVALID_PARAMETER error I think.

I tried the other option HCI_EXT_DisconnectImmedCmd() and this also didnt work.

Can any one figure out what is wrong?

  • Hello,

    Are you calling GAPRole_TerminateConnection from the App task or did you create a new task which is being used to make the API call?

    Best wishes
  • I am calling GAPRole_TerminateConnection from an application task. This task is not the simple BLE peripheral application task , but this is my own task in which my state machine is running.
    So when ever I transit from BLE_MODE to SLEEP_MODE (this modes are my application specific modes) I am calling GAPRole_TerminateConnection to terminate the BLE conection
  • Hi JXS,

    you gave me a great hint. I was disconnecting it from my own task. So I routed this to the main BLE task via a timer call back from my application. And it solved the issue.

    Thank you so much.
  • hi,

    Can you explain in detail how you resolved the issue/post the code
  • Can someone please explain why it does not work outside the App task, or provide a link to the wiki where it is explained.

    I have a very similar problem, and I have already tried moving GAPRole_TerminateConnection() to the App task, but the connection stays.

    Afterwards it is impossible to read data from the characteristics, or even what characteristics and services there are.

    If I disconnect it is impossible to reconnect, but device is still advertising

  • I have the same problem, if I was disconnected from device, it's impossible to reconnect.

    I also use:

    uint8_t advertEnabled = FALSE; // Turn on Advertising
    // Disable connectable advertising.
    GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t), &advertEnabled);

  • Similar to my answer nearly 2 years ago, are you calling these APIs outside of the application task (or any ICall registered RTOS task)? If you are calling from a non-ICall aware task - or - a callback/"handler" function, do not expect the API to work. More details in the SW User Guide.

    Best wishes