This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

The scan observer stops getting called after a failed attempt to connect to a peripheral using whitelist.

Hello All,

I have the following issue
- a peripheral and a central using nrf52832 with SDK 15.3 and S132
- on the peripheral I advertise with a whitelist
- the central scans with UUID filter activated for a specific UUID

Now when the central sees the peripheral, it tries to connect to it but since it is not in the centrals whitelist the connection is not established.
The problem on the central side is that the observer function nrf_ble_scan_on_ble_evt() stops getting called after the failed attempt to connect.

I reproduced this behavior using the ble_app_multirole_lesc example with some minor changes.
On the central I commented out the call to ble_advertising_start() so that it only scans.
On the peripheral I removed the scan_start() call so it only advertises and I activated the whitelist which has one entry.

I did put logging in nrf_ble_scan_on_adv_report() so that I can see whenever it gets called. When I run the central code, there is continuous log showing advertising packets from different devices. After a failed attempt to connect, I turn off the peripheral and there is no log output from nrf_ble_scan_on_adv_report() any more on the central.

This is how the log looks like on the central:
<info> ble_scan: B460775CF63C
<info> ble_scan: 775F1B8AEA41
<info> ble_scan: EE8BD6D1ABF4
<info> app: CENTRAL: Connected, handle: 0.
<info> app: CENTRAL: Searching for HRS on conn_handle 0x0
<info> peer_manager_handler: Connection security failed: role: Central, conn_handle: 0x0, procedure: Bonding, error: 4352
<warning> peer_manager_handler: Disconnecting conn_handle 0.
<info> app: CENTRAL: Disconnected, handle: 0, reason: 0x3E
<info> app: Scanning
<info> ble_scan: 44237CE1653F
<info> ble_scan: EE8BD6D1ABF4

Obviously this leads to a problem state where the central can not find any other devices to connect to. Stopping and starting the scan does not help. Only if the same peripheral appears again, the central starts calling nrf_ble_scan_on_adv_report again.

Do you know what could be causing this issue and how to resolve it? Does the SoftDevice get stuck somewhere?

Thanks,
Skara


  • Hi Skara

    Could you try to add the following code to the on_ble_evt(..) function, inside the switch case?

    case BLE_GAP_EVT_TIMEOUT:
        // The issue occurs when the connection times out, in which case scanning hasn't been started when we think it has
        if (p_ble_evt->evt.gap_evt.params.timeout.src == BLE_GAP_TIMEOUT_SRC_CONN)
        {
            NRF_LOG_DEBUG("Connection Request timed out. Restart scanning...");
            nrf_ble_scan_start(&m_scan);
        }
        break;

    Best regards
    Torbjørn

  • Hi Torbjørn,

    I did place that code in the on_ble_evt function but it never gets called.

    As I've written previously, I am logging all events that come. I do log them in the ble_evt_handler function which is the observer for ble events. I also log them in the nrf_sdh_ble_evts_poll function. After the sd_ble_gap_connect that returns success there are no more events coming.

    In the picture above you can see after I start the scanning device it finds lots of ble devices which do not match the filter. Than I turn on the second board which is advertising only and right after I see the 'Connection status: 0' log, I unplug the advertising device. At that point the scanning device is already hanging. There are no more logs coming until I start the advertising device again.

    Cheers,
    Skara

  • Hi 

    Are you able to share your latest version of your code with me, so I can test it out here?

    I am basing my test on the code you sent earlier, and with the changes I made I am unable to get it to lock up. 

    Best regards
    Torbjørn

  • Hi again

    Ignore my last reply. 

    I realize that I made one (possibly critical) change to the code you sent me: I changed the NRF_BLE_SCAN_SCAN_DURATION in sdk_config.h from 0 to 1000. 

    I noticed that the scan parameters are passed along to the sd_ble_gap_connect(..) function, which means that if you have unlimited scan duration (timeout) you also have unlimited timeout when trying to connect to a device. 

    Could you try to change the scan_duration to a non zero number as well?

    Then the connection attempt should time out like I described in my earlier response. 

    Please note that when using a scan timeout you need to restart scanning manually once it times out, in case you want scanning to run continuously. 

    Best regards
    Torbjørn

Related