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

Changing advertising modes from IDLE to FAST SDK V15.0

I am migrating from SDK v14.2.0 to v15.0.0 and from S132 to S112 (v6) using the NRF52810. I have mostly everything migrated, but a functionality that worked before does not seem to behave correctly now and have not been able to find the root cause.

I am using a whitelist, but if there are no peers, the device is started with:

ble_advertising_start(&m_advertising, BLE_ADV_MODE_IDLE);

and then after a user button press, the device will then switch to advertising without a whitelist:

    ret_code_t err_code;
    
    m_advertising.adv_mode_current = BLE_ADV_MODE_FAST;
    m_advertising.adv_modes_config.ble_adv_fast_timeout = APP_ADV_NOWHITELEST_TIMEOUT_IN_SECONDS;
    
    err_code = ble_advertising_restart_without_whitelist(&m_advertising);
    if (err_code != NRF_ERROR_INVALID_STATE)
    {
        APP_ERROR_CHECK(err_code);
    }

but that results in an error code 7 (NRF_ERROR_INVALID_PARAM).

If the device starts out in BLE_ADV_MODE_FAST, instead of BLE_ADV_MODE_IDLE, calling ble_advertising_restart_without_whitelist(), returns correctly.

Any suggestions?

Thank you.

Parents
  • Hi!

    That sounds strange.

    Is is possible for you to upload your code? So that I can get a better overview of what is going on.

    If your code contains any sensitive information and you don't want to upload your code to the public forum, it is possible to turn the case private first.

    Best regards,
    Joakim.

  • The file main.c I linked duplicates the issue, which occurs when it is in idle then ble_advertising_restart_without_whitelist is called to switch to fast mode. Would you be able to evaluate this?

    I will send the results of your request when i get back in the office.

  • FormerMember
    0 FormerMember in reply to amorgan

    I cannot see directly from the main.c what is causing the issue. When you have the failing and working parameters avaiable, please upload them here.

  • Sorry for the delay, Attached are the before and after. Note I get the error when ble_advertising_restart_without_whitelist calls flags_set.

    Before update m_advertising coming from IDLE:

    Before updating

    Before ble_advertising_restart_without_whitelist calls flags_set:

    Before flags_set

    After flags_set returns Error (0x07):

    After flags_set

    LLet me know if this helps.

    TThank you.

  • static void sleep_mode_enter(void)
    {
        ret_code_t err_code;
        
        m_advertising.adv_mode_current = BLE_ADV_MODE_FAST;
        m_advertising.adv_params.duration = 10000;
        m_advertising.adv_params.interval = APP_ADV_INTERVAL;
    
        err_code = ble_advertising_restart_without_whitelist(&m_advertising);
        if (err_code != NRF_ERROR_INVALID_STATE)
        {
            APP_ERROR_CHECK(err_code);
        }
    }

    Hi amorgan, try the code above instead. You were setting configs that are only being read during ble_advertising_init().

    On a related note, if you are not using whitelist, you should never have to call ble_advertising_restart...

    instead you can just call ble_advertising_start(&m_advertising,APP_ADV_MODE_FAST) when you get the idle event.

    Good luck!

  • Håvard,

       Thanks for the reply! This resolved the error I was getting, but it was not setting the duration correctly.

    Stepping through ble_advertising_start, you will see that

    memset(&p_advertising->adv_params, 0, sizeof(p_advertising->adv_params));

    is called, which clears out the adv_params. Therefore, the following is what was needed to get the duration / timeout to fully work and to not get the original error message:

    static void sleep_mode_enter(void)
    {
        ret_code_t err_code;
        
        m_advertising.adv_mode_current = BLE_ADV_MODE_FAST;
        m_advertising.adv_modes_config.ble_adv_fast_timeout = 10000;
        m_advertising.adv_modes_config.ble_adv_fast_interval = APP_ADV_INTERVAL;
        
        m_advertising.adv_params.duration = 10000;
        m_advertising.adv_params.interval = APP_ADV_INTERVAL;
    
        err_code = ble_advertising_restart_without_whitelist(&m_advertising);
        if (err_code != NRF_ERROR_INVALID_STATE)
        {
            APP_ERROR_CHECK(err_code);
        }
    }

    Note also that if m_advertising.adv_params.interval = APP_ADV_INTERVAL; is not set before calling ble_advertising_restart_without_whitelist, I still get the invalid parameters error. Even though I was not intending to change the interval, only duration, this still was needed.

    Is there any documentation on how to correctly change these parameters? It seems as if the new SDK does not handle this as seamlessly as one would expect.

    Also, I am using a whitelist, but in this specific case, where there are no bonds, I do not want the device to be advertising, which does occur when using a whitelist when there are no bonds. Therefore I prevent this from happening by forcing it to go to idle, then on user input, change to advertise without whitelist to get the initial bond.

    Either way, thank you for helping out, this has now solved my issue.

Reply
  • Håvard,

       Thanks for the reply! This resolved the error I was getting, but it was not setting the duration correctly.

    Stepping through ble_advertising_start, you will see that

    memset(&p_advertising->adv_params, 0, sizeof(p_advertising->adv_params));

    is called, which clears out the adv_params. Therefore, the following is what was needed to get the duration / timeout to fully work and to not get the original error message:

    static void sleep_mode_enter(void)
    {
        ret_code_t err_code;
        
        m_advertising.adv_mode_current = BLE_ADV_MODE_FAST;
        m_advertising.adv_modes_config.ble_adv_fast_timeout = 10000;
        m_advertising.adv_modes_config.ble_adv_fast_interval = APP_ADV_INTERVAL;
        
        m_advertising.adv_params.duration = 10000;
        m_advertising.adv_params.interval = APP_ADV_INTERVAL;
    
        err_code = ble_advertising_restart_without_whitelist(&m_advertising);
        if (err_code != NRF_ERROR_INVALID_STATE)
        {
            APP_ERROR_CHECK(err_code);
        }
    }

    Note also that if m_advertising.adv_params.interval = APP_ADV_INTERVAL; is not set before calling ble_advertising_restart_without_whitelist, I still get the invalid parameters error. Even though I was not intending to change the interval, only duration, this still was needed.

    Is there any documentation on how to correctly change these parameters? It seems as if the new SDK does not handle this as seamlessly as one would expect.

    Also, I am using a whitelist, but in this specific case, where there are no bonds, I do not want the device to be advertising, which does occur when using a whitelist when there are no bonds. Therefore I prevent this from happening by forcing it to go to idle, then on user input, change to advertise without whitelist to get the initial bond.

    Either way, thank you for helping out, this has now solved my issue.

Children
No Data
Related