Question about System.uptime()

Is System.uptime() affected by sleep (STOP, ULP, HIBERNATE etc.)? Does it require that the RTC have the correct “true” time? I know that millis does not tick in sleep modes, and the RTC (I’m using Borons and Electrons on 2.3.0 LTS) won’t have the correct time until the first time the Particle device connects to cloud and do a clock sync.

The doc doesn’t say much about System.uptime(). I suppose I can set up minimal programs to test these, but it’d be better if these behaviors are guaranteed by the doc so I can depend on them when upgrading DeviceOS.

Uptime is literally System.millis() divided by 1000:

    static uint64_t millis() {
        return hal_timer_millis(nullptr);

    static unsigned uptime() {
        return (hal_timer_millis(nullptr) / 1000);
  • It does not require a valid RTC time to work
  • System.millis() behaves the same as millis() with regards to when it’s incremented, but the result is a uint64_t so it does not roll over to 0 after 49 days.

So if millis does not increment in sleep modes (accord to this post), that means neither System.millis nor System.uptime can keep track of time during sleep. So my only option of keeping track of time elapsed in sleep would be comparing before and after sleep. The difference between the two calls should give me the time elapsed during sleep, assuming I don’t connect to cloud and do a clock sync in between, am I correct?

Yes, this is correct for Gen 2 (Photon, P1, Electron, E Series).

On Gen 3 devices (Argon, Boron, B Series SoM, and Tracker), the millis() counter does increment during sleep.

The reason is that on STM32, millis is implemented via the 1 millisecond MCU tick interrupt, not the RTC peripheral on the STM32.

On nRF52, there isn’t a dedicated RTC peripheral on-chip, it uses a real-time counter that does get incremented in sleep mode. This is used for both RTC and for millis().

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