Page 1 of 1

Getting the uptime

Posted: Thu Mar 16, 2017 8:39 pm
by StefanRvO
Hi
Is it possible to find the time since last boot?
I know that it is possible to use gettimeofday() in some cases, but this (obviously) does not work if sntp is enabled. Is there any other way to find the uptime?

Regards
Stefan

Re: Getting the uptime

Posted: Thu Mar 16, 2017 8:55 pm
by Hans Dorn
Hi

xTaskGetTickCount will probably do the trick.

P.S: The tickcount will wrap every 49 days I guess. You'll have to check it periodically and adjust your uptime calculation.

Re: Getting the uptime

Posted: Wed Mar 14, 2018 5:08 am
by meowsqueak
Hans Dorn wrote:xTaskGetTickCount will probably do the trick.

P.S: The tickcount will wrap every 49 days I guess. You'll have to check it periodically and adjust your uptime calculation.
With a default tick rate of 100 Hz and TickType_t being a uint32_t, wouldn't it overflow every ~497 days?

Code: Select all

In [7]: 2**32 / 100 / 60 / 60 / 24.
Out[7]: 497.10269629629624

Re: Getting the uptime

Posted: Wed Mar 14, 2018 5:50 am
by ESP_igrr
esp_timer_get_time returns 64-bit time since startup, in microseconds.

Re: Getting the uptime

Posted: Wed Mar 14, 2018 6:25 am
by meowsqueak
ESP_igrr wrote:esp_timer_get_time returns 64-bit time since startup, in microseconds.
Oh, now that IS useful! - now I wish I hadn't just spent the last hour implementing the exact same thing :)

By my calculations that should last for about 584,000 years before overflow. Should be sufficient for most IoT applications.

EDIT: oh, it's signed, so I guess that's only 292,000 years then. Pity.

Re: Getting the uptime

Posted: Fri Jun 08, 2018 4:21 pm
by shelladdicted
meowsqueak wrote:
ESP_igrr wrote:esp_timer_get_time returns 64-bit time since startup, in microseconds.
Oh, now that IS useful! - now I wish I hadn't just spent the last hour implementing the exact same thing :)

By my calculations that should last for about 584,000 years before overflow. Should be sufficient for most IoT applications.

EDIT: oh, it's signed, so I guess that's only 292,000 years then. Pity.
esp_timer_get_time() returns an int64_t so [-2³²,+2³²] is the max.
in a day there are 8.64*10^10 uS and is bigger than 2³² so esp_timer_get_time() will overflow in less than one day
how can i handle more than one day?

Re: Getting the uptime

Posted: Sat Jun 09, 2018 4:52 am
by ESP_Sprite
shelladdicted wrote: esp_timer_get_time() returns an int64_t so [-2³²,+2³²] is the max.
Let me correct you there: esp_timer_get_time() returns an int64_t so [-2^63,+2^63-1] is the max.

Re: Getting the uptime

Posted: Sat Jun 09, 2018 7:24 am
by meowsqueak
shelladdicted wrote: esp_timer_get_time() returns an int64_t so [-2³²,+2³²] is the max.
As ESP_Sprite said, you've got your math wrong. It will overflow after 292,000 years. Should be long enough for most IoT apps and even some enterprise applications.

Re: Getting the uptime

Posted: Wed Nov 14, 2018 9:04 am
by HermannSW
Interesting. I looked into ESP32 (and ESP8266) overflow for MicroPython utime module ticks_ms() and ticks_us() functions:
https://forum.micropython.org/viewtopic ... 855#p31855

Both do return uint32_t, so overflow after 71 minutes / 49 days.
Interestingly ESP8266 MicroPython implements high 32bit of 64bit counter and allows for same overflows, although ESP8266 system_get_time() returns uint32_t only.

Re: Getting the uptime

Posted: Mon Nov 19, 2018 7:35 pm
by Ritesh
ESP_igrr wrote:
Wed Mar 14, 2018 5:50 am
esp_timer_get_time returns 64-bit time since startup, in microseconds.
From which ESP32 IDF, It has been supported?