I am using nRF52832, SDK_15.3.0, S132 SoftDevice and Segger for flashing the image. I am using ‘ble_app_blinky’.
In my application, I am starting BLE advertisement only when button is pressed. Also advertisement will timeout after 3 minutes. Currently it is working fine.
But I have a requirement where BLE advertisement should restart. I mean if already advertisement happening and if it completed 2 minutes duration. Now if I press a button, advertisement should timeout after 3 minutes rather than after 1 minute.
For this I just called advertising_start(). For first time button press its working fine. But when I press the same button within 2 minutes I am getting exception with error NRF_ERROR_INVALID_STATE (8) within advertising_start().
err_code = sd_ble_gap_adv_start(m_adv_handle, APP_BLE_CONN_CFG_TAG);
NRF_LOG_INFO("AdvFail %d", err_code);
Please let me know how to implement above scenario.
Thanks & Regards
You will always get NRF_ERROR_INVALID_STATE returned if you try to start advertising when it is already active. A better way to do this is probably to stop and then re-start advertising.
Can I blindly call stop advertisement functionality even though advertisement did not started at all. Below is the code I tested and its seems working. Can you please cross check and let me know your inputs.
ret_code_t err_code = sd_ble_gap_adv_start(m_adv_handle, APP_BLE_CONN_CFG_TAG);
ret_code_t err_code = sd_ble_gap_adv_stop(m_adv_handle);
beemavishnu said:Can I blindly call stop advertisement functionality even though advertisement did not started at all
If your device is not advertising when you call sd_ble_gap_adv_stop, it will return NRF_ERROR_INVALID_STATE - but that is harmless. So you just need to handle that case as an "OK" result.
Note that if you use the 'Go To Declaration' feature of your IDE there will be comments there which describe the possible return codes, and what causes them.
Thank you for your inputs