mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
fixes for #751
This commit is contained in:
@@ -83,5 +83,4 @@ void NTPSettingsService::configureTime(AsyncWebServerRequest * request, JsonVari
|
|||||||
void NTPSettingsService::ntp_received(struct timeval * tv) {
|
void NTPSettingsService::ntp_received(struct timeval * tv) {
|
||||||
// emsesp::EMSESP::logger().info("NTP sync to %d sec", tv->tv_sec);
|
// emsesp::EMSESP::logger().info("NTP sync to %d sec", tv->tv_sec);
|
||||||
emsesp::EMSESP::system_.ntp_connected(true);
|
emsesp::EMSESP::system_.ntp_connected(true);
|
||||||
emsesp::EMSESP::system_.send_info_mqtt("connected");
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -536,17 +536,17 @@ void System::loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// send MQTT info topic appended with the version information as JSON, as a retained flag
|
// 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;
|
StaticJsonDocument<EMSESP_JSON_SIZE_MEDIUM> doc;
|
||||||
doc["event"] = event_str;
|
doc["event"] = event_str;
|
||||||
doc["version"] = EMSESP_APP_VERSION;
|
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)
|
// 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
|
// https://github.com/emsesp/EMS-ESP32/issues/751
|
||||||
if (ntp_connected()) {
|
if (send_ntp) {
|
||||||
char time_string[25];
|
char time_string[25];
|
||||||
time_t now = time(nullptr); // grab the current instant in unix seconds
|
time_t now = time(nullptr) - uuid::get_uptime_sec();
|
||||||
strftime(time_string, 25, "%F %T", localtime(&now));
|
strftime(time_string, 25, "%FT%T%z", localtime(&now));
|
||||||
doc["boot_time"] = time_string;
|
doc["boot_time"] = time_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1414,7 +1414,8 @@ std::string System::reset_reason(uint8_t cpu) const {
|
|||||||
// set NTP status
|
// set NTP status
|
||||||
void System::ntp_connected(bool b) {
|
void System::ntp_connected(bool b) {
|
||||||
if (b != ntp_connected_) {
|
if (b != ntp_connected_) {
|
||||||
LOG_INFO(b ? "NTP connected" : "NTP disconnected"); // if changed report it
|
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_connected_ = b;
|
||||||
ntp_last_check_ = b ? uuid::get_uptime_sec() : 0;
|
ntp_last_check_ = b ? uuid::get_uptime_sec() : 0;
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ class System {
|
|||||||
bool check_upgrade();
|
bool check_upgrade();
|
||||||
bool heartbeat_json(JsonObject & output);
|
bool heartbeat_json(JsonObject & output);
|
||||||
void send_heartbeat();
|
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() {
|
bool syslog_enabled() {
|
||||||
return syslog_enabled_;
|
return syslog_enabled_;
|
||||||
|
|||||||
Reference in New Issue
Block a user