Advertise while connected

I cannot re start advertising while connected. 

this occurs even when i configure BLE_GAP_ADV_TYPE_NONCONNECTABLE_SCANNABLE_UNDIRECTED.

I get NRF_ERROR_CONN_COUNT error code when calling sd_ble_gap_adv_start().

I do not understand why do i get this error when the ADV i want to send is not-connectable.

When i change NRF_SDH_BLE_PERIPHERAL_LINK_COUNT from 1 to 2 it works, but why should i do that? i do not want to keep more than one connection, just to keep advertising while connected.

this is my modified ble_advertising_start() code, look for 'is_connectable'. 

uint32_t ble_advertising_start(ble_advertising_t * const p_advertising,
                               ble_adv_mode_t            advertising_mode,
                               bool is_connectable)
{
    uint32_t ret = NRF_SUCCESS;

    if (p_advertising->initialized == false)
    {
        return NRF_ERROR_INVALID_STATE;
    }

    p_advertising->adv_mode_current = advertising_mode;

    (void)memset(&p_advertising->peer_address, 0, sizeof(p_advertising->peer_address));

    if (  ((p_advertising->adv_modes_config.ble_adv_directed_high_duty_enabled) && (p_advertising->adv_mode_current == BLE_ADV_MODE_DIRECTED_HIGH_DUTY))
        ||((p_advertising->adv_modes_config.ble_adv_directed_enabled)           && (p_advertising->adv_mode_current == BLE_ADV_MODE_DIRECTED_HIGH_DUTY))
        ||((p_advertising->adv_modes_config.ble_adv_directed_enabled)           && (p_advertising->adv_mode_current == BLE_ADV_MODE_DIRECTED))
       )
    {
        if (p_advertising->evt_handler != NULL)
        {
            p_advertising->peer_addr_reply_expected = true;
            p_advertising->evt_handler(BLE_ADV_EVT_PEER_ADDR_REQUEST);
        }
        else
        {
            p_advertising->peer_addr_reply_expected = false;
        }
    }

    p_advertising->adv_mode_current = adv_mode_next_avail_get(p_advertising, advertising_mode);

    // Fetch the whitelist.
    if ((p_advertising->evt_handler != NULL) &&
        (p_advertising->adv_mode_current == BLE_ADV_MODE_FAST || p_advertising->adv_mode_current == BLE_ADV_MODE_SLOW) &&
        (p_advertising->adv_modes_config.ble_adv_whitelist_enabled) &&
        (!p_advertising->whitelist_temporarily_disabled))
    {
        p_advertising->whitelist_in_use         = false;
        p_advertising->whitelist_reply_expected = true;
        p_advertising->evt_handler(BLE_ADV_EVT_WHITELIST_REQUEST);
    }
    else
    {
        p_advertising->whitelist_reply_expected = false;
    }

    // Initialize advertising parameters with default values.
    (void)memset(&p_advertising->adv_params, 0, sizeof(p_advertising->adv_params));

    if ( is_connectable )
    {
      p_advertising->adv_params.properties.type = BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED;
    }
    else
    {
      p_advertising->adv_params.properties.type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_SCANNABLE_UNDIRECTED;
    }

    // Use 1MBIT as primary phy if no phy was selected.
    if (phy_is_valid(&p_advertising->adv_modes_config.ble_adv_primary_phy))
    {
        p_advertising->adv_params.primary_phy = (uint8_t)p_advertising->adv_modes_config.ble_adv_primary_phy;
    }
    else
    {
        p_advertising->adv_params.primary_phy = BLE_GAP_PHY_1MBPS;
    }

    if (p_advertising->adv_modes_config.ble_adv_extended_enabled)
    {
        // Use 1MBIT as secondary phy if no phy was selected.
        if (phy_is_valid(&p_advertising->adv_modes_config.ble_adv_secondary_phy))
        {
            p_advertising->adv_params.secondary_phy = (uint8_t)p_advertising->adv_modes_config.ble_adv_secondary_phy;
        }
        else
        {
            p_advertising->adv_params.secondary_phy = BLE_GAP_PHY_1MBPS;
        }
    }
    p_advertising->adv_params.filter_policy = BLE_GAP_ADV_FP_ANY;

    // Set advertising parameters and events according to selected advertising mode.
    switch (p_advertising->adv_mode_current)
    {
        case BLE_ADV_MODE_DIRECTED_HIGH_DUTY:
            ret = set_adv_mode_directed_high_duty(p_advertising, &p_advertising->adv_params);
            break;

        case BLE_ADV_MODE_DIRECTED:
            ret = set_adv_mode_directed(p_advertising, &p_advertising->adv_params);
            break;

        case BLE_ADV_MODE_FAST:
            ret = set_adv_mode_fast(p_advertising, &p_advertising->adv_params);
            break;

        case BLE_ADV_MODE_SLOW:
            ret = set_adv_mode_slow(p_advertising, &p_advertising->adv_params);
            break;

        case BLE_ADV_MODE_IDLE:
            p_advertising->adv_evt = BLE_ADV_EVT_IDLE;
            break;

    }

    if ( !is_connectable )
    {
      p_advertising->adv_params.properties.type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_SCANNABLE_UNDIRECTED;
    }
    
    if (p_advertising->adv_mode_current != BLE_ADV_MODE_IDLE)
    {
        // take the latest status and prepare it encrypted and all 
        comm_tj_fill_status(true);
        
        // call ble_advertising_advdata_update to swap enc_advdata[0] and enc_advdata[1] to ensure first advertise transmitted updated 
        comm_tj_pump_update_advertise(); 
        
        // start advertising 
        ret = sd_ble_gap_adv_start(p_advertising->adv_handle, p_advertising->conn_cfg_tag);
        if (ret != NRF_SUCCESS)
        {
            return ret;
        }
    }

    if (p_advertising->evt_handler != NULL)
    {
        p_advertising->evt_handler(p_advertising->adv_evt);
    }

    return ret;
}

Parents
  • Hi

    I think you need to set the peripheral link count to 2 because a non-connectable advertisement is still a peripheral link, just a non-connectable one. If it is indeed nonconnectable then you shouldn't have to worry about it being connected to afterwards.

    Best regards,

    Simon

  • the comment in ble_gap.h for sd_ble_gap_adv_start says

    "NRF_ERROR_CONN_COUNT means that the limit of available connections for this connection configuration tag has been reached; connectable advertiser cannot be started."

    Increasing the number of available connections also increases the RAM used by the soft device, so i was trying to avoid that... but if that's the only way to do it then i will do that...

Reply
  • the comment in ble_gap.h for sd_ble_gap_adv_start says

    "NRF_ERROR_CONN_COUNT means that the limit of available connections for this connection configuration tag has been reached; connectable advertiser cannot be started."

    Increasing the number of available connections also increases the RAM used by the soft device, so i was trying to avoid that... but if that's the only way to do it then i will do that...

Children
No Data
Related