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

connection time out problem

Hello, I am working on s130 softdevice(SDK 6.1.0.0 and nRf51822 &nRf51 DK). I have one peripheral and two centrals. but the data from peripheral should be read from only one central at a time. After getting advertisement from peripheral both centrals will send a connection request. but peripheral will get connected to only one. For the second central which did not receive any response from peripheral should time out after some time. Whether there is any event which will be triggered if a connection request fails?? i saw one of the time out reason as BLE_GAP_TIMEOUT_SRC_CONN. But it is not working. Why i am not getting timeout. i am using one application timer in my program. the connection parameters that i am using is: static const ble_gap_conn_params_t connection_param = { (uint16_t)MSEC_TO_UNITS(7.5, UNIT_1_25_MS), // Minimum connection (uint16_t)MSEC_TO_UNITS(30, UNIT_1_25_MS), // Maximum connection 0, // Slave latency (uint16_t)MSEC_TO_UNITS(4000, UNIT_10_MS) // Supervision time-out };

What is the way to know whether connection request is timed out?? my program is not taking any events after it has called sd_ble_gap_connect() as though it got stuck. what will be the reason for this? any help is appreciated.

Thanks in advance.

  • Hi,

    When you call sd_ble_gap_connect() three failure modes can happen, depending on your parameters and timing:

    • The central detects an advertisement, sends a connect request and produces a BLE_GAP_EVT_CONNECTED event. The peripheral missed this or got connected from another device. Then, after the supervision timeout has passed, a BLE_GAP_EVT_DISCONNECTED event is produced with reason "Connection Failed to be Established" (0x3E).
    • The central does not detect advertisement and keeps scanning. When the timeout is reached, a BLE_GAP_EVT_TIMEOUT event is produced with reason BLE_GAP_TIMEOUT_SRC_CONN
    • If a timeout is not set, and no advertisement is seen, the central will keep scanning indefinitely until either the device is seen or sd_ble_gap_connect_cancel() is called.

    I believe the third option is what you are seeing. You need to set a timeout in the scan parameters provided to the connect() function.

  • My problem is with the first option. In my case the central could detect the advertisement and it sends connection request. But by that time another central got connected to peripheral. But I am not getting any disconnect event as you said. After sending connection request my central is not getting any events(even BLE_GAP_EVT_CONNECTED event) as though it got stuck. What may be problem for this?? Anything related to stack??

  • I have one doubt. What is the relation between the scan parameters set in the sd_ble_gap_connect call and the normal scanning parameters the central used to scan. whether both are the same? Also BLE_GAP_TIMEOUT_SRC_CONN does not have any relation between supervision time out??

  • Have you set the advertising timeout? Do you get the timeout after sending connection request if you set the advertising timeout?

  • I am using directed advertisement. So it will automatically time out after 1.2 seconds. We will get connection request timeout if we set scanning timeout in the scan_params field in the sd_ble_gap_connect() API.

Related