Handling of mixed Advertising and Extended Advertising

Hallo,

currently I test several options in regarding the use of advertising. I have a few nRF52840-DK and use Zephyr 2.7-99 and ncs. I have a question regarding combined use of extended advertising and "simple" advertising.

I create an advertising set with bt_le_ext_adv_create(..). Than, I set my transmit data with bt_le_ext_adv_set_data(..), start extended advertising with bt_le_ext_adv_start(..) and stop it after a few transmits with bt_le_ext_adv_stop(..). After a while I do the cycle bt_le_ext_adv_set_data(..) - bt_le_ext_adv_start(..) - bt_le_ext_adv_stop(..) again, and so on. This runs well, no problems. Now I want to use the pause between this cycles to start a simple advertising with bt_le_adv_start(..). Here I saw an error (-12 - not enough memory). I found that I have to delete the advertising set with bt_le_ext_adv_delete(..).

I wonder why I see such a behaviour. It's quite clear that I can't have two different advertising schemes running at the same time. But my extended advertising doesn't run, it is stopped. The advertising set is in my mind just a "collection" of parameters regarding the extended advertising, which is stored in the memory. Furthermore, as far as I understood the functions, I can have a number of advertising sets and pick up one of them when starting extended advertising. So the stack should be able to handle several advertising sets. But why can I not start a simple advertising, when an advertising set exists? The set isn't touched, and the simple advertising doesn't need one.

Kind regards

Axel

Parents
  • Hello Axel,

    You need to use the bt_le_ext_adv_* APIs for all advertising when the CONFIG_BT_EXT_ADV symbol is enabled. However, this should not be a problem as you also can create legacy advertisement sets with this API. Just omit the BT_LE_ADV_OPT_EXT_ADV option when creating the adv. set.

    The number of advertising sets you can create is defined by the BT_EXT_ADV_MAX_ADV_SET symbol here: https://github.com/nrfconnect/sdk-zephyr/blob/v2.7.99-ncs1-branch/subsys/bluetooth/Kconfig.adv#L41

    Kind regards,

    Vidar

  • Hallo Vidar,

    your right, with BT_EXT_ADV_MAX_ADV_SET=2 I can have two advertising sets and I'm able to start extended as well as simple advertising. But there is a remaining question: Using the simple advertising alone, starting by means of bt_le_adv_start(..), I have the two arrays "ad" and "sd" for setting a number of flags and options. When starting the simple advertising in the "combined" mode by means of bt_le_ext_adv_start(..), I have just one parameter set. How can I manage the all the options from the simple example? I could create "ad" and set this data portion with bt_le_ext_adv_set_data(..), but how to handle "sd"?

    Kind regards

    Axel

  • Hallo Axel,

    You can pass your scan response packet to bt_le_ext_adv_set_data() too. From the API documentation:

    Kind regards,

    Vidar

  • Hallo Vidar,

    thanks, this point is ok now (to be honest: I could have seen it by myself). But for the next step a next question occurs:

    When I use the simple advertising, I have (according to the UART example) callback functions by means of

    BT_CONN_CB_DEFINE(conn_callbacks) = {
        .connected        = connected,
        .disconnected     = disconnected,};

    i.e. in the end using bt_con_cb. For extended advertising, I have the callback structure bt_le_ext_adv_cb, but this structure doesn't contain a disconnect callback. What have I to do here to obtain the same functionality?

    Kind regards

    Axel

  • Hallo Vidar,

    a short update: When setting CONFIG_BT_EXT_ADV_MAX_ADV_SET=2, I can use extended advertising and simple advertising in one setting as described originally. In that case there is no issue regarding the callbacks.

    I don't know - according to your first answer - if it is intended to use extended advertising only, once this option is configured. I also don't know if the internal handling might be different in that case. But using simple advertising and extended advertising in one setting (ensuring that there is always only one of them running) seems ok for now.

    Kind regards

    Axel

Reply
  • Hallo Vidar,

    a short update: When setting CONFIG_BT_EXT_ADV_MAX_ADV_SET=2, I can use extended advertising and simple advertising in one setting as described originally. In that case there is no issue regarding the callbacks.

    I don't know - according to your first answer - if it is intended to use extended advertising only, once this option is configured. I also don't know if the internal handling might be different in that case. But using simple advertising and extended advertising in one setting (ensuring that there is always only one of them running) seems ok for now.

    Kind regards

    Axel

Children
  • hi

    i followed all steps that u have told here.but still iam facing enomem error...

    err = bt_le_ext_adv_stop(adv);

    if (err) {
        printk("Failed to stop advertising (err %d)\n", err);
    } else {
        printk("Advertising stopped successfully\n");
    }
    bt_le_ext_adv_delete(adv);
    /*

    struct bt_le_adv_param param = {
        .id = BT_ID_DEFAULT,
        .sid = 0,
        .secondary_max_skip = 0,
        .options = BT_LE_ADV_OPT_EXT_ADV | BT_LE_ADV_OPT_CONNECTABLE,
        .interval_min = params.interval/0.625,  
        .interval_max = params.interval/0.625,
        .peer = NULL,
    };
    */
    struct bt_le_adv_param param =
            BT_LE_ADV_PARAM_INIT(BT_LE_ADV_OPT_EXT_ADV | BT_LE_ADV_OPT_CONNECTABLE,
                         3000,
                         3000,
                         NULL);

        // Update advertising data
        struct bt_data ad[] = {
            BT_DATA(BT_DATA_NAME_COMPLETE, name_buffer, DEVICE_NAME_LEN),
             BT_DATA_BYTES(BT_DATA_FLAGS, BT_LE_AD_NO_BREDR),
            BT_DATA(BT_DATA_MANUFACTURER_DATA, manufacturer_data, sizeof(manufacturer_data)),
            BT_DATA(BT_DATA_MANUFACTURER_DATA, adv_data, sizeof(adv_data)),  


        };


        // Start advertising with updated data
         err = bt_le_ext_adv_create(&param, NULL, &adv);
        if (err) {
            printk("Failed to create advertising set (err %d)\n", err);
            return err;
        }

        err = bt_le_ext_adv_set_data(adv, ad, ARRAY_SIZE(ad), NULL, 0);
        if (err) {
            printk("Failed to set advertising data (err %d)\n", err);
            return 0;
        }
       
    set_tx_power(BT_HCI_VS_LL_HANDLE_TYPE_ADV, 0, 8);
        err = bt_le_ext_adv_start(adv, &start_params);
        if (err) {
            printk("Failed to start extended advertising (err %d)\n", err);
        }
        else
        {
        printk("Advertising successfully started\n");
        }
Related