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

Switching advertising type

I have seen that the recommended method for switching between connectable and non-connectable advertising is:

    sd_ble_gap_adv_stop()
    ...change advertising structures as needed...
    sd_ble_gap_adv_start()

My app is doing this, and it works. But using sd_ble_gap_adv_start() instead of ble_advertising_start() causes my app to no longer get events to on_adv_evt(). When I try to change to using ble_advertising_start() instead, I get crashes on restarting (works fine starting the first time).

So is there a way to switch between connectable and non-connectable advertising while still getting advertising events?

Parents
  • Hello,

    Your approach seems correct. Stop advertising, run another advertising_init() function where you change your advertising parameters, and start advertising again.

     

    When your project crashes, it might be that a function call, returning an err_code != NRF_SUCCESS is passed onto an APP_ERROR_CHECK(err_code), which will reboot your application. Can you try to define "DEBUG" in your preprocessor defines, turn off optimization, and try to set a breakpoint inside app_error_handler(...) on line 65 approximately (depending on what SDK version you use), and see if you can find the .line_num, .p_file_name and .err_code that caused the error. What function call returned the err_code, and what was the err_code?

     

    Best regards,

    Edvin

  • I'm using SDK 14.2. Here's a gdb stack trace (I have APP_ERROR_CHECK raise a breakpoint):

    #0 app_error_handler_bare (err_code=18) at /home/lee/work/argos/lib/nrf/sys_nrf.c:372
    #1 0x0002a20c in advertising_start (this=0x200043f8 <_ble_object>) at /home/lee/work/argos/lib/nrf/ble_nrf.c:165
    #2 0x0002a288 in on_connect (this=0x200043f8 <_ble_object>) at /home/lee/work/argos/lib/nrf/ble_nrf.c:185
    #3 0x0002a476 in ble_evt_handler (pevt=0x2000fd88, context=0x200043f8 <_ble_object>) at /home/lee/work/argos/lib/nrf/ble_nrf.c:208
    #4 0x000271d2 in nrf_sdh_ble_evts_poll (p_context=0x0) at /opt/Nordic/SDK14.2/components/softdevice/common/nrf_sdh_ble.c:285
    #5 0x000277d4 in nrf_sdh_evts_poll () at /opt/Nordic/SDK14.2/components/softdevice/common/nrf_sdh.c:378

    So it is ble_advertising_start() itself that's returning error 0x12 (NRF_ERROR_CONN_COUNT ?).

    Perhaps it would be better to run my on_connect() handler with the scheduler?

Reply
  • I'm using SDK 14.2. Here's a gdb stack trace (I have APP_ERROR_CHECK raise a breakpoint):

    #0 app_error_handler_bare (err_code=18) at /home/lee/work/argos/lib/nrf/sys_nrf.c:372
    #1 0x0002a20c in advertising_start (this=0x200043f8 <_ble_object>) at /home/lee/work/argos/lib/nrf/ble_nrf.c:165
    #2 0x0002a288 in on_connect (this=0x200043f8 <_ble_object>) at /home/lee/work/argos/lib/nrf/ble_nrf.c:185
    #3 0x0002a476 in ble_evt_handler (pevt=0x2000fd88, context=0x200043f8 <_ble_object>) at /home/lee/work/argos/lib/nrf/ble_nrf.c:208
    #4 0x000271d2 in nrf_sdh_ble_evts_poll (p_context=0x0) at /opt/Nordic/SDK14.2/components/softdevice/common/nrf_sdh_ble.c:285
    #5 0x000277d4 in nrf_sdh_evts_poll () at /opt/Nordic/SDK14.2/components/softdevice/common/nrf_sdh.c:378

    So it is ble_advertising_start() itself that's returning error 0x12 (NRF_ERROR_CONN_COUNT ?).

    Perhaps it would be better to run my on_connect() handler with the scheduler?

Children
No Data
Related