не рабочая версия - ввод даты в процессе

This commit is contained in:
Dmitry Borisenko
2022-09-10 02:58:42 +02:00
parent fff7c976a9
commit 8340ae2a0f
11 changed files with 87 additions and 21 deletions

View File

@@ -455,18 +455,16 @@
"num": 34
},
{
"name": "35. PWM ESP32",
"name": "35. PWM ESP8266",
"type": "Writing",
"subtype": "Pwm32",
"subtype": "Pwm8266",
"id": "pwm",
"widget": "range",
"page": "Кнопки",
"descr": "PWM",
"int": 0,
"pin": 2,
"pin": 15,
"freq": 5000,
"ledChannel": 2,
"PWM_resolution": 10,
"val": 0,
"apin": -1,
"num": 35

View File

@@ -194,5 +194,8 @@
"widget": "anydata",
"after": "Vlt",
"icon": "speedometer"
},
{
"label": "Без виджета"
}
]

View File

@@ -21,7 +21,7 @@
},
"projectProp": {
"platformio": {
"default_envs": "esp32_4mb",
"default_envs": "esp8266_4mb",
"data_dir": "data_svelte"
}
},

View File

@@ -40,7 +40,7 @@ build_src_filter =
${env:esp32_4mb_fromitems.build_src_filter}
[platformio]
default_envs = esp32_4mb
default_envs = esp8266_4mb
data_dir = data_svelte
[common_env_data]

View File

@@ -25,10 +25,16 @@ void handleOrder() {
String order = selectToMarker(orderBuf, ",");
SerialPrint("i", F("ORDER"), order);
String id = selectToMarker(order, " ");
//это модификатор для даты графика
// if (id.endsWith("-date")) {
//}
//здесь нужно перебрать все методы execute всех векторов и выполнить те id которых совпали с id события
IoTItem* item = findIoTItem(selectToMarker(order, " "));
IoTItem* item = findIoTItem(id);
if (item) {
SerialPrint("i", F("ORDER"), "order matched " + order);
SerialPrint("i", F("ORDER"), "order found " + order);
String valStr = selectToMarkerLast(order, " ");
item->setValue(valStr);
}

View File

@@ -287,6 +287,7 @@ void publishWidgets() {
void publishState() {
String json = getParamsJson();
SerialPrint("i", F("DATA"), json);
json.replace("{", "");
json.replace("}", "");
json.replace("\"", "");

View File

@@ -70,7 +70,7 @@ String IoTItem::getValue() {
return value.valS;
}
//установить
//определяем тип прилетевшей величины
void IoTItem::setValue(String valStr) {
if (value.isDecimal = isDigitDotCommaStr(valStr)) {
value.valD = valStr.toFloat();
@@ -80,7 +80,7 @@ void IoTItem::setValue(String valStr) {
setValue(value);
}
//установить
//
void IoTItem::setValue(IoTValue Value) {
value = Value;
if (value.isDecimal) {

View File

@@ -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;

View File

@@ -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);
}

View File

@@ -6,7 +6,7 @@
"type": "Writing",
"subtype": "Loging",
"id": "log",
"widget": "chart1",
"widget": "chart2",
"page": "Графики",
"descr": "Температура",
"int": 1,

View File

@@ -159,7 +159,8 @@ boolean isDigitStr(const String& str) {
boolean isDigitDotCommaStr(const String& str) {
for (size_t i = 0; i < str.length(); i++) {
char latter = str.charAt(i);
if (!isDigit(latter) && latter != '.' && latter != '-') {
//если символ не цифра и не точка и не тире
if (!isDigit(latter) && latter != '.') {
return false;
}
}
@@ -186,9 +187,9 @@ String uint64ToString(uint64_t input) {
input /= base;
if (c < 10)
c +='0';
c += '0';
else
c += 'A' - 10;
c += 'A' - 10;
result = c + result;
} while (input);
return result;