This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2640R2F: Dynamically adjusting advertising interval at run time

Part Number: CC2640R2F

I am using the simple_broadcaster example in beacon mode and would like to adjust the advertising interval according to the voltage level.

I tried calling:

GAP_SetParamValue(TGAP_LIM_DISC_ADV_INT_MIN, 5*160);
GAP_SetParamValue(TGAP_LIM_DISC_ADV_INT_MAX, 5*160);
GAP_SetParamValue(TGAP_GEN_DISC_ADV_INT_MIN,5*160);
GAP_SetParamValue(TGAP_GEN_DISC_ADV_INT_MAX, 5*160);

from SimpleBLEBroadcaster_taskFxn() but this did not work. The Bluetooth Advertising interval was measured using the current consumption on an oscilloscope.

Is there a proper way of adjusting the advertising interval?

  • Hello,

    The advertising parameters are only sent to the link layer when GAP_MakeDiscoverable() is called.
    The proper way to change the advertising parameters is to stop advertising, change the parameters, and then re-enable advertising via the gap role (broadcaster.c) using GAPROLE_ADVERT_ENABLED.
  • Hello,

    The I did this in SimpleBLEBroadcaster_taskFxn, disabling the advertisement, changing the interval, then enabling it again.

    if (adcValue2 > 2400) {
    advertising_enable = FALSE;
    GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t),
    &advertising_enable);
    GAP_SetParamValue(TGAP_LIM_DISC_ADV_INT_MIN, 160*5);
    GAP_SetParamValue(TGAP_LIM_DISC_ADV_INT_MAX, 160*5);
    GAP_SetParamValue(TGAP_GEN_DISC_ADV_INT_MIN, 160*5);
    GAP_SetParamValue(TGAP_GEN_DISC_ADV_INT_MAX, 160*5);
    advertising_enable = TRUE;
    GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t),
    &advertising_enable);

    } else {
    advertising_enable = FALSE;
    GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t),
    &advertising_enable);
    GAP_SetParamValue(TGAP_LIM_DISC_ADV_INT_MIN, 160*20);
    GAP_SetParamValue(TGAP_LIM_DISC_ADV_INT_MAX, 160*20);
    GAP_SetParamValue(TGAP_GEN_DISC_ADV_INT_MIN, 160*20);
    GAP_SetParamValue(TGAP_GEN_DISC_ADV_INT_MAX, 160*20);
    advertising_enable = TRUE;
    GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t),
    &advertising_enable);
    }

    I was able to update the broadcast interval but only once. When I vary the voltage (measured with adcValue2), the advertising interval does not update. Is there a step I am missing?
  • Hello,

    You have the steps right, but you need to fully wait until the advertisement is stopped before changing the parameters and enabling it again.

    See this code snippet from broadcaster.c

            else if ((oldAdvEnabled == FALSE) && (gapRole_AdvEnabled))
            {
              // Turn on Advertising
              if ((gapRole_state == GAPROLE_STARTED)
                  || (gapRole_state == GAPROLE_WAITING))
              {
                gapRole_setEvent(START_ADVERTISING_EVT);
              }
            }

    In summary you must either be in the GAPROLE_STARTED or GAPROLE_WAITING state in order to be able to either start or stop advertising.

    So the recommendation would be:

    1. On ADC value changed disable advertising, and set variables that old your new advertising interval values

    2. On processing of the GAPROLE_WAITING event in the simple_broadcaster.c file, update the advertising parameters and renable the advertisement.