NRF52, ble_blinky example: advertising timeout event and sleep calls, how?

Hi,

I am using the ble_blinky example as a template to develop my project, with nRF52832  and SDK 17.0.2.

My first goal is to reduce consumption, so I have changed the advertising time to 5 seconds, after this time it is automatically powered off. I need to configure a button before it goes to sleep to enable waking up.

For the blinky example, the question is what function is getting this timeout event and putting the device to sleep? 

i.e., in the ble_app_uart example, as mentioned in this thread, I can find it in the ble_advertising.c file, but for the blinky example, it doesn´t use this file, so I am not able to identify where the event detection and the sleeping function call is happening.

Thanks in advance!

  • Hi

    Just to make sure, in order to have "changed the advertising time to 5 seconds" you edited the #define APP_ADV_DURATION last for 5 seconds, or alternatively changed the adv_params.duration to 5 seconds in your advertising_init() function, correct? This means it will advertise for 5 seconds before going to sleep (likely without connecting at all, since 5 seconds is not much time for a central to discover it and connect to it. The ble_app_blinky uses the sd_ble_gap_adv_start function in the SoftDevice to start advertising, and according to the message sequence chart it will go to IDLE mode if it times out before connecting to a device.

    I strongly recommend that you increase this somewhat so a central has the chance to connect to your device, as this example project is designed to connect to a device. If not I would check out the ble_app_beacon project instead, which is designed to only advertise.

    Best regards,

    Simon

  • Hi Simon,

    Thanks for your reply. Yes, I am using #define APP_ADV_DURATION 500. So far is connecting to the central, I will increase it if I find issues with that. 

    I need to connect to the central, I am just powering it off quickly to save power.

    I guess I can't or shouldn´t modify the softdevice code. My intention is to set up the button to wake up when is pressed.

    I added this case into the ble_evt_handler and it prints the message.

            case BLE_GAP_EVT_ADV_SET_TERMINATED:
            	NRF_LOG_INFO("AdvTimeout!");
            	break;

    I have now to add the code to prepare the button before going to sleep, which I haven´t done before, if you had a simple piece of code for it would be much appreciated, or some indications.

    Another question is, when it wakes up, does it reset or continue in the infinite loop? 

    Thanks!

  • Hi

    If you're connecting to the central device the advertiser won't go to sleep after 5 seconds, as it will stay in a connected state until it either is disconnected from the central or peripheral side or the connection supervision time runs out.

    To see how you can set up wakeup buttons, please check out the sleep_mode_enter() function which is present in multiple example projects in the nRF5 SDK. The ble_app_gls example for instance.

    /**@brief Function for putting the chip into sleep mode.
     *
     * @note This function will not return.
     */
    static void sleep_mode_enter(void)
    {
        ret_code_t err_code;;
        err_code = bsp_indication_set(BSP_INDICATE_IDLE);
        APP_ERROR_CHECK(err_code);
    
        // Prepare wakeup buttons.
        err_code = bsp_btn_ble_sleep_mode_prepare();
        APP_ERROR_CHECK(err_code);
    
        // Go to system-off mode (this function will not return; wakeup will cause a reset).
        err_code = sd_power_system_off();
        APP_ERROR_CHECK(err_code);
    }

    Best regards,

    Simon

  • Hi,

    I didn´t explain myself. The idea is that the peripheral is sleeping when it is not connected to the central. To wake it up, the user presses the button. Once they are connected, I don´t need it to go to sleep as the consumption is acceptable for some time. 

    Many thanks for your help, I will explore the example soon.

    Regards

Related