Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Multi role in SDK 15 - Scanning for devices only working when peripheral is not connected

Hi,

I'm trying to get the scanning procedure to work while my device is connected to a phone. At the moment, even though I start the scanning procedure, I don't get any BLE_GAP_EVT_ADV_REPORT events.

As soon as the peripheral link is terminated (i.e. phone disconnects), I start getting the adv report events. This happens without me telling the scanning procedure to start again, as far as I'm concerned the scanning was started already.

What could be going wrong? Is scanning while connected not supported? I haven't read any limitations about this in the documentation.

Any help with this is appreciated :)

Parents Reply Children
  • I found the problem! It's this code:

    static void on_adv_report(ble_evt_t const * p_ble_evt) {
    	ble_gap_evt_t const * p_gap_evt = &p_ble_evt->evt.gap_evt;
    	ret_code_t            err_code;
    	
    	if (is_already_connected(&p_gap_evt->params.adv_report.peer_addr)) {
    		debug_line("Returning because already connected");
    		return;
    	}
    	.
    	.
    	.

    I don't know why I had that there. I possibly copied it from one of the examples. My question now is: Why would an advertising report come from a device that is already connected? That doesn't make sense at all.

  • Hi,

    Yes, that would probably explain it. In the latest SoftDevice you need to actively resume scanning on an advertising report, so just returning from the handler would leave the SoftDevice in a state where scanning is "paused".

    As to why you could receive an advertising report from a device to which you are already in a connection, that would be normal if the other device can have multiple connections as a peripheral. It would then continue to advertise again after the connection with your central device was established.

    In order to not end up with multiple connections to the same peripheral it is wise to do that check, but with SoftDevice 6 and onward you must make sure to restart scanning before you return from the handler.

    Regards,
    Terje

  • Ok, that makes sense. But then since my only connection was an iPhone, that would mean that the iPhone was advertising and then I got an adv report from the iPhone?

  • Hi,

    That sounds a bit strange, but it looks like that would be the case, yes. Had you set up your iPhone to advertise, through an app or otherwise?

    Regards,
    Terje

  • Not that I'm aware of. I'll close this thread since I don't really have more questions about it. Thanks for your help!

Related