Changing adv_params.channel_mask while adv is ongoing

Hi!


With SDK15, I figured that is possible to change the advertisement content on the fly by overwriting the content of `adv_data.adv_data.p_data` and updating `adv_data.adv_data.len` accordingly. But, if I instead change `m_advertising.adv_params.channel_mask` that does not seem to be doing anything. Static initialization of that field works flawlessly.

Calling `sd_ble_gap_adv_set_configure()` after changing `adv_params` seems to return various errors.. I tried calling it with `p_adv_data == NULL` and `adv_data` to no avail.

Does anyone have an example of how to change advertising channel on the fly?

Parents
  • Hello Michele,

    What type of advertising are you attempting to change the channel on? LE uses 3 advertising channels for regular adverts and while you can disable 1 or 2 or change the order in which they are used, you can't dynamically control them. Periodic advertising would follow the channel map procedures for non-ADV channels. 

    Can you expand a bit on what you are attempting to do?

    Thank you,

    Jennifer Gibbs

  • I did setup a BLE connectable advertising instance.
    In addition to changing the content of the advertisement every interval, I would also be able to select which of the 3 channels (37, 38, 39) will actually be used. 

    While this works

    memcpy(advinstance.adv_data.adv_data.p_data, advpayload[k], advpayloadlen[k]);
    advinstance.adv_data.adv_data.len = advpayloadlen[k];

    This does not do anything
    advinstance.adv_params.channel_mask[4] = 0b11000000; // only adv on CH37
    Hope this helps?
  • Where did you find channel_mask as a valid adv_param field? The only options are to disable one or more of the 3 channels but I could be missing something.

    The spec, to the best of my knowledge, allows you to modify the order the 3 channels are used or disable as stated above during the advertising setup only. Once adverts are started they will always use all 3 (unless you've disabled one or more) for each advertising event, possibly randomizing the order of the 3 channels if selected. If you want to change that behavior, you have to stop adverts, change the parameters, and restart adverts.

    I am not aware of a feature to dynamically change the advertising channel unless you are using periodic advertising which would require devices to synchronize in order to operate together. However, these all take place on the 37 Data Channels which require channel_mask feature. 

Reply
  • Where did you find channel_mask as a valid adv_param field? The only options are to disable one or more of the 3 channels but I could be missing something.

    The spec, to the best of my knowledge, allows you to modify the order the 3 channels are used or disable as stated above during the advertising setup only. Once adverts are started they will always use all 3 (unless you've disabled one or more) for each advertising event, possibly randomizing the order of the 3 channels if selected. If you want to change that behavior, you have to stop adverts, change the parameters, and restart adverts.

    I am not aware of a feature to dynamically change the advertising channel unless you are using periodic advertising which would require devices to synchronize in order to operate together. However, these all take place on the 37 Data Channels which require channel_mask feature. 

Children
  • Where did you find channel_mask as a valid adv_param field?

    The `ble_advertising_t` struct has a field 

    ```

    ble_gap_adv_params_t adv_params; /**< GAP advertising parameters. */
    ```

    and the `ble_gap_adv_params_t` struct has a field
    ```

    ble_gap_ch_mask_t channel_mask; /**< Channel mask for primary and secondary advertising channels.
    At least one of the primary channels, that is channel index 37-39, must be used.
    Masking away secondary advertising channels is not supported. */
    ```
    The function `ble_advertising_init()` does 
    ```
    // Configure a initial advertising configuration. The advertising data and and advertising
    // parameters will be changed later when we call @ref ble_advertising_start, but must be set
    // to legal values here to define an advertising handle.
    p_advertising->adv_params.primary_phy = BLE_GAP_PHY_1MBPS;
    p_advertising->adv_params.duration = p_advertising->adv_modes_config.ble_adv_fast_timeout;
    p_advertising->adv_params.properties.type = BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED;
    p_advertising->adv_params.p_peer_addr = NULL;
    p_advertising->adv_params.filter_policy = BLE_GAP_ADV_FP_ANY;
    p_advertising->adv_params.interval = p_advertising->adv_modes_config.ble_adv_fast_interval;

    ret = sd_ble_gap_adv_set_configure(&p_advertising->adv_handle, NULL, &p_advertising->adv_params);
    VERIFY_SUCCESS(ret);
    ```
    and it's valid to change the mask here.
    But, once it's started, with `ble_advertising_start()`, then it seems like the data can change, but the mask cannot.
    Sounds like you are confirming this in your last message?
Related