mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 06:32:19 +03:00
не рабочая версия - ввод даты в процессе
This commit is contained in:
@@ -22,7 +22,7 @@ void* getAPI_ButtonOut(String subtype, String params);
|
||||
void* getAPI_IoTServo(String subtype, String params);
|
||||
void* getAPI_Mcp23017(String subtype, String params);
|
||||
void* getAPI_Mp3(String subtype, String params);
|
||||
void* getAPI_Pwm32(String subtype, String params);
|
||||
void* getAPI_Pwm8266(String subtype, String params);
|
||||
void* getAPI_TelegramLT(String subtype, String params);
|
||||
void* getAPI_Lcd2004(String subtype, String params);
|
||||
|
||||
@@ -50,7 +50,7 @@ if ((tmpAPI = getAPI_ButtonOut(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_IoTServo(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Mcp23017(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Mp3(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Pwm32(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Pwm8266(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_TelegramLT(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Lcd2004(subtype, params)) != nullptr) return tmpAPI;
|
||||
return nullptr;
|
||||
|
||||
@@ -1,18 +1,25 @@
|
||||
#include "Global.h"
|
||||
#include "classes/IoTItem.h"
|
||||
#include "ESPConfiguration.h"
|
||||
#include "NTP.h"
|
||||
|
||||
void *getAPI_Date(String params);
|
||||
|
||||
String date;
|
||||
class Loging : public IoTItem {
|
||||
private:
|
||||
String logid;
|
||||
String id;
|
||||
String filesList = "";
|
||||
|
||||
bool firstTime = true;
|
||||
|
||||
int points;
|
||||
int keepdays;
|
||||
|
||||
IoTItem *dateIoTItem;
|
||||
|
||||
unsigned long interval;
|
||||
bool firstTime = true;
|
||||
|
||||
public:
|
||||
Loging(String parameters) : IoTItem(parameters) {
|
||||
@@ -26,6 +33,10 @@ class Loging : public IoTItem {
|
||||
jsonRead(parameters, F("int"), interval);
|
||||
interval = interval * 1000 * 60; //приводим к милисекундам
|
||||
jsonRead(parameters, F("keepdays"), keepdays);
|
||||
|
||||
//создадим экземпляр класса даты
|
||||
dateIoTItem = (IoTItem *)getAPI_Date("{\"id\": \"" + id + "-date\"}");
|
||||
IoTItems.push_back(dateIoTItem);
|
||||
}
|
||||
|
||||
String getValue() {
|
||||
@@ -46,13 +57,21 @@ class Loging : public IoTItem {
|
||||
void regEvent(String value, String consoleInfo = "") {
|
||||
generateEvent(_id, value);
|
||||
publishStatusMqtt(_id, value);
|
||||
String topic = mqttRootDevice + "/" + _id;
|
||||
String json = "{\"topic\":\"" + topic + "\",\"status\":[{\"x\":" + String(unixTime) + ",\"y1\":" + value + "}]}";
|
||||
String json = createSingleJson(_id, value);
|
||||
publishStatusWsJson(json);
|
||||
SerialPrint("i", "Sensor " + consoleInfo, "'" + _id + "' data: " + value + "'");
|
||||
}
|
||||
|
||||
String createSingleJson(String id, String value) {
|
||||
String topic = mqttRootDevice + "/" + _id;
|
||||
return "{\"topic\":\"" + topic + "\",\"status\":[{\"x\":" + String(unixTime) + ",\"y1\":" + value + "}]}";
|
||||
}
|
||||
|
||||
void doByInterval() {
|
||||
if (firstTime) {
|
||||
firstTime = false;
|
||||
}
|
||||
|
||||
//если объект логгирования не был создан
|
||||
if (!isItemExist(logid)) {
|
||||
SerialPrint("E", F("Loging"), "'" + id + "' loging object not exist");
|
||||
@@ -169,7 +188,13 @@ class Loging : public IoTItem {
|
||||
SerialPrint("i", F("Loging"), "file '" + buf + "' too old, deleted");
|
||||
removeFile(buf);
|
||||
} else {
|
||||
createJson(buf, i, mqtt);
|
||||
unsigned long reqUnixTime = strDateToUnix(date);
|
||||
if (fileUnixTime > reqUnixTime && fileUnixTime < reqUnixTime + 86400) {
|
||||
createJson(buf, i, mqtt);
|
||||
SerialPrint("i", F("Loging"), "file '" + buf + "' sent, user requested " + date);
|
||||
} else {
|
||||
SerialPrint("i", F("Loging"), "file '" + buf + "' skipped, user requested " + date);
|
||||
}
|
||||
}
|
||||
|
||||
SerialPrint("i", F("Loging"), String(f) + ") path: " + buf + ", lines №: " + String(i) + ", created: " + getDateTimeDotFormatedFromUnix(fileUnixTime));
|
||||
@@ -304,3 +329,35 @@ void *getAPI_Loging(String subtype, String param) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
class Date : public IoTItem {
|
||||
private:
|
||||
public:
|
||||
String id;
|
||||
Date(String parameters) : IoTItem(parameters) {
|
||||
jsonRead(parameters, F("id"), id);
|
||||
value.isDecimal = false;
|
||||
}
|
||||
|
||||
void setValue(String valStr) {
|
||||
value.valS = valStr;
|
||||
date = valStr;
|
||||
setValue(value);
|
||||
}
|
||||
|
||||
void setValue(IoTValue Value) {
|
||||
value = Value;
|
||||
regEvent(value.valS, "");
|
||||
for (std::list<IoTItem *>::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) {
|
||||
if ((*it)->getSubtype() == "Loging") {
|
||||
(*it)->sendChart(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void doByInterval() {}
|
||||
};
|
||||
|
||||
void *getAPI_Date(String param) {
|
||||
return new Date(param);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
"type": "Writing",
|
||||
"subtype": "Loging",
|
||||
"id": "log",
|
||||
"widget": "chart1",
|
||||
"widget": "chart2",
|
||||
"page": "Графики",
|
||||
"descr": "Температура",
|
||||
"int": 1,
|
||||
|
||||
Reference in New Issue
Block a user