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 {
|
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() {
|
uint64_t get_uptime_ms() {
|
||||||
static uint32_t high_millis = 0;
|
static uint32_t high_millis = 0;
|
||||||
static uint32_t low_millis = 0;
|
static uint32_t low_millis = 0;
|
||||||
@@ -36,8 +52,7 @@ uint64_t get_uptime_ms() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// added by proddy
|
// added by proddy
|
||||||
|
static uint32_t now_millis;
|
||||||
static uint32_t now_millis; // added by proddy
|
|
||||||
|
|
||||||
void set_uptime() {
|
void set_uptime() {
|
||||||
now_millis = ::millis();
|
now_millis = ::millis();
|
||||||
|
|||||||
@@ -87,6 +87,8 @@ void loop();
|
|||||||
uint64_t get_uptime_ms();
|
uint64_t get_uptime_ms();
|
||||||
|
|
||||||
uint32_t get_uptime(); // added by proddy
|
uint32_t get_uptime(); // added by proddy
|
||||||
|
uint32_t get_uptime_sec(); // added by proddy
|
||||||
|
|
||||||
void set_uptime();
|
void set_uptime();
|
||||||
|
|
||||||
} // namespace uuid
|
} // namespace uuid
|
||||||
|
|||||||
@@ -450,10 +450,11 @@ void Mqtt::send_heartbeat() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
StaticJsonDocument<90> doc;
|
StaticJsonDocument<EMSESP_MAX_JSON_SIZE_SMALL> doc;
|
||||||
|
|
||||||
doc["rssid"] = Network::wifi_quality();
|
doc["rssid"] = Network::wifi_quality();
|
||||||
doc["uptime"] = uuid::log::format_timestamp_ms(uuid::get_uptime_ms(), 3);
|
doc["uptime"] = uuid::log::format_timestamp_ms(uuid::get_uptime_ms(), 3);
|
||||||
|
doc["uptime_sec"] = uuid::get_uptime_sec();
|
||||||
doc["freemem"] = System::free_mem();
|
doc["freemem"] = System::free_mem();
|
||||||
doc["mqttpublishfails"] = mqtt_publish_fails_;
|
doc["mqttpublishfails"] = mqtt_publish_fails_;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user