Skip to content

Instantly share code, notes, and snippets.

@kakopappa
Created January 24, 2023 14:12
Show Gist options
  • Save kakopappa/abca7e57dec2319489efeccfc45732df to your computer and use it in GitHub Desktop.
Save kakopappa/abca7e57dec2319489efeccfc45732df to your computer and use it in GitHub Desktop.
ESP32 Uptime example
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