mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
add uptime in seconds to heartbeat MQTT payload
This commit is contained in:
@@ -22,6 +22,22 @@
|
||||
|
||||
namespace uuid {
|
||||
|
||||
#define UPTIME_OVERFLOW 4294967295 // Uptime overflow value
|
||||
|
||||
// returns system uptime in seconds
|
||||
uint32_t get_uptime_sec() {
|
||||
static uint32_t last_uptime = 0;
|
||||
static uint8_t uptime_overflows = 0;
|
||||
|
||||
if (millis() < last_uptime) {
|
||||
++uptime_overflows;
|
||||
}
|
||||
last_uptime = millis();
|
||||
uint32_t uptime_seconds = uptime_overflows * (UPTIME_OVERFLOW / 1000) + (last_uptime / 1000);
|
||||
|
||||
return uptime_seconds;
|
||||
}
|
||||
|
||||
uint64_t get_uptime_ms() {
|
||||
static uint32_t high_millis = 0;
|
||||
static uint32_t low_millis = 0;
|
||||
@@ -36,8 +52,7 @@ uint64_t get_uptime_ms() {
|
||||
}
|
||||
|
||||
// added by proddy
|
||||
|
||||
static uint32_t now_millis; // added by proddy
|
||||
static uint32_t now_millis;
|
||||
|
||||
void set_uptime() {
|
||||
now_millis = ::millis();
|
||||
|
||||
@@ -86,8 +86,10 @@ void loop();
|
||||
*/
|
||||
uint64_t get_uptime_ms();
|
||||
|
||||
uint32_t get_uptime(); // added by proddy
|
||||
void set_uptime();
|
||||
uint32_t get_uptime(); // added by proddy
|
||||
uint32_t get_uptime_sec(); // added by proddy
|
||||
|
||||
void set_uptime();
|
||||
|
||||
} // namespace uuid
|
||||
|
||||
|
||||
Reference in New Issue
Block a user