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


  • Hey,

    indeed I do see the "Are we scanning or not?" output when the device ends up in this state. Do you know why is the device entering this invalid state and how can I recover in that case?

    Detecting this state might be a bit of a problem in my application though. I do start the scanner every time I get  a BLE_GAP_EVT_CONNECTED or BLE_GAP_EVT_DISCONNECTED event. Since the stack is stuck and no events are sent out, the scanner will not be restarted.

    In my tests I use a timer that restarts the scanner upon timeout and that is when I see the "Are we scanning or not?" message.

    By the way I have the same behavior when using SDK12.3 on the central.


    Thank you again for your help.
    Skara

  • Hi Skara

    In my case I was running an app_timer that would try to start scanning at 5 second intervals. This would recover the stack after the issue occurred, but obviously this is not an ideal workaround. 

    It could be interesting to try and set a flag when the issue occurs, and check this flag in main. Once the flag is set you try to start scanning again from main context. 

    I will have to spend some more time with this, and will try to get you an update early next week. 

    Best regards
    Torbjørn

  • Hi Torbjørn,

    were you able to find anything new regarding this issue?

    Thanks
    Sakra

  • Hi Skara

    My deepest apologies. It has been some busy months here, and I forgot to follow up on your case. Thanks a lot for the reminder. 

    Debugging this further it seems the problem is related to the missed handling of the BLE_GAP_EVT_TIMEOUT event. 

    I tried to track if any BLE events were sent after the occurrence of the "Are we scanning or not" situation, and found that the only BLE event I could see was the BLE_GAP_EVT_TIMEOUT event. 
    This event signals that the connection attempt failed, but is not being picked up by any of the event handlers in the application, or by the scan module. 

    The scan module only responds to this event when the timeout source is BLE_GAP_TIMEOUT_SRC_SCAN, but in this case the source is BLE_GAP_TIMEOUT_SRC_CONN because it is a connection that times out. 

    In your main file I notice that there is some log output if the event is passed to the on_ble_central_evt(..) function, but since the role is set to BLE_GAP_ROLE_INVALID the event will not be forwarded here. 

    Could you try to start scanning manually if the BLE_GAP_EVT_TIMEOUT event occurs with source set to BLE_GAP_TIMEOUT_SRC_CONN and role set to BLE_GAP_ROLE_INVALID?

    I believe this should solve the issue. 

    Best regards
    Torbjørn

  • Hey Torbjørn,

    no worries :) Thank you for taking your time, to help solving my issue.

    I'm not sure I understand exactly what you mean.

    As I already mentioned, I restart the scanner on CONNECTED/DISCONNECTED events. In my case the application gets stuck somewhere after a connection attempt is being made in the nrf_ble_scan_connect_with_target function, where sd_ble_gap_connect is called and it returns success. There are no more events after that to which I can react.

    I do have NRF_SDH_BLE_LOG_ENABLED and the NRF_LOG_LEVEL set to Debug so I can see all the events coming to that module, but after that sd_ble_gap_connect where my app gets stuck, there are no more events.

    My application restarts the scanner manually after about a minute where I get the NRF_ERROR_INVALID_STATE response but still no events are logged.

    Where and when exactly should I be expecting/handling this BLE_GAP_EVT_TIMEOUT?

    Thank you!
    Skara

Related