This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Restart the advertising

Dear Sir,

I want to do the following scenario.

Once I power the device it will start advertising.

Now the advertising duration is 2minutes.

I have written a routine based on timer. When it is called it should initiate the advertising again.

How can I  restart an advertising sequence once a current advertising going on?.

I tried the following sequence

(void) sd_ble_gap_adv_stop(&m_advertising.adv_handle);
advertising_start(erase_bonds);

But it shows the error

 WakeUp
<error> app: ERROR 8 [NRF_ERROR_INVALID_STATE] at I:\GK\Rigado\sdk\nRF5_SDK_15.0.0_a53641a\examples\ble_peripheral\Sieva_prod1_wologs\main.c:1325

What am I missing in restarting advertising routine?

In function "ble_advertising_restart_without_whitelist()", I think it follows the same sequence.

But I dont know why it is not working for me.

Please shed some light on this.

with regards,

Geetha

Parents
  • Hi.

    The error code is most likely because when you try to stop advertising, you're not advertising. Look at this question for more information about NRF_ERROR_INVALID_STATE and advertising.

    The proper way to start/stop would be:

    //Stop
    err_code = sd_ble_gap_adv_stop(m_adv_handle);
    APP_ERROR_CHECK(err_code);
    NRF_LOG_INFO("Stopping advertising");
            
    //Start        
    err_code = sd_ble_gap_adv_start(m_adv_handle, APP_BLE_CONN_CFG_TAG);
    APP_ERROR_CHECK(err_code);
    NRF_LOG_INFO("Starting advertising");

    Look at this question, there is an attached .zip file containing a modified beacon example, where start/stop advertising is implemented as a handle of pressing button 1 (in void in_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action))

    - Andreas

  • Hi,

    Thank you very much for your response.

    My scenario is as follows.

    I am using 2 timers.

    First timer will wake up for each 5 mins and second one wake up after the first 1 minute.

    So when I start the device , it advertises. And initial 1 minute I will do a connect-disconnect method to get the adddresses.

    Now once I disconnect the device it will start advertising since the function "ble_advertising_start()"  is getting called inside "on_disconnected()" function.

    If I want to stop advertising from the main.c file  how can I do this?..

    how can I get the advertising handle?

    Which function I should call from the main function to stop the current advertising instance and to start a new one?

    I tried your scenario, but it shows the same problem

    Thanking you

  • Hi.

    ble_advertising_start() is an API call to start advertising using the Advertising Module. At the bottom of the module, advertising is started by sd_ble_gap_adv_start() (line 657 in ble_advertising.c) If you don't need to do some of the "extra things" you refer to before you start advertising, you don't need to use ble_advertising_start().

    If you only need to start or stop advertising you can safely use only sd_ble_gap_adv_start() and sd_ble_gap_adv_stop().

    - Andreas

  • Hi ,

    Suppose if we use ble_advertising_start() to start the advertising.

    Can I use sd_ble_gap_adv_stop(). to stop the current instance of advertising?

    If yes, what should be the steps to be taken?

    Can I use sd_ble_gap_adv_start() to restrat the advertising again after stopping one instance of advertising?

    PLease share your ideas on the same.

    with regards,

    Geetha

  • Hi.

    I've been out of office this week.

    Yes, you can use sd_ble_gap_adv_stop() to stop the current instance of advertising, just call it and use your advertising handle as input in the function.

    And yes, you can start it again by using sd_ble_gap_adv_start(), just call it and use your advertising hnadle as a input in the function.

    - Andreas

  • if I write this 

    //Stop
    err_code = sd_ble_gap_adv_stop(m_adv_handle);
    APP_ERROR_CHECK(err_code);
    NRF_LOG_INFO("Stopping advertising");

    //Start
    err_code = sd_ble_gap_adv_start(m_adv_handle, APP_BLE_CONN_CFG_TAG);
    APP_ERROR_CHECK(err_code);
    NRF_LOG_INFO("Starting advertising");

    Then I am getting these errors:

    ./../../main.c: In function 'nus_data_handler':
    ../../../main.c:205:32: error: 'm_adv_handle' undeclared (first use in this function); did you mean 'm_conn_handle'?
    err_code = sd_ble_gap_adv_stop(m_adv_handle);
    ^~~~~~~~~~~~
    m_conn_handle
    ../../../main.c:205:32: note: each undeclared identifier is reported only once for each function it appears in
    ../../../main.c:205:12: error: too many arguments to function 'sd_ble_gap_adv_stop'
    err_code = sd_ble_gap_adv_stop(m_adv_handle);
    ^~~~~~~~~~~~~~~~~~~
    In file included from ../../../../../../components/softdevice/s132/headers/ble_gap.h:49,
    from ../../../../../../components/softdevice/s132/headers/ble.h:52,
    from ../../../../../../components/ble/common/ble_advdata.h:55,
    from ../../../main.c:56:
    ../../../../../../components/softdevice/s132/headers/ble_gap.h:1448:39: note: declared here
    SVCALL(SD_BLE_GAP_ADV_STOP, uint32_t, sd_ble_gap_adv_stop(void));
    ^~~~~~~~~~~~~~~~~~~
    ../../../../../../components/softdevice/s132/headers/nrf_svc.h:64:22: note: in definition of macro 'SVCALL'
    static return_type signature \
    ^~~~~~~~~
    ../../../main.c:210:47: error: 'APP_BLE_CONN_CFG_TAG' undeclared (first use in this function); did you mean 'BLE_CONN_CFG_GAP'?
    err_code = sd_ble_gap_adv_start(m_adv_handle, APP_BLE_CONN_CFG_TAG);

  • Hi

    It seems like you are having quite a few undeclared identifiers in your applications. Please make sure these are declared in your project and try again.

    This ticket is over 1 year old, so if you're having trouble with this, I suggest creating a new ticket describing your issue in detail.

    Best regards,

    Simon

Reply Children
No Data
Related