This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

calling sd_ble_gap_disconnect () from function ble_evt_handler()

Dear Sir,

I am calling the function sd_ble_gap_disconnect() to disconnect the peripheral  from the App.

This is called inside  ble_evt_handler() function and under 

switch (p_ble_evt->header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:

 Under the case statement  BLE_GAP_EVT_CONNECTED: I am calling a  function which in turn calls  sd_ble_gap_disconnect().

I was using nRFCOnnect to test the working.

When the connect - disconnect happens I am getting the following error from the App.

Do I need to take care of anything while calling  sd_ble_gap_disconnect() after establishing connection.

Or the fix for this to be done on the App side?

In the peripheral side I checked the error codes and all of them returns NRF_SUCCESS only.

Thanking you in advance.

with regards,

Geetha

Parents Reply Children
  • The first two sniffer traces only show advertisements and scan/response packets, but the third trace has some valuable information. 

    The first connection start at packet number 480 and is immediately terminated by the peripheral. This pattern repeats itself for the next connection attempts. 


    "Under the case statement  BLE_GAP_EVT_CONNECTED: I am calling a  function which in turn calls  sd_ble_gap_disconnect()."

    "I need to re-start advertising as soon as disconnect happens."

    You have set up a loop where you disconnect whenever you enter a connection, and re-start advertisements whenever you disconnect. 


  • Hi haakonsh,

    Thank you for your reply. I am very happy to hear from you.

    Yes what you told is correct.

    For the initial 45secs/60 secs I will do a looping. where the device will connect and disconnect. It is the behaviour I am expecting. THis is done to know about the phones who are all trying to connect to the device.The connect-disconnect pattern is repeated for this purpose.

    But my question is about the error coming on App. i.e. the GATT-ERROR 133 . Is that something expected?.

    Do I need to worry about this error on App side?

    Or something to be done on App side to fix this, like i mentioned.

    "Or is it to be fixed on the App side?( On the peripheral side none of the APIs return errors)(like this....  https://github.com/NordicSemiconductor/Android-nRF-Toolbox/issues/9)?"( Because none of the API returns an error on peripheral side).

    Please share your valuable suggestions.

    with regards,

    Geetha

  • Error 133 is a very general error code that Android spits out, and debugging it is next to impossible. What I think is that Android throws the error because the BLE stack got surprised by the sudden disconnect. By the sniffer trace you can see that the LL_TERMINATE_IND is received 500µs after the LL_FEATURE_REQ was sendt. This might have cause the Android stack to perform an "illegal" state change. 

  • Thank you for your reply.

    ok. So any ways to fix it?  Is it an issue with App or issue in peripheral? Any solution like Introduction of some delay etc will work?

  • If the issue is a BLE stack panic then a delay between connection and disconnect might solve the problem. 

    We do not have any control over the BLE stack on the various mobile phones on the market. If they behave out of spec then we can only try to work around it. 

Related