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

Going from Slow Advertise to Fast Advertise with button press

Hi,

Is it possible to go from slow advertising to fast advertising with a button press?

I did this but it didn't work:

        case BLE_ADV_EVT_FAST:
            #if (ENABLE_TASK_NRF_LOG) 
            NRF_LOG_INFO("Fast advertising.");
            #endif // ENABLE_TASK_NRF_LOG

            #if ENABLE_BLE_LED_BUTTON
            err_code = bsp_indication_set(BSP_INDICATE_ADVERTISING);
            APP_ERROR_CHECK(err_code);

            set_battery_led_indicate = false;
            #endif //ENABLE_BLE_LED_BUTTON

            break;

        case BLE_ADV_EVT_SLOW:
            #if (ENABLE_TASK_NRF_LOG) 
            NRF_LOG_INFO("Slow advertising.");
            #endif // ENABLE_TASK_NRF_LOG

            #if ENABLE_BLE_LED_BUTTON
            err_code = bsp_indication_set(BSP_INDICATE_ADVERTISING_SLOW);
            APP_ERROR_CHECK(err_code);

            set_battery_led_indicate = false;
            #endif //ENABLE_BLE_LED_BUTTON

            // Prepare wakeup buttons.
            err_code = bsp_btn_ble_sleep_mode_prepare();
            APP_ERROR_CHECK(err_code);

            break;


P.S. I slightly modified names and operation of my LED indication modes but I can clearly distinguish the two and pressing the button does not switch the LED state - that's how I can tell it didn't switch back to fast advertising.

Parents
  • Hi,

    Is it possible to go from slow advertising to fast advertising with a button press?

    I don't see exactly how the code snippet is related to the question, but yes, that is possible. You need some code for getting an event on the button press (for instance using the BSP module), and when you get the button press you can first stop any current advertisers with a call to sd_ble_gap_adv_stop() ignoring the return value in this case so that it will work regardless if it was active or not, and then call ble_advertising_start() with BLE_ADV_MODE_FAST as the second parameter.

    If you want an example, you can refer to one of the examples that let you push a button to restart advertising without whitelisting. You could simply replace the call to ble_advertising_restart_without_whitelist() with what I suggested above.

Reply
  • Hi,

    Is it possible to go from slow advertising to fast advertising with a button press?

    I don't see exactly how the code snippet is related to the question, but yes, that is possible. You need some code for getting an event on the button press (for instance using the BSP module), and when you get the button press you can first stop any current advertisers with a call to sd_ble_gap_adv_stop() ignoring the return value in this case so that it will work regardless if it was active or not, and then call ble_advertising_start() with BLE_ADV_MODE_FAST as the second parameter.

    If you want an example, you can refer to one of the examples that let you push a button to restart advertising without whitelisting. You could simply replace the call to ble_advertising_restart_without_whitelist() with what I suggested above.

Children
No Data
Related