diff --git a/data/items/items.txt b/data/items/items.txt index 3b9d7ca4..52db5c4d 100644 --- a/data/items/items.txt +++ b/data/items/items.txt @@ -22,4 +22,4 @@ 0;count-down;cntid;anydata;Таймер;Обратный#отчет;order* 0;inoutput;txtid;anydata;Вывод;Вывод#uart;order* 0;logging;crtid;chart;Графики;История;order;val[any];int[60];cnt[100]* -0;uptime;uptid;anydataTime;Системные;%name%#uptime;order* \ No newline at end of file +0;uptime;uptid;anydataTime;Системные;%name%#uptime;order;int[60]* \ No newline at end of file diff --git a/include/items/sysUptime.h b/include/items/sysUptime.h deleted file mode 100644 index 9e9b3f7c..00000000 --- a/include/items/sysUptime.h +++ /dev/null @@ -1,5 +0,0 @@ - -#pragma once - -extern void sysUptime(); -extern void uptimeReading(); \ No newline at end of file diff --git a/include/items/vSensorUptime.h b/include/items/vSensorUptime.h new file mode 100644 index 00000000..ff8df7eb --- /dev/null +++ b/include/items/vSensorUptime.h @@ -0,0 +1,33 @@ +#pragma once +#include + +#include "Global.h" +#include "GyverFilters.h" + +class SensorUptime; + +typedef std::vector MySensorUptimeVector; + +struct paramsUptime { + String key; + unsigned long interval; +}; + +class SensorUptime { + public: + SensorUptime(const paramsUptime& paramsUpt); + ~SensorUptime(); + + void loop(); + void read(); + + private: + paramsUptime _paramsUpt; + + unsigned long prevMillis; + unsigned long difference; +}; + +extern MySensorUptimeVector* mySensorUptime; + +extern void uptimeSensor(); \ No newline at end of file diff --git a/src/BufferExecute.cpp b/src/BufferExecute.cpp index 0f5c487d..2d079244 100644 --- a/src/BufferExecute.cpp +++ b/src/BufferExecute.cpp @@ -2,7 +2,7 @@ #include "Global.h" #include "SoftUART.h" // -#include "items/sysUptime.h" +#include "items/vSensorUptime.h" #include "items/vSensorDallas.h" #include "items/vSensorUltrasonic.h" #include "items/vButtonOut.h" @@ -92,7 +92,7 @@ void csvCmdExecute(String& cmdStr) { } #endif else if (order == F("uptime")) { - sCmd.addCommand(order.c_str(), sysUptime); + sCmd.addCommand(order.c_str(), uptimeSensor); } else if (order == F("logging")) { sCmd.addCommand(order.c_str(), logging); diff --git a/src/Utils/WiFiUtils.cpp b/src/Utils/WiFiUtils.cpp index d69c1a59..dfebd244 100644 --- a/src/Utils/WiFiUtils.cpp +++ b/src/Utils/WiFiUtils.cpp @@ -1,5 +1,4 @@ #include "Utils/WiFiUtils.h" -#include "items/sysUptime.h" #include "FileSystem.h" void routerConnect() { @@ -141,7 +140,6 @@ uint8_t RSSIquality() { void wifiSignalInit() { ts.add( SYGNAL, 1000 * 60, [&](void*) { - //uptimeReading(); SerialPrint("I", "System", printMemoryStatus()); #ifdef ESP8266 getFSInfo(); diff --git a/src/items/sysUptime.cpp b/src/items/sysUptime.cpp deleted file mode 100644 index b20029d9..00000000 --- a/src/items/sysUptime.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "items/sysUptime.h" -#include "Class/LineParsing.h" -#include "BufferExecute.h" -#include "Global.h" -#include - -void sysUptime() { - myLineParsing.update(); - String key = myLineParsing.gkey(); - sCmd.addCommand(key.c_str(), uptimeReading); - myLineParsing.clear(); -} - -void uptimeReading() { - String key = sCmd.order(); - String uptime = timeNow->getUptime(); - jsonWriteStr(configLiveJson, key, uptime); - publishStatus(key, uptime); - SerialPrint("I", "Sensor", "'" + key + "' data: " + uptime); -} \ No newline at end of file diff --git a/src/items/vSensorUptime.cpp b/src/items/vSensorUptime.cpp new file mode 100644 index 00000000..595e76ce --- /dev/null +++ b/src/items/vSensorUptime.cpp @@ -0,0 +1,49 @@ +#include "items/vSensorUptime.h" + +#include + +#include "BufferExecute.h" +#include "Class/LineParsing.h" +#include "Global.h" + +SensorUptime::SensorUptime(const paramsUptime& paramsUpt) { + _paramsUpt = paramsUptime(paramsUpt); +} + +SensorUptime::~SensorUptime() {} + +void SensorUptime::loop() { + difference = millis() - prevMillis; + if (difference >= _paramsUpt.interval) { + prevMillis = millis(); + read(); + } +} + +void SensorUptime::read() { + String upt = timeNow->getUptime(); + + eventGen2(_paramsUpt.key, upt); + jsonWriteStr(configLiveJson, _paramsUpt.key, upt); + publishStatus(_paramsUpt.key, upt); + SerialPrint("I", "Sensor", "'" + _paramsUpt.key + "' data: " + upt); +} + +MySensorUptimeVector* mySensorUptime = nullptr; + +void uptimeSensor() { + myLineParsing.update(); + String key = myLineParsing.gkey(); + String interval = myLineParsing.gint(); + myLineParsing.clear(); + + static paramsUptime paramsUpt; + + paramsUpt.key = key; + paramsUpt.interval = interval.toInt() * 1000; + + static bool firstTime = true; + if (firstTime) mySensorUptime = new MySensorUptimeVector(); + firstTime = false; + mySensorUptime->push_back(SensorUptime(paramsUpt)); +} diff --git a/src/main.cpp b/src/main.cpp index bd065a05..df2f4462 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,6 +19,7 @@ #include "Utils/Timings.h" #include "Utils/WebUtils.h" #include "items/ButtonInClass.h" +#include "items/vSensorUptime.h" #include "items/vCountDown.h" #include "items/vImpulsOut.h" #include "items/vLogging.h" @@ -153,4 +154,9 @@ void loop() { mySensorBmp280->at(i).loop(); } } + if (mySensorUptime != nullptr) { + for (unsigned int i = 0; i < mySensorUptime->size(); i++) { + mySensorUptime->at(i).loop(); + } + } } \ No newline at end of file