I'm migrating a project from SDK 14.2.0 to SDK 15.3.0. I use gcc. I have three advertising modes and the first of them is working fine. For the second one, the same
I'm migrating a project from SDK 14.2.0 to SDK 15.3.0. I use gcc. I have three advertising modes and the first of them is working fine. For the second one, the same
Hi Elliot,
I sincerely apologize for the very late reply.
We do provide a migration guide in the first release of a new major version number, e.g. SDK v15.0.0. Here is the Migration guide from SDK v14.2.0 to SDK v15.0.0. As far as I can see the only change is that the directed advertisement modes have been renamed.
Did you go deeper into ble_advertising_init()? I guess it was sd_ble_gap_adv_set_configure that returned NRF_ERROR_INVALID_PARAM.
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);
It could appear that not setting the ble_adv_fast_timeout and/or ble_adv_fast_interval will cause sd_ble_gap_adv_set_configure() to return NRF_ERROR_INVALID_PARAM.
No worries. Yes, I went deeper but quickly hit the SD call, beyond which of course I don't have the code. OK, thanks, but why is this invalid? I didn't use to be. It used to be fine to do a bit of slow advertising alone. Now I have to do some fast advertising first. Why? And is my understanding correct?
Hi Eliot,
just doing slow advertising is not invalid. I believe this is due to how the ble_advertising_init() function is using the parameters in ble_advertising_init_t init.config struct. As you see in the end of ble_advertising_init, it sets the advertisment interval and timeout to p_advertising->adv_modes_config.ble_adv_fast_interval and p_advertising->adv_modes_config.ble_adv_fast_timeout.
So passing the following configuration to ble_advertising_init
init.config.ble_adv_slow_enabled = true;
init.config.ble_adv_slow_interval = APP_ADV_INTERVAL;
init.config.ble_adv_slow_timeout = APP_ADV_DURATION;
/*
init.config.ble_adv_fast_enabled = false; //true
init.config.ble_adv_fast_interval = APP_ADV_INTERVAL;
init.config.ble_adv_fast_timeout = APP_ADV_DURATION;
*/
init.evt_handler = on_adv_evt;
err_code = ble_advertising_init(&m_advertising, &init);
APP_ERROR_CHECK(err_code);
will result in p_advertising->adv_params.duration and p_advertising->adv_params.interval being set to zero. But, if you modify ble_advertising_init to the following, then you should not get any errors.
// 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_slow_timeout; // 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_slow_interval; // ble_adv_fast_interval ret = sd_ble_gap_adv_set_configure(&p_advertising->adv_handle, NULL, &p_advertising->adv_params); VERIFY_SUCCESS(ret);
Best regards
Bjørn
So it's a bug in ble_advertising_init()?
No, as the comment in the ble_advertising_init states
// 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.
When you start advertising using ble_advertising_start, then the intervals set in ble_advertising_init_t init struct will be used, i.e. if you call
ble_advertising_start(&m_advertising, BLE_ADV_MODE_SLOW);
then the following parameters will be used.
init.config.ble_adv_slow_interval = APP_ADV_INTERVAL;
init.config.ble_adv_slow_timeout = APP_ADV_DURATION;
Best regards
Bjørn
No, as the comment in the ble_advertising_init states
// 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.
When you start advertising using ble_advertising_start, then the intervals set in ble_advertising_init_t init struct will be used, i.e. if you call
ble_advertising_start(&m_advertising, BLE_ADV_MODE_SLOW);
then the following parameters will be used.
init.config.ble_adv_slow_interval = APP_ADV_INTERVAL;
init.config.ble_adv_slow_timeout = APP_ADV_DURATION;
Best regards
Bjørn