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
  • Hi,

    You should be able to still scan, even if you still have one connection as peripheral and one connection as central, provided that you have configured the SoftDevice to have (at least) one connection as peripheral and two connections as central.

    May it be that your timing requirements on the existing connections means those will get priority over the scan events, so that most (of all) of the scan requests gets dropped? See SoftDevice timing-activities and priorities. What are the connection parameters for the existing links, both as peripheral and as central?

    You can also have a look at the Experimental: BLE Relay Example, which scans for and connects to two peripherals, as well ass acts as peripheral in a connection to a central. As such it looks like the perfect reference example for your use case.

    Regards,
    Terje

Children
  • 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

Related