Created
January 24, 2023 14:12
-
-
Save kakopappa/abca7e57dec2319489efeccfc45732df to your computer and use it in GitHub Desktop.
ESP32 Uptime example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void setup() { | |
Serial.begin(115200); | |
} | |
void loop() { | |
char buf[50]; | |
int64_t upTimeUS = esp_timer_get_time(); // in microseconds | |
int64_t seconds = upTimeUS/1000000; | |
uint32_t days = (uint32_t)seconds/86400; | |
uint32_t hr=(uint32_t)seconds % 86400 / 3600; | |
uint32_t min=(uint32_t)seconds % 3600 / 60; | |
uint32_t sec=(uint32_t)seconds % 60; | |
snprintf (buf,sizeof(buf),"%dd %d:%02d:%02d", days, hr, min, sec); | |
String upTime = String(buf); | |
Serial.println(upTime); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment