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
  • This is the expected, normal behaviour - peripherals don't advertise while they are connected!

  • Hi tesc,

    I do have a setup that supports simultaneous peripheral and central connections, but I'm not sure if my setup is correct:

    // Configure the maximum number of connections.
    memset(&ble_cfg, 0, sizeof(ble_cfg));
    ble_cfg.gap_cfg.role_count_cfg.periph_role_count  = NRF_SDH_BLE_PERIPHERAL_LINK_COUNT;
    ble_cfg.gap_cfg.role_count_cfg.central_role_count = NRF_SDH_BLE_CENTRAL_LINK_COUNT;
    ble_cfg.gap_cfg.role_count_cfg.central_sec_count  = NRF_SDH_BLE_CENTRAL_LINK_COUNT;
    err_code = sd_ble_cfg_set(BLE_GAP_CFG_ROLE_COUNT, &ble_cfg, ram_start);
    APP_ERROR_CHECK(err_code);
    
    // Configure peripheral links.
    // Configure the maximum ATT MTU.
    memset(&ble_cfg, 0x00, sizeof(ble_cfg));
    ble_cfg.conn_cfg.params.gatt_conn_cfg.att_mtu = NRF_SDH_BLE_GATT_MAX_MTU_SIZE;
    ble_cfg.conn_cfg.conn_cfg_tag                 = PERIPHERAL_CONN_CFG_TAG;
    err_code = sd_ble_cfg_set(BLE_CONN_CFG_GATT, &ble_cfg, ram_start);
    APP_ERROR_CHECK(err_code);
    
    // Configure GAP connections.
    memset(&ble_cfg, 0, sizeof(ble_cfg));
    ble_cfg.conn_cfg.params.gap_conn_cfg.conn_count     = 1;
    ble_cfg.conn_cfg.params.gap_conn_cfg.event_length   = NRF_SDH_BLE_GAP_EVENT_LENGTH;
    ble_cfg.conn_cfg.conn_cfg_tag                       = PERIPHERAL_CONN_CFG_TAG;
    err_code = sd_ble_cfg_set(BLE_CONN_CFG_GAP, &ble_cfg, ram_start);
    APP_ERROR_CHECK(err_code);
    
    // Configure central links.
    // Configure the maximum ATT MTU.
    memset(&ble_cfg, 0x00, sizeof(ble_cfg));
    ble_cfg.conn_cfg.params.gatt_conn_cfg.att_mtu = 23;
    ble_cfg.conn_cfg.conn_cfg_tag                 = CENTRAL_CONN_CFG_TAG;
    err_code = sd_ble_cfg_set(BLE_CONN_CFG_GATT, &ble_cfg, ram_start);
    APP_ERROR_CHECK(err_code);
    
    // Configure GAP connections.
    memset(&ble_cfg, 0, sizeof(ble_cfg));
    ble_cfg.conn_cfg.params.gap_conn_cfg.conn_count     = NRF_BLE_LINK_COUNT;
    ble_cfg.conn_cfg.params.gap_conn_cfg.event_length   = NRF_SDH_BLE_GAP_EVENT_LENGTH;
    ble_cfg.conn_cfg.conn_cfg_tag                       = CENTRAL_CONN_CFG_TAG;
    err_code = sd_ble_cfg_set(BLE_CONN_CFG_GAP, &ble_cfg, ram_start);
    APP_ERROR_CHECK(err_code);

    Basically I have one configuration that supports just one peripheral connection with MTU 247, and one configuration that supports 1 peripheral connection and 3 central connections with MTU 23. I did this due to RAM restrictions.

    I guess it might be that once the peripheral connects first, it stays using the first configuration? How can I make it so that the second configuration is used? Do I need to advertise with the second configuration tag?

  • I played around with the scanning parameters but didn't get anywhere.

    I have a peripheral with a connection interval between 15 (minimum) and 30 ms (maximum), most times it is 30 ms. I have tried different scanning parameters with no success. Any recommendations?

  • I just tried a configuration similar to the one in the Relay example, i.e. 100 ms interval, 50 ms window, and it also didn't work. I don't even understand how those parameters would even work on a 7.5 ms - 30 ms connection interval (in the example).

  • The connection parameters of my central links are set to 500 ms min, 2000 ms max, but the scanning doesn't even work when no central links are active (i.e. peripheral active, no central links active).

  • Hi,

    The suggestion to look at the connection intervals was because scan events are dropped in their entirety if they collide with connection events. (That would explain why you did not get any advertising reports.) But if scan events are dropped multiple times and the connections have high enough supervision timeout (and, in peripheral role, slave latency) then after a few missed scan event a scan event would be scheduled anyway (and the connection event be dropped instead.) However, with the parameters that you listed I do not see how this could be the issue. Also, in that case you should expect at least _some_ scan events to get thorugh.

    Have you gotten the scan and establishment of a second connection to work if you use the same configuration for both links? The issues that you experience may be totally unrelated to the use of different configurations.

    Regards,
    Terje

Reply
  • Hi,

    The suggestion to look at the connection intervals was because scan events are dropped in their entirety if they collide with connection events. (That would explain why you did not get any advertising reports.) But if scan events are dropped multiple times and the connections have high enough supervision timeout (and, in peripheral role, slave latency) then after a few missed scan event a scan event would be scheduled anyway (and the connection event be dropped instead.) However, with the parameters that you listed I do not see how this could be the issue. Also, in that case you should expect at least _some_ scan events to get thorugh.

    Have you gotten the scan and establishment of a second connection to work if you use the same configuration for both links? The issues that you experience may be totally unrelated to the use of different configurations.

    Regards,
    Terje

Children
  • I just tried what you suggested, i.e. scanning with a single configuration supporting one peripheral and on e central link, and it didn't work either. So at least that means that the configuration isn't the problem

  • 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

Related