This commit is contained in:
Proddy
2022-11-29 21:14:31 +01:00
parent c9ef0bcd7b
commit d6a8563cc7
3 changed files with 7 additions and 7 deletions

View File

@@ -83,5 +83,4 @@ void NTPSettingsService::configureTime(AsyncWebServerRequest * request, JsonVari
void NTPSettingsService::ntp_received(struct timeval * tv) {
// emsesp::EMSESP::logger().info("NTP sync to %d sec", tv->tv_sec);
emsesp::EMSESP::system_.ntp_connected(true);
emsesp::EMSESP::system_.send_info_mqtt("connected");
}

View File

@@ -536,17 +536,17 @@ void System::loop() {
}
// send MQTT info topic appended with the version information as JSON, as a retained flag
void System::send_info_mqtt(const char * event_str) {
void System::send_info_mqtt(const char * event_str, bool send_ntp) {
StaticJsonDocument<EMSESP_JSON_SIZE_MEDIUM> doc;
doc["event"] = event_str;
doc["version"] = EMSESP_APP_VERSION;
// if NTP is enabled send the boot_time in local time in ISO 8601 format (eg: 2022-11-15 20:46:38)
// https://github.com/emsesp/EMS-ESP32/issues/751
if (ntp_connected()) {
if (send_ntp) {
char time_string[25];
time_t now = time(nullptr); // grab the current instant in unix seconds
strftime(time_string, 25, "%F %T", localtime(&now));
time_t now = time(nullptr) - uuid::get_uptime_sec();
strftime(time_string, 25, "%FT%T%z", localtime(&now));
doc["boot_time"] = time_string;
}
@@ -1415,6 +1415,7 @@ std::string System::reset_reason(uint8_t cpu) const {
void System::ntp_connected(bool b) {
if (b != ntp_connected_) {
LOG_INFO(b ? "NTP connected" : "NTP disconnected"); // if changed report it
emsesp::EMSESP::system_.send_info_mqtt("connected", true); // send info topic, but only once
}
ntp_connected_ = b;
ntp_last_check_ = b ? uuid::get_uptime_sec() : 0;

View File

@@ -77,7 +77,7 @@ class System {
bool check_upgrade();
bool heartbeat_json(JsonObject & output);
void send_heartbeat();
void send_info_mqtt(const char * event_str);
void send_info_mqtt(const char * event_str, bool send_ntp = false);
bool syslog_enabled() {
return syslog_enabled_;