Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uptime fold over #631

Open
Jean-LG opened this issue Dec 7, 2024 · 1 comment
Open

Uptime fold over #631

Jean-LG opened this issue Dec 7, 2024 · 1 comment

Comments

@Jean-LG
Copy link

Jean-LG commented Dec 7, 2024

the uptime counter is coded with an uint32. the uptime is in milliseconds therefore after 49 days (2^32 milliseconds), uptime folds over. Moreover some coversions in the code from uint32 to long give negative values. for uptime after 49/2=25.5 days (2^31 ms)

Some possible solution for ESP32 arch:

In AutoConnectPageImpl.hpp line 1009
#elif defined(ARDUINO_ARCH_ESP32)
long millisecs = esp_timer_get_time() / 1000;

esp_timer_get_time() returns an int64_t (see https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/esp_timer.html#_CPPv418esp_timer_get_timev)

It would be then usefull to convert either to seconds instead of keeping milliseconds in an uint32 variable, or use int64_t all the way long. Not sure if the arduino compiler handles properly uint64

JL

@Jean-LG
Copy link
Author

Jean-LG commented Dec 8, 2024

modified AutoConnectPageImpl.hpp this way, under tests for the next 25 days...

template
String AutoConnectCore::_getSystemUptime() {
#if defined(ARDUINO_ARCH_ESP8266)
unsigned long secs = millis()/1000;
#elif defined(ARDUINO_ARCH_ESP32)
long secs = esp_timer_get_time() / 1000000;
#endif
int systemUpTimeM = static_cast((secs / ( 60)) % 60);
int systemUpTimeH = static_cast((secs / ( 60 * 60)) % 24);
int systemUpTimeD = static_cast(secs / ( 60 * 60 * 24));
String uptime = String(systemUpTimeM) + "m ";
if (systemUpTimeH > 0)
uptime += String(systemUpTimeH) + "h ";
if (systemUpTimeD > 0)
uptime += String(systemUpTimeD) + "d ";
return uptime;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant