add NTP status to mqtt/ha (heartbeat) and log

This commit is contained in:
MichaelDvP
2022-03-29 18:40:32 +02:00
parent d269029bb1
commit 07b438f6f0
3 changed files with 26 additions and 5 deletions

View File

@@ -154,14 +154,13 @@ class System {
ethernet_connected_ = b;
}
void ntp_connected(bool b) {
ntp_connected_ = b;
ntp_last_check_ = b ? uuid::get_uptime_sec() : 0;
}
void ntp_connected(bool b);
bool ntp_connected() {
// timeout 2 hours, ntp sync is normally every hour.
ntp_connected_ = (uuid::get_uptime_sec() - ntp_last_check_ > 7201) ? false : ntp_connected_;
if ((uuid::get_uptime_sec() - ntp_last_check_ > 7201) && ntp_connected_) {
ntp_connected(false);
}
return ntp_connected_;
}