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

BLE_GAP_EVT_CONNECTED event is not triggered

Hi all,

I have checked in Nordic Devzone for this query but no luck in finding solution for my query.

I am using nrf52832 and configured as central and peripheral.

my device will scan and store peer address in flash and then connect to stored address later.

when i connect to peer address using sd_ble_gap_connect it returns NRF_SUUCESS but BLE_GAP_EVT_CONNECTED  is not triggered.

this issue occurs only for some peripherals and some peripheral i can able to connect and it triggers event as well.

tested with one of the example code: when i try to connect  peripheral  device programmed with ble_app_uart code this issue occurs where  BLE_GAP_EVT_CONNECTED  is not triggered.

but the same peripheral connects successfully through my Android phone.

i am unable understand what is the issue.

Please guide...

Thanks

Rekha

Parents Reply Children
  • I understand. I was not clear in my previous reply, but the point is that sd_ble_gap_connect() will initiate scanning in order to connect. That is due to how connections work in BLE, where the peripheral advertises, and the central has to send a connection request within a short window after the advertising packet. To be clear: You have to call sd_ble_gap_connect() again in order to connect to a second peripheral (and so on).

  • Hi Thank you for the detailed explaination. Now i understand the connection process better.

    You have to call sd_ble_gap_connect() again in order to connect to a second peripheral (and so on).

    As you said I am calling sd_ble_gap_connect() in a loop. only for the first time it returns NRF_SUCCESS and next time for other devices it returns INVALID_STATE (in my case: may be because of first device is still searching for a connection) so how to overcome this issue without changing timeout.

    Thanks 

  • Hi,

    You cannot do this in a loop. You have to wait for a BLE_GAP_EVT_CONNECTED or BLE_GAP_EVT_TIMEOUT event before you can call sd_ble_gap_connect() for the second time.

  • Hi 

    That is where the risk is - if i set timeout device is not getting connected within that short span. hence i disabled timeout. suppose peripheral device is not in the vicinity, even then my device will still wait for the connection therefore i am unable to connect to next devices.

    How much time does a central requires to connect peripheral?

    Thanks

  • Rekha said:
    That is where the risk is - if i set timeout device is not getting connected within that short span. hence i disabled timeout. suppose peripheral device is not in the vicinity, even then my device will still wait for the connection therefore i am unable to connect to next devices.

     Yes. That is why a timeout is usually sensible.

    Rekha said:
    How much time does a central requires to connect peripheral?

    The time depends on the advertising interval of the peripheral, and the RF environment (noise/interference), which can lead to packet loss. This is because you have to receive an advertising packed in order to connect, and then send a successful connection request. If the time between advertisement packets (advertising interval) is long, or packets are lost, it will take longer time to connect. This are all inherent properties of BLE, and not directly related to the nRF devices.

Related