Getting the uptime
Getting the uptime
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
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
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.
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.
-
- Posts: 151
- Joined: Thu Jun 15, 2017 4:54 am
- Location: New Zealand
Re: Getting the uptime
With a default tick rate of 100 Hz and TickType_t being a uint32_t, wouldn't it overflow every ~497 days?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.
Code: Select all
In [7]: 2**32 / 100 / 60 / 60 / 24.
Out[7]: 497.10269629629624
Re: Getting the uptime
esp_timer_get_time returns 64-bit time since startup, in microseconds.
-
- Posts: 151
- Joined: Thu Jun 15, 2017 4:54 am
- Location: New Zealand
Re: Getting the uptime
Oh, now that IS useful! - now I wish I hadn't just spent the last hour implementing the exact same thingESP_igrr wrote:esp_timer_get_time returns 64-bit time since startup, in microseconds.
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.
-
- Posts: 3
- Joined: Fri Dec 29, 2017 11:32 pm
Re: Getting the uptime
esp_timer_get_time() returns an int64_t so [-2³²,+2³²] is the max.meowsqueak wrote:Oh, now that IS useful! - now I wish I hadn't just spent the last hour implementing the exact same thingESP_igrr wrote:esp_timer_get_time returns 64-bit time since startup, in microseconds.
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.
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?
-
- Posts: 9764
- Joined: Thu Nov 26, 2015 4:08 am
Re: Getting the uptime
Let me correct you there: esp_timer_get_time() returns an int64_t so [-2^63,+2^63-1] is the max.shelladdicted wrote: esp_timer_get_time() returns an int64_t so [-2³²,+2³²] is the max.
-
- Posts: 151
- Joined: Thu Jun 15, 2017 4:54 am
- Location: New Zealand
Re: Getting the uptime
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.shelladdicted wrote: esp_timer_get_time() returns an int64_t so [-2³²,+2³²] is the max.
Re: Getting the uptime
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.
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.