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

Wake on timer vs slow advertising

Hi,

my application consists of long waiting time without connection (hours, possibly days, weeks), then a central connects and downloads data, and then again long waiting time until next connection. I have no buttons or other external components to trigger wakeup, so I need to rely on internal periodic wakeup.

What would be best solution to achieve this type of operation? I'd like to wake about every 5 seconds, advertise for 500ms, then sleep again. Is slow advertising intended for such purpose? It is puzzling because documentation says slow advertising goes to idle state if no connection after timeout.

I have tried to modify ble_app_hrs example using timers to just stop advertising instead of going system off, but I get periodic system resets every second.. still working on this..

I also found this thread devzone.nordicsemi.com/.../, but the linked code is not available any more.

Any help appreciated.

Borut

Parents
  • As you have not buttons or any other external source to wake up the device when it needs to advertise, you cannot use system off lower power mode. You should use system ON, which is used by most of the examples (including the HRM example).

    I have attached a modified main.c (and the diff) from the HRM example in SDK 12 that advertises every 5 seconds. When not advertising or doing anything else, the example goes to system ON low power mode.

    Basically what you should do is:

    • set the advertising interval to 8000 (8000 * 0.625 ms = 5 s)
    • Disable advertising timeout by setting the timeout value to 0
    • set the advertising type to BLE_ADV_MODE_SLOW (this is just an internal concept of the advertising module), and modify the configuration struct () that is passed to ble_advertising_init()accordingly. This just means to change the tree ble_adv_fast_* fields to ble_adv_slow_*.

    Here are all the changes (the diff between the attached main.c and the unmodified main.c in the HRM example):

    diff --git a/examples/ble_peripheral/ble_app_hrs/main.c b/examples/ble_peripheral/ble_app_hrs/main.c
    index cc115a1..b031ac9 100644
    --- a/examples/ble_peripheral/ble_app_hrs/main.c
    +++ b/examples/ble_peripheral/ble_app_hrs/main.c
    @@ -59,8 +59,8 @@
    
     #define DEVICE_NAME                      "Nordic_HRM"                                /**< Name of device. Will be included in the advertising data. */
     #define MANUFACTURER_NAME                "NordicSemiconductor"                       /**< Manufacturer. Will be passed to Device Information Service. */
    -#define APP_ADV_INTERVAL                 300                                         /**< The advertising interval (in units of 0.625 ms. This value corresponds to 187.5 ms). */
    -#define APP_ADV_TIMEOUT_IN_SECONDS       180                                         /**< The advertising timeout in units of seconds. */
    +#define APP_ADV_INTERVAL                 8000                                        /**< The advertising interval (in units of 0.625 ms. This value corresponds to 187.5 ms). */
    +#define APP_ADV_TIMEOUT_IN_SECONDS       0                                           /**< The advertising timeout in units of seconds. */
    
     #define APP_TIMER_PRESCALER              0                                           /**< Value of the RTC1 PRESCALER register. */
     #define APP_TIMER_OP_QUEUE_SIZE          4                                           /**< Size of timer operation queues. */
    @@ -149,7 +149,7 @@ void advertising_start(void)
     {
         ret_code_t err_code;
    
    -    err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
    +    err_code = ble_advertising_start(BLE_ADV_MODE_SLOW);
         APP_ERROR_CHECK(err_code);
     }
    
    @@ -953,9 +953,9 @@ static void advertising_init(void)
         advdata.uuids_complete.p_uuids  = m_adv_uuids;
    
         memset(&options, 0, sizeof(options));
    -    options.ble_adv_fast_enabled  = true;
    -    options.ble_adv_fast_interval = APP_ADV_INTERVAL;
    -    options.ble_adv_fast_timeout  = APP_ADV_TIMEOUT_IN_SECONDS;
    +    options.ble_adv_slow_enabled  = true;
    +    options.ble_adv_slow_interval = APP_ADV_INTERVAL;
    +    options.ble_adv_slow_timeout  = APP_ADV_TIMEOUT_IN_SECONDS;
    
         err_code = ble_advertising_init(&advdata, NULL, &options, on_adv_evt, NULL);
         APP_ERROR_CHECK(err_code);
    
  • Thanks Einar, this is very helpful and it works as planned. I understand your point about keeping the system ON, but would it make sense to call sd_app_event_wait() to save some power?

    Regards,

    Borut

Reply Children
No Data
Related