From 89b95a75ebc5f8336f09261621ce836ea24041de Mon Sep 17 00:00:00 2001 From: Dmitry Borisenko <67171972+IoTManagerProject@users.noreply.github.com> Date: Sun, 4 Dec 2022 21:13:59 +0100 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D1=81=D0=BC=D0=B5=D0=BD=D1=83=20=D0=B4=D0=B0=D1=82=D1=8B=20?= =?UTF-8?q?=D0=B2=D0=BE=20=D0=B2=D1=81=D0=B5=D1=85=20=D0=B3=D1=80=D0=B0?= =?UTF-8?q?=D1=84=D0=B8=D0=BA=D0=B0=D1=85=20=D0=BF=D1=80=D0=B8=20=D1=81?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D0=B5=20=D0=B4=D0=B0=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/Global.h | 2 ++ include/NTP.h | 1 + src/Global.cpp | 2 ++ src/NTP.cpp | 20 +++++++++++++++++++ src/modules/virtual/Loging/Loging.cpp | 10 ++++------ .../virtual/LogingDaily/LogingDaily.cpp | 6 +++--- 6 files changed, 32 insertions(+), 9 deletions(-) diff --git a/include/Global.h b/include/Global.h index a777ce5e..ea549411 100644 --- a/include/Global.h +++ b/include/Global.h @@ -134,6 +134,8 @@ struct Time_t { extern unsigned long unixTime; extern unsigned long unixTimeShort; +extern String prevDate; +extern bool firstTimeInit; extern bool isTimeSynch; extern Time_t _time_local; diff --git a/include/NTP.h b/include/NTP.h index dac739df..61a8c754 100644 --- a/include/NTP.h +++ b/include/NTP.h @@ -8,6 +8,7 @@ extern void breakEpochToTime(unsigned long epoch, Time_t& tm); extern void ntpInit(); extern time_t getSystemTime(); extern void synchTime(); +extern bool onDayChange(); extern const String getTimeLocal_hhmm(); extern const String getTimeLocal_hhmmss(); extern const String getDateTimeDotFormated(); diff --git a/src/Global.cpp b/src/Global.cpp index 6bf64d6f..c4364e13 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -70,6 +70,8 @@ String mqttRootDevice = ""; // Time unsigned long unixTime = 0; unsigned long unixTimeShort = 0; +String prevDate = ""; +bool firstTimeInit = true; // unsigned long loopPeriod; diff --git a/src/NTP.cpp b/src/NTP.cpp index e2f83178..112050fa 100644 --- a/src/NTP.cpp +++ b/src/NTP.cpp @@ -29,6 +29,7 @@ void ntpInit() { dateAndTime = deleteToMarkerLast(dateAndTime, ":"); jsonWriteStr_(errorsHeapJson, F("timenow"), dateAndTime); SerialPrint("I", F("NTP"), "✔ " + dateAndTime); + onDayChange(); } _time_isTrust = true; // доверяем значению времени }, @@ -41,6 +42,25 @@ void synchTime() { configTime(0, 0, "pool.ntp.org", "ru.pool.ntp.org", "pool.ntp.org"); } +//событие смены даты +bool onDayChange() { + bool changed = false; + String currentDate = getTodayDateDotFormated(); + if (!firstTimeInit) { + if (prevDate != currentDate) { + changed = true; + SerialPrint("i", F("NTP"), F("Change day core event")); + //установим новую дату во всех графиках системы + for (std::list::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) { + (*it)->setTodayDate(); + } + } + } + firstTimeInit = false; + prevDate = currentDate; + return changed; +} + unsigned long gmtTimeToLocal(unsigned long gmtTimestamp) { return gmtTimestamp + (jsonReadInt(settingsFlashJson, F("timezone")) * 60 * 60); } diff --git a/src/modules/virtual/Loging/Loging.cpp b/src/modules/virtual/Loging/Loging.cpp index 8ad54de6..9df1aaa4 100644 --- a/src/modules/virtual/Loging/Loging.cpp +++ b/src/modules/virtual/Loging/Loging.cpp @@ -21,7 +21,7 @@ class Loging : public IoTItem { IoTItem *dateIoTItem; String prevDate = ""; - bool firstTimeDate = true; + bool firstTimeInit = true; long interval; @@ -188,12 +188,10 @@ class Loging : public IoTItem { bool hasDayChanged() { bool changed = false; String currentDate = getTodayDateDotFormated(); - if (!firstTimeDate) { + if (!firstTimeInit) { if (prevDate != currentDate) { changed = true; - SerialPrint("i", F("NTP"), "Change day event"); - //установим дату на изменившуюся при смене суток - dateIoTItem->setTodayDate(); + SerialPrint("i", F("NTP"), F("Change day event")); #if defined(ESP8266) FileFS.gc(); #endif @@ -201,7 +199,7 @@ class Loging : public IoTItem { #endif } } - firstTimeDate = false; + firstTimeInit = false; prevDate = currentDate; return changed; } diff --git a/src/modules/virtual/LogingDaily/LogingDaily.cpp b/src/modules/virtual/LogingDaily/LogingDaily.cpp index 50ed724f..ee849651 100644 --- a/src/modules/virtual/LogingDaily/LogingDaily.cpp +++ b/src/modules/virtual/LogingDaily/LogingDaily.cpp @@ -19,7 +19,7 @@ class LogingDaily : public IoTItem { IoTItem *dateIoTItem; String prevDate = ""; - bool firstTimeDate = true; + bool firstTimeInit = true; long interval; @@ -138,7 +138,7 @@ class LogingDaily : public IoTItem { bool hasDayChanged() { bool changed = false; String currentDate = getTodayDateDotFormated(); - if (!firstTimeDate) { + if (!firstTimeInit) { if (prevDate != currentDate) { changed = true; SerialPrint("i", F("NTP"), "Change day event"); @@ -149,7 +149,7 @@ class LogingDaily : public IoTItem { #endif } } - firstTimeDate = false; + firstTimeInit = false; prevDate = currentDate; return changed; }