mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-30 03:49:13 +03:00
не рабочая версия - ввод даты в процессе
This commit is contained in:
@@ -455,18 +455,16 @@
|
|||||||
"num": 34
|
"num": 34
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "35. PWM ESP32",
|
"name": "35. PWM ESP8266",
|
||||||
"type": "Writing",
|
"type": "Writing",
|
||||||
"subtype": "Pwm32",
|
"subtype": "Pwm8266",
|
||||||
"id": "pwm",
|
"id": "pwm",
|
||||||
"widget": "range",
|
"widget": "range",
|
||||||
"page": "Кнопки",
|
"page": "Кнопки",
|
||||||
"descr": "PWM",
|
"descr": "PWM",
|
||||||
"int": 0,
|
"int": 0,
|
||||||
"pin": 2,
|
"pin": 15,
|
||||||
"freq": 5000,
|
"freq": 5000,
|
||||||
"ledChannel": 2,
|
|
||||||
"PWM_resolution": 10,
|
|
||||||
"val": 0,
|
"val": 0,
|
||||||
"apin": -1,
|
"apin": -1,
|
||||||
"num": 35
|
"num": 35
|
||||||
|
|||||||
@@ -194,5 +194,8 @@
|
|||||||
"widget": "anydata",
|
"widget": "anydata",
|
||||||
"after": "Vlt",
|
"after": "Vlt",
|
||||||
"icon": "speedometer"
|
"icon": "speedometer"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Без виджета"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
},
|
},
|
||||||
"projectProp": {
|
"projectProp": {
|
||||||
"platformio": {
|
"platformio": {
|
||||||
"default_envs": "esp32_4mb",
|
"default_envs": "esp8266_4mb",
|
||||||
"data_dir": "data_svelte"
|
"data_dir": "data_svelte"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ build_src_filter =
|
|||||||
${env:esp32_4mb_fromitems.build_src_filter}
|
${env:esp32_4mb_fromitems.build_src_filter}
|
||||||
|
|
||||||
[platformio]
|
[platformio]
|
||||||
default_envs = esp32_4mb
|
default_envs = esp8266_4mb
|
||||||
data_dir = data_svelte
|
data_dir = data_svelte
|
||||||
|
|
||||||
[common_env_data]
|
[common_env_data]
|
||||||
|
|||||||
@@ -25,10 +25,16 @@ void handleOrder() {
|
|||||||
String order = selectToMarker(orderBuf, ",");
|
String order = selectToMarker(orderBuf, ",");
|
||||||
SerialPrint("i", F("ORDER"), order);
|
SerialPrint("i", F("ORDER"), order);
|
||||||
|
|
||||||
|
String id = selectToMarker(order, " ");
|
||||||
|
|
||||||
|
//это модификатор для даты графика
|
||||||
|
// if (id.endsWith("-date")) {
|
||||||
|
//}
|
||||||
|
|
||||||
//здесь нужно перебрать все методы execute всех векторов и выполнить те id которых совпали с id события
|
//здесь нужно перебрать все методы execute всех векторов и выполнить те id которых совпали с id события
|
||||||
IoTItem* item = findIoTItem(selectToMarker(order, " "));
|
IoTItem* item = findIoTItem(id);
|
||||||
if (item) {
|
if (item) {
|
||||||
SerialPrint("i", F("ORDER"), "order matched " + order);
|
SerialPrint("i", F("ORDER"), "order found " + order);
|
||||||
String valStr = selectToMarkerLast(order, " ");
|
String valStr = selectToMarkerLast(order, " ");
|
||||||
item->setValue(valStr);
|
item->setValue(valStr);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -287,6 +287,7 @@ void publishWidgets() {
|
|||||||
|
|
||||||
void publishState() {
|
void publishState() {
|
||||||
String json = getParamsJson();
|
String json = getParamsJson();
|
||||||
|
SerialPrint("i", F("DATA"), json);
|
||||||
json.replace("{", "");
|
json.replace("{", "");
|
||||||
json.replace("}", "");
|
json.replace("}", "");
|
||||||
json.replace("\"", "");
|
json.replace("\"", "");
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ String IoTItem::getValue() {
|
|||||||
return value.valS;
|
return value.valS;
|
||||||
}
|
}
|
||||||
|
|
||||||
//установить
|
//определяем тип прилетевшей величины
|
||||||
void IoTItem::setValue(String valStr) {
|
void IoTItem::setValue(String valStr) {
|
||||||
if (value.isDecimal = isDigitDotCommaStr(valStr)) {
|
if (value.isDecimal = isDigitDotCommaStr(valStr)) {
|
||||||
value.valD = valStr.toFloat();
|
value.valD = valStr.toFloat();
|
||||||
@@ -80,7 +80,7 @@ void IoTItem::setValue(String valStr) {
|
|||||||
setValue(value);
|
setValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
//установить
|
//
|
||||||
void IoTItem::setValue(IoTValue Value) {
|
void IoTItem::setValue(IoTValue Value) {
|
||||||
value = Value;
|
value = Value;
|
||||||
if (value.isDecimal) {
|
if (value.isDecimal) {
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ void* getAPI_ButtonOut(String subtype, String params);
|
|||||||
void* getAPI_IoTServo(String subtype, String params);
|
void* getAPI_IoTServo(String subtype, String params);
|
||||||
void* getAPI_Mcp23017(String subtype, String params);
|
void* getAPI_Mcp23017(String subtype, String params);
|
||||||
void* getAPI_Mp3(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_TelegramLT(String subtype, String params);
|
||||||
void* getAPI_Lcd2004(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_IoTServo(subtype, params)) != nullptr) return tmpAPI;
|
||||||
if ((tmpAPI = getAPI_Mcp23017(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_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_TelegramLT(subtype, params)) != nullptr) return tmpAPI;
|
||||||
if ((tmpAPI = getAPI_Lcd2004(subtype, params)) != nullptr) return tmpAPI;
|
if ((tmpAPI = getAPI_Lcd2004(subtype, params)) != nullptr) return tmpAPI;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|||||||
@@ -1,18 +1,25 @@
|
|||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include "classes/IoTItem.h"
|
#include "classes/IoTItem.h"
|
||||||
|
#include "ESPConfiguration.h"
|
||||||
#include "NTP.h"
|
#include "NTP.h"
|
||||||
|
|
||||||
|
void *getAPI_Date(String params);
|
||||||
|
|
||||||
|
String date;
|
||||||
class Loging : public IoTItem {
|
class Loging : public IoTItem {
|
||||||
private:
|
private:
|
||||||
String logid;
|
String logid;
|
||||||
String id;
|
String id;
|
||||||
String filesList = "";
|
String filesList = "";
|
||||||
|
|
||||||
|
bool firstTime = true;
|
||||||
|
|
||||||
int points;
|
int points;
|
||||||
int keepdays;
|
int keepdays;
|
||||||
|
|
||||||
|
IoTItem *dateIoTItem;
|
||||||
|
|
||||||
unsigned long interval;
|
unsigned long interval;
|
||||||
bool firstTime = true;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Loging(String parameters) : IoTItem(parameters) {
|
Loging(String parameters) : IoTItem(parameters) {
|
||||||
@@ -26,6 +33,10 @@ class Loging : public IoTItem {
|
|||||||
jsonRead(parameters, F("int"), interval);
|
jsonRead(parameters, F("int"), interval);
|
||||||
interval = interval * 1000 * 60; //приводим к милисекундам
|
interval = interval * 1000 * 60; //приводим к милисекундам
|
||||||
jsonRead(parameters, F("keepdays"), keepdays);
|
jsonRead(parameters, F("keepdays"), keepdays);
|
||||||
|
|
||||||
|
//создадим экземпляр класса даты
|
||||||
|
dateIoTItem = (IoTItem *)getAPI_Date("{\"id\": \"" + id + "-date\"}");
|
||||||
|
IoTItems.push_back(dateIoTItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
String getValue() {
|
String getValue() {
|
||||||
@@ -46,13 +57,21 @@ class Loging : public IoTItem {
|
|||||||
void regEvent(String value, String consoleInfo = "") {
|
void regEvent(String value, String consoleInfo = "") {
|
||||||
generateEvent(_id, value);
|
generateEvent(_id, value);
|
||||||
publishStatusMqtt(_id, value);
|
publishStatusMqtt(_id, value);
|
||||||
String topic = mqttRootDevice + "/" + _id;
|
String json = createSingleJson(_id, value);
|
||||||
String json = "{\"topic\":\"" + topic + "\",\"status\":[{\"x\":" + String(unixTime) + ",\"y1\":" + value + "}]}";
|
|
||||||
publishStatusWsJson(json);
|
publishStatusWsJson(json);
|
||||||
SerialPrint("i", "Sensor " + consoleInfo, "'" + _id + "' data: " + value + "'");
|
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() {
|
void doByInterval() {
|
||||||
|
if (firstTime) {
|
||||||
|
firstTime = false;
|
||||||
|
}
|
||||||
|
|
||||||
//если объект логгирования не был создан
|
//если объект логгирования не был создан
|
||||||
if (!isItemExist(logid)) {
|
if (!isItemExist(logid)) {
|
||||||
SerialPrint("E", F("Loging"), "'" + id + "' loging object not exist");
|
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");
|
SerialPrint("i", F("Loging"), "file '" + buf + "' too old, deleted");
|
||||||
removeFile(buf);
|
removeFile(buf);
|
||||||
} else {
|
} else {
|
||||||
|
unsigned long reqUnixTime = strDateToUnix(date);
|
||||||
|
if (fileUnixTime > reqUnixTime && fileUnixTime < reqUnixTime + 86400) {
|
||||||
createJson(buf, i, mqtt);
|
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));
|
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;
|
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",
|
"type": "Writing",
|
||||||
"subtype": "Loging",
|
"subtype": "Loging",
|
||||||
"id": "log",
|
"id": "log",
|
||||||
"widget": "chart1",
|
"widget": "chart2",
|
||||||
"page": "Графики",
|
"page": "Графики",
|
||||||
"descr": "Температура",
|
"descr": "Температура",
|
||||||
"int": 1,
|
"int": 1,
|
||||||
|
|||||||
@@ -159,7 +159,8 @@ boolean isDigitStr(const String& str) {
|
|||||||
boolean isDigitDotCommaStr(const String& str) {
|
boolean isDigitDotCommaStr(const String& str) {
|
||||||
for (size_t i = 0; i < str.length(); i++) {
|
for (size_t i = 0; i < str.length(); i++) {
|
||||||
char latter = str.charAt(i);
|
char latter = str.charAt(i);
|
||||||
if (!isDigit(latter) && latter != '.' && latter != '-') {
|
//если символ не цифра и не точка и не тире
|
||||||
|
if (!isDigit(latter) && latter != '.') {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -186,7 +187,7 @@ String uint64ToString(uint64_t input) {
|
|||||||
input /= base;
|
input /= base;
|
||||||
|
|
||||||
if (c < 10)
|
if (c < 10)
|
||||||
c +='0';
|
c += '0';
|
||||||
else
|
else
|
||||||
c += 'A' - 10;
|
c += 'A' - 10;
|
||||||
result = c + result;
|
result = c + result;
|
||||||
|
|||||||
Reference in New Issue
Block a user