Particle Tracker wakes up in about a minute after going to sleep

The code is as follows:

void loop()

{
    Tracker::instance().loop();
    bluetooth_loop();
    PublishQueuePosix::instance().loop();
    if (countdown_before_going_to_sleep < 0){
        Log.info("==============GOING TO SLEEP==============!");
        countdown_before_going_to_sleep = time_out_before_going_to_sleep;
        SystemSleepConfiguration config;
        if (number_of_successful_connections)
            config.mode(SystemSleepMode::HIBERNATE)
                  .duration(3600000);
        else
            config.mode(SystemSleepMode::HIBERNATE)
                  .duration(1200000);
        System.sleep(config);
    }
}

In about a minute the device is promptly awake. The cloud asset tracker settings are all disabled on the sleep and location side (0, 0 for both max and min publishing).

We are just simply looking for the device to comply with the instructions and go to sleep for a specified time triggered by the code without any speculations on whether it is a good idea to go to sleep.

Does this problem also occur when using ULTRA_LOW_POWER?

The reason I ask is that in ULP mode, wake is controlled by the nRF52840 MCU. In hibernate mode, it’s woken by the AM1805 RTC, so this could help narrow down the possibilities.

Both.

I think that’s happening because the Device OS sleep API does not disable the Tracker AM1805 watchdog timer, which is firing and resetting the device. You can either use the Tracker sleep API instead of the Device OS sleep API, or manually disable the watchdog before sleep.

1 Like

Solved. The code below uses Tracker Edge Firmware and actually does what the thread question asks:

int time_out_before_going_to_sleep = 300;

void prepareSleepCallback(TrackerSleepContext context)
{
    Log.info("==============GOING TO SLEEP==============!");
    countdown_before_going_to_sleep = time_out_before_going_to_sleep;
    if (number_of_successful_connections){
        Log.trace("Tracker will be awake in %lu miliseconds", (uint64_t)(first_wake * 10 * EARLY_WAKE_MARGIN));
        Log.trace("Wake update returned error #%d", TrackerSleep::instance().wakeAtMilliseconds(System.millis() + (uint64_t)(first_wake * 10 * EARLY_WAKE_MARGIN)));
    }    
    else{
        Log.trace("Tracker will be awake in %lu miliseconds", (uint64_t)(3600000));
        Log.trace("Wake update returned error #%d", TrackerSleep::instance().wakeAtMilliseconds(System.millis() + (uint64_t)(1200000)));
    }
}

void pause_sleep_callback(TrackerSleepContext context){
    TrackerSleep::instance().pauseSleep();
    Log.info("================================Waking up!==================================");
    number_of_successful_connections = 0;
    countdown_before_going_to_sleep = time_out_before_going_to_sleep;
}

void setup(){
    /* Other important stuff setting up */
    countdown_before_going_to_sleep = time_out_before_going_to_sleep;
    number_of_successful_connections = 0;
    TrackerSleep::instance().pauseSleep();
    TrackerSleep::instance().registerWake(pause_sleep_callback);
    TrackerSleep::instance().registerSleepPrepare(prepareSleepCallback);
}

void loop()
{
    Tracker::instance().loop();
    bluetooth_loop();
    PublishQueuePosix::instance().loop();
    if (countdown_before_going_to_sleep < 0){
        TrackerSleep::instance().resumeSleep();
    }
}

countdown_before_going_to_sleep may be decremented at leisure. The sleep option must be enabled in the cloud settings.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.