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!

  • There are plenty of devices advertising around me. My phone can see at least 10. I expect my device to be able to scan for these devices while it is connected to my phone. 

  • I think you need to give a fuller explanation of what, exactly, is going on.

    What, exactly, is "your device" ?

    What is doing the advertising?

    A diagram would help ...

  • My device is a peripheral that connects to a mobile app. It should be able to scan and connect to third-party accessories. I already have multiple concurrent connections working, i.e. my device connected to a phone using a peripheral link, and my device connected to multiple accessories using central links.

    However, apparently I can only scan for accessories while the peripheral link is not active. 

  • 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

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

Reply
  • 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?

Children
No Data
Related