add uptime in seconds to heartbeat MQTT payload

This commit is contained in:
proddy
2020-06-26 13:02:20 +02:00
parent f9233076bf
commit 4bea741958
3 changed files with 23 additions and 5 deletions

View File

@@ -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();

View File

@@ -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