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
  • Hi,

    This is expected when the connection is unsuccessful, and you have no timeout. If you did expect the connection to succeed you need to look at the parameters you provided to sd_ble_gap_connect().

    Details: If you set the timeout field in the ble_gap_scan_params_t instance passed to sd_ble_gap_connect() this is BLE_GAP_SCAN_TIMEOUT_UNLIMITED, which indicate "Continue to scan forever". So in this case you will never get any other event then BLE_GAP_EVT_CONNECTED, and scanning will continue until a successful connection is made (and you get the event) or you call sd_ble_gap_connect_cancel().

Children
  • Hi 

    thank you for the support. 

    If you did expect the connection to succeed you need to look at the parameters you provided to sd_ble_gap_connect()

    i want my device to connect to peripheral if it is available in advertising state. but sd_ble_gap_connect will return NRF_SUCCESS even if the device bluetooth is turned off.

    if i try to connect the same device second time it returns INVALID_STATE error which is correct result which i expected during first time connection itself.

    How to get correct status of peripheral device ?

    please guide

    Thanks

  • Hi, 

    Rekha said:
    i want my device to connect to peripheral if it is available in advertising state. but sd_ble_gap_connect will return NRF_SUCCESS even if the device bluetooth is turned off.

    Yes, sd_ble_gap_connect() will return NRF_SUCCESS to indicate that the scanning (which is the initial part of connection establishment for a central role) was started. You have to wait for the BLE_GAP_EVT_CONNECTED or BLE_GAP_EVT_TIMEOUT event to know if the connection was established. Therefore you should set a sensible timeout value (not 0), and that should be it.

    Rekha said:
    if i try to connect the same device second time it returns INVALID_STATE error which is correct result which i expected during first time connection itself.

     You will typically get INVALID_STATE returned from the call to sd_ble_gap_connect() if there is an ongoing connection attempt. If you don't use timeout (set it to 0), you always have to either wait for the BLE_GAP_EVT_CONNECTED event or call sd_ble_gap_connect_cancel() to cancel the ongoing connection attempt before you can call sd_ble_gap_connect() again. Perhaps this is what is happening in this case?

    Rekha said:
    How to get correct status of peripheral device ?

    Can you elaborate the question?

  • Hi

    Can you elaborate the question?

    i want any kind of indication if my device is not getting connected after some time . can i specify particular amount of time as wait time for connection?

    i want to wait for some time and then jump connecting to next device as per my application.

    is time out error is the only indication if connection fails ?

    Thanks

  • Rekha said:
    i want any kind of indication if my device is not getting connected after some time . can i specify particular amount of time as wait time for connection?

    Yes, this is the timeout parameter that you have experimented with (first setting it to 0, then to 1). This specifies the timeout in 10 ms intervals. For example:

    • 0: no timeout
    • 1: 10 ms timeout
    • 20: 200 ms timeout 
    Rekha said:
    is time out error is the only indication if connection fails ?

     Yes.

  • Hi 

    i have not achieved my requirement yet.

    is it possible to connect more than one device at a time with scan paramter timeout set to 0.

    try to connect multiple device at the same time.

    how to achieve this ?

    because if i connect first device i unable to connect next since timeout is set to 0.

    how to achieve multiple connection simultaneously having an array of MAC address with me?

    Thanks

Related