модуль логгирования, начало

This commit is contained in:
Dmitry Borisenko
2022-08-13 12:18:58 +02:00
parent 72b54eb5bb
commit 1f9f746149
9 changed files with 195 additions and 126 deletions

View File

@@ -7,7 +7,19 @@
"header": "Виртуальные элементы" "header": "Виртуальные элементы"
}, },
{ {
"name": "1. Таймер", "name": "1. Логгирование в график",
"type": "Writing",
"subtype": "Loging",
"id": "log",
"widget": "chart1",
"page": "Графики",
"descr": "График",
"int": 60,
"logid": "tmp",
"num": 1
},
{
"name": "2. Таймер",
"type": "Writing", "type": "Writing",
"subtype": "Timer", "subtype": "Timer",
"id": "timer", "id": "timer",
@@ -19,10 +31,10 @@
"ticker": 0, "ticker": 0,
"repeat": 0, "repeat": 0,
"needSave": 0, "needSave": 0,
"num": 1 "num": 2
}, },
{ {
"name": "2. Окно ввода цифры (переменная)", "name": "3. Окно ввода цифры (переменная)",
"type": "Reading", "type": "Reading",
"subtype": "Variable", "subtype": "Variable",
"id": "value", "id": "value",
@@ -30,11 +42,11 @@
"page": "Ввод", "page": "Ввод",
"descr": "Введите цифру", "descr": "Введите цифру",
"int": "0", "int": "0",
"val": "0", "val": "0.0",
"num": 2 "num": 3
}, },
{ {
"name": "3. Окно ввода времени", "name": "4. Окно ввода времени",
"type": "Reading", "type": "Reading",
"subtype": "Variable", "subtype": "Variable",
"id": "time", "id": "time",
@@ -42,11 +54,11 @@
"page": "Ввод", "page": "Ввод",
"descr": "Введите время", "descr": "Введите время",
"int": "0", "int": "0",
"val": "0", "val": "02:00",
"num": 3 "num": 4
}, },
{ {
"name": "4. Окно ввода даты", "name": "5. Окно ввода даты",
"type": "Reading", "type": "Reading",
"subtype": "Variable", "subtype": "Variable",
"id": "time", "id": "time",
@@ -54,11 +66,11 @@
"page": "Ввод", "page": "Ввод",
"descr": "Введите дату", "descr": "Введите дату",
"int": "0", "int": "0",
"val": "0", "val": "24.05.2022",
"num": 4 "num": 5
}, },
{ {
"name": "5. Виртуальная кнопка", "name": "6. Виртуальная кнопка",
"type": "Reading", "type": "Reading",
"subtype": "VButton", "subtype": "VButton",
"id": "vbtn", "id": "vbtn",
@@ -67,13 +79,13 @@
"descr": "Кнопка", "descr": "Кнопка",
"int": "0", "int": "0",
"val": "0", "val": "0",
"num": 5 "num": 6
}, },
{ {
"header": "Сенсоры" "header": "Сенсоры"
}, },
{ {
"name": "6. Cенсор температуры AHT20", "name": "7. Cенсор температуры AHT20",
"type": "Reading", "type": "Reading",
"subtype": "Aht20t", "subtype": "Aht20t",
"id": "Temp20", "id": "Temp20",
@@ -83,10 +95,10 @@
"int": 15, "int": 15,
"addr": "0x38", "addr": "0x38",
"round": 1, "round": 1,
"num": 6 "num": 7
}, },
{ {
"name": "7. Cенсор влажности AHT20", "name": "8. Cенсор влажности AHT20",
"type": "Reading", "type": "Reading",
"subtype": "Aht20h", "subtype": "Aht20h",
"id": "Hum20", "id": "Hum20",
@@ -96,10 +108,10 @@
"int": 15, "int": 15,
"addr": "0x38", "addr": "0x38",
"round": 1, "round": 1,
"num": 7 "num": 8
}, },
{ {
"name": "8. Аналоговый сенсор", "name": "9. Аналоговый сенсор",
"type": "Reading", "type": "Reading",
"subtype": "AnalogAdc", "subtype": "AnalogAdc",
"id": "t", "id": "t",
@@ -113,10 +125,10 @@
"pin": 0, "pin": 0,
"int": 15, "int": 15,
"avgSteps": 1, "avgSteps": 1,
"num": 8 "num": 9
}, },
{ {
"name": "9. Cенсор температуры Bme280", "name": "10. Cенсор температуры Bme280",
"type": "Reading", "type": "Reading",
"subtype": "Bme280t", "subtype": "Bme280t",
"id": "tmp3", "id": "tmp3",
@@ -126,10 +138,10 @@
"int": 15, "int": 15,
"addr": "0x77", "addr": "0x77",
"round": 1, "round": 1,
"num": 9 "num": 10
}, },
{ {
"name": "10. Cенсор давления Bme280", "name": "11. Cенсор давления Bme280",
"type": "Reading", "type": "Reading",
"subtype": "Bme280p", "subtype": "Bme280p",
"id": "Press3", "id": "Press3",
@@ -139,10 +151,10 @@
"int": 15, "int": 15,
"addr": "0x77", "addr": "0x77",
"round": 1, "round": 1,
"num": 10 "num": 11
}, },
{ {
"name": "11. Cенсор влажности Bme280", "name": "12. Cенсор влажности Bme280",
"type": "Reading", "type": "Reading",
"subtype": "Bme280h", "subtype": "Bme280h",
"id": "Hum3", "id": "Hum3",
@@ -152,10 +164,10 @@
"int": 15, "int": 15,
"addr": "0x77", "addr": "0x77",
"round": 1, "round": 1,
"num": 11 "num": 12
}, },
{ {
"name": "12. Cенсор температуры Bmp280", "name": "13. Cенсор температуры Bmp280",
"type": "Reading", "type": "Reading",
"subtype": "Bmp280t", "subtype": "Bmp280t",
"id": "tmp3", "id": "tmp3",
@@ -165,10 +177,10 @@
"int": 15, "int": 15,
"addr": "0x77", "addr": "0x77",
"round": 1, "round": 1,
"num": 12 "num": 13
}, },
{ {
"name": "13. Cенсор давления Bmp280", "name": "14. Cенсор давления Bmp280",
"type": "Reading", "type": "Reading",
"subtype": "Bmp280p", "subtype": "Bmp280p",
"id": "Press3", "id": "Press3",
@@ -178,10 +190,10 @@
"int": 15, "int": 15,
"addr": "0x77", "addr": "0x77",
"round": 1, "round": 1,
"num": 13 "num": 14
}, },
{ {
"name": "14. Cенсор температуры dht11", "name": "15. Cенсор температуры dht11",
"type": "Reading", "type": "Reading",
"subtype": "Dht1122t", "subtype": "Dht1122t",
"id": "tmp3", "id": "tmp3",
@@ -191,10 +203,10 @@
"int": 15, "int": 15,
"pin": 0, "pin": 0,
"senstype": "dht11", "senstype": "dht11",
"num": 14 "num": 15
}, },
{ {
"name": "15. Cенсор влажности dht11", "name": "16. Cенсор влажности dht11",
"type": "Reading", "type": "Reading",
"subtype": "Dht1122h", "subtype": "Dht1122h",
"id": "Hum3", "id": "Hum3",
@@ -204,10 +216,10 @@
"int": 15, "int": 15,
"pin": 0, "pin": 0,
"senstype": "dht11", "senstype": "dht11",
"num": 15 "num": 16
}, },
{ {
"name": "16. Cенсор температуры ds18b20", "name": "17. Cенсор температуры ds18b20",
"type": "Reading", "type": "Reading",
"subtype": "Ds18b20", "subtype": "Ds18b20",
"id": "dstmp", "id": "dstmp",
@@ -219,10 +231,10 @@
"index": 0, "index": 0,
"addr": "", "addr": "",
"round": 1, "round": 1,
"num": 16 "num": 17
}, },
{ {
"name": "17. Cенсор температуры GY21", "name": "18. Cенсор температуры GY21",
"type": "Reading", "type": "Reading",
"subtype": "GY21t", "subtype": "GY21t",
"id": "tmp4", "id": "tmp4",
@@ -231,10 +243,10 @@
"descr": "Температура", "descr": "Температура",
"round": 1, "round": 1,
"int": 15, "int": 15,
"num": 17 "num": 18
}, },
{ {
"name": "18. Cенсор влажности GY21", "name": "19. Cенсор влажности GY21",
"type": "Reading", "type": "Reading",
"subtype": "GY21h", "subtype": "GY21h",
"id": "Hum4", "id": "Hum4",
@@ -243,10 +255,10 @@
"descr": "Влажность", "descr": "Влажность",
"round": 1, "round": 1,
"int": 15, "int": 15,
"num": 18 "num": 19
}, },
{ {
"name": "19. Cенсор температуры HDC1080", "name": "20. Cенсор температуры HDC1080",
"type": "Reading", "type": "Reading",
"subtype": "Hdc1080t", "subtype": "Hdc1080t",
"id": "Temp1080", "id": "Temp1080",
@@ -256,10 +268,10 @@
"int": 15, "int": 15,
"addr": "0x40", "addr": "0x40",
"round": 1, "round": 1,
"num": 19 "num": 20
}, },
{ {
"name": "20. Cенсор влажности HDC1080", "name": "21. Cенсор влажности HDC1080",
"type": "Reading", "type": "Reading",
"subtype": "Hdc1080h", "subtype": "Hdc1080h",
"id": "Hum1080", "id": "Hum1080",
@@ -269,10 +281,10 @@
"int": 15, "int": 15,
"addr": "0x40", "addr": "0x40",
"round": 1, "round": 1,
"num": 20 "num": 21
}, },
{ {
"name": "21. Cенсор температуры MAX6675", "name": "22. Cенсор температуры MAX6675",
"type": "Reading", "type": "Reading",
"subtype": "Max6675t", "subtype": "Max6675t",
"id": "maxtmp", "id": "maxtmp",
@@ -283,11 +295,11 @@
"DO": 12, "DO": 12,
"CS": 13, "CS": 13,
"CLK": 14, "CLK": 14,
"num": 21 "num": 22
}, },
{ {
"name": "22. Сканер кнопок 433 MHz", "name": "23. Сканер кнопок 433 MHz",
"num": 22, "num": 23,
"type": "Reading", "type": "Reading",
"subtype": "RCswitch", "subtype": "RCswitch",
"id": "rsw", "id": "rsw",
@@ -296,7 +308,7 @@
"pinTx": 12 "pinTx": 12
}, },
{ {
"name": "23. Cенсор температуры Sht20", "name": "24. Cенсор температуры Sht20",
"type": "Reading", "type": "Reading",
"subtype": "Sht20t", "subtype": "Sht20t",
"id": "tmp2", "id": "tmp2",
@@ -305,10 +317,10 @@
"descr": "Температура", "descr": "Температура",
"int": 15, "int": 15,
"round": 1, "round": 1,
"num": 23 "num": 24
}, },
{ {
"name": "24. Cенсор влажности Sht20", "name": "25. Cенсор влажности Sht20",
"type": "Reading", "type": "Reading",
"subtype": "Sht20h", "subtype": "Sht20h",
"id": "Hum2", "id": "Hum2",
@@ -317,10 +329,10 @@
"descr": "Влажность", "descr": "Влажность",
"int": 15, "int": 15,
"round": 1, "round": 1,
"num": 24 "num": 25
}, },
{ {
"name": "25. Cенсор температуры Sht30", "name": "26. Cенсор температуры Sht30",
"type": "Reading", "type": "Reading",
"subtype": "Sht30t", "subtype": "Sht30t",
"id": "tmp30", "id": "tmp30",
@@ -329,10 +341,10 @@
"descr": "SHT30 Температура", "descr": "SHT30 Температура",
"int": 15, "int": 15,
"round": 1, "round": 1,
"num": 25 "num": 26
}, },
{ {
"name": "26. Cенсор влажности Sht30", "name": "27. Cенсор влажности Sht30",
"type": "Reading", "type": "Reading",
"subtype": "Sht30h", "subtype": "Sht30h",
"id": "Hum30", "id": "Hum30",
@@ -341,11 +353,11 @@
"descr": "SHT30 Влажность", "descr": "SHT30 Влажность",
"int": 15, "int": 15,
"round": 1, "round": 1,
"num": 26 "num": 27
}, },
{ {
"name": "27. Сонар HC-SR04", "name": "28. Сонар HC-SR04",
"num": 27, "num": 28,
"type": "Reading", "type": "Reading",
"subtype": "Sonar", "subtype": "Sonar",
"id": "sonar", "id": "sonar",
@@ -360,7 +372,7 @@
"header": "Исполнительные устройства" "header": "Исполнительные устройства"
}, },
{ {
"name": "28. Кнопка подключенная к пину", "name": "29. Кнопка подключенная к пину",
"type": "Writing", "type": "Writing",
"subtype": "ButtonIn", "subtype": "ButtonIn",
"id": "btn", "id": "btn",
@@ -373,10 +385,10 @@
"pinMode": "INPUT", "pinMode": "INPUT",
"debounceDelay": 50, "debounceDelay": 50,
"fixState": 1, "fixState": 1,
"num": 28 "num": 29
}, },
{ {
"name": "29. Кнопка управляющая пином (Реле)", "name": "30. Кнопка управляющая пином (Реле)",
"type": "Writing", "type": "Writing",
"subtype": "ButtonOut", "subtype": "ButtonOut",
"id": "btn", "id": "btn",
@@ -386,23 +398,6 @@
"int": 0, "int": 0,
"inv": 0, "inv": 0,
"pin": 2, "pin": 2,
"num": 29
},
{
"name": "30. Поддержка DS1302(1), DS1307(2), DS3231(3), RX8025(4)",
"type": "Reading",
"subtype": "IarduinoRTC",
"id": "RTC",
"widget": "",
"page": "",
"descr": "",
"int": "1",
"chipNum": 1,
"rst": 16,
"clk": 5,
"dat": 4,
"defFormat": "d-m-Y",
"ticker": 0,
"num": 30 "num": 30
}, },
{ {

View File

@@ -27,6 +27,10 @@
}, },
"modules": { "modules": {
"Виртуальные элементы": [ "Виртуальные элементы": [
{
"path": "src\\modules\\virtual\\Logging",
"active": true
},
{ {
"path": "src\\modules\\virtual\\Timer", "path": "src\\modules\\virtual\\Timer",
"active": true "active": true
@@ -127,10 +131,6 @@
"path": "src\\modules\\exec\\EspCam", "path": "src\\modules\\exec\\EspCam",
"active": false "active": false
}, },
{
"path": "src\\modules\\exec\\IarduinoRTC",
"active": true
},
{ {
"path": "src\\modules\\exec\\IoTServo", "path": "src\\modules\\exec\\IoTServo",
"active": true "active": true

View File

@@ -65,7 +65,9 @@ lib_deps =
adafruit/Adafruit BusIO @ ^1.13.0 adafruit/Adafruit BusIO @ ^1.13.0
dfrobot/DFRobotDFPlayerMini @ ^1.0.5 dfrobot/DFRobotDFPlayerMini @ ^1.0.5
marcoschwartz/LiquidCrystal_I2C@^1.1.4 marcoschwartz/LiquidCrystal_I2C@^1.1.4
build_src_filter = build_src_filter =
+<modules\virtual\Logging>
+<modules\virtual\Timer> +<modules\virtual\Timer>
+<modules\virtual\Variable> +<modules\virtual\Variable>
+<modules\virtual\VButton> +<modules\virtual\VButton>
@@ -84,7 +86,6 @@ build_src_filter =
+<modules\sensors\Sonar> +<modules\sensors\Sonar>
+<modules\exec\ButtonIn> +<modules\exec\ButtonIn>
+<modules\exec\ButtonOut> +<modules\exec\ButtonOut>
+<modules\exec\IarduinoRTC>
+<modules\exec\IoTServo> +<modules\exec\IoTServo>
+<modules\exec\Mcp23017> +<modules\exec\Mcp23017>
+<modules\exec\Mp3> +<modules\exec\Mp3>
@@ -110,6 +111,7 @@ lib_deps =
adafruit/Adafruit BusIO @ ^1.13.0 adafruit/Adafruit BusIO @ ^1.13.0
dfrobot/DFRobotDFPlayerMini @ ^1.0.5 dfrobot/DFRobotDFPlayerMini @ ^1.0.5
marcoschwartz/LiquidCrystal_I2C@^1.1.4 marcoschwartz/LiquidCrystal_I2C@^1.1.4
build_src_filter = build_src_filter =
+<modules\virtual\Timer> +<modules\virtual\Timer>
+<modules\virtual\Variable> +<modules\virtual\Variable>

View File

@@ -132,20 +132,20 @@ void loop() {
handleEvent(); handleEvent();
// сохраняем значения IoTItems в файл каждую секунду, если были изменения (установлены маркеры на сохранение) // сохраняем значения IoTItems в файл каждую секунду, если были изменения (установлены маркеры на сохранение)
currentMillis = millis(); // currentMillis = millis();
if (currentMillis - prevMillis >= 1000) { // if (currentMillis - prevMillis >= 1000) {
prevMillis = millis(); // prevMillis = millis();
volStrForSave = ""; // volStrForSave = "";
for (std::list<IoTItem *>::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) { // for (std::list<IoTItem *>::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) {
if ((*it)->needSave) { // if ((*it)->needSave) {
(*it)->needSave = false; // (*it)->needSave = false;
volStrForSave = volStrForSave + (*it)->getID() + "=" + (*it)->getValue() + ";"; // volStrForSave = volStrForSave + (*it)->getID() + "=" + (*it)->getValue() + ";";
} // }
} // }
//
if (volStrForSave != "") { // if (volStrForSave != "") {
Serial.print("volStrForSave: "); // Serial.print("volStrForSave: ");
Serial.println(volStrForSave.c_str()); // Serial.println(volStrForSave.c_str());
} // }
} //}
} }

View File

@@ -165,8 +165,8 @@ IoTItem* findIoTItem(String name) {
return nullptr; return nullptr;
} }
// поиск плюс получение значения
String getItemValue(String name) { // поиск плюс получение значения String getItemValue(String name) {
IoTItem* tmp = findIoTItem(name); IoTItem* tmp = findIoTItem(name);
if (tmp) if (tmp)
return tmp->getValue(); return tmp->getValue();

View File

@@ -1,5 +1,6 @@
#include "ESPConfiguration.h" #include "ESPConfiguration.h"
void* getAPI_Loging(String subtype, String params);
void* getAPI_Timer(String subtype, String params); void* getAPI_Timer(String subtype, String params);
void* getAPI_Variable(String subtype, String params); void* getAPI_Variable(String subtype, String params);
void* getAPI_VButton(String subtype, String params); void* getAPI_VButton(String subtype, String params);
@@ -27,6 +28,7 @@ void* getAPI_Lcd2004(String subtype, String params);
void* getAPI(String subtype, String params) { void* getAPI(String subtype, String params) {
void* tmpAPI; void* tmpAPI;
if ((tmpAPI = getAPI_Loging(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Timer(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Timer(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Variable(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Variable(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_VButton(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_VButton(subtype, params)) != nullptr) return tmpAPI;

View File

@@ -0,0 +1,35 @@
#include "Global.h"
#include "classes/IoTItem.h"
class Loging : public IoTItem {
private:
String logval;
public:
Loging(String parameters) : IoTItem(parameters) {
jsonRead(parameters, F("logid"), logval);
}
// void setValue(IoTValue Value) {
// value = Value;
// regEvent((String)(int)value.valD, "Loging");
// }
void doByInterval() {
Serial.println("logging test " + logval);
String value = getItemValue(logval);
if (value == "") {
SerialPrint("E", F("Logging"), F("no value set"));
} else {
Serial.println("value " + value);
}
}
};
void* getAPI_Loging(String subtype, String param) {
if (subtype == F("Loging")) {
return new Loging(param);
} else {
return nullptr;
}
}

View File

@@ -0,0 +1,35 @@
{
"menuSection": "Виртуальные элементы",
"configItem": [
{
"name": "Логгирование в график",
"type": "Writing",
"subtype": "Loging",
"id": "log",
"widget": "chart1",
"page": "Графики",
"descr": "График",
"int": 60,
"logid": "tmp",
"num": 1
}
],
"about": {
"authorName": "Dmitry Borisenko",
"authorContact": "https://t.me/Dmitry_Borisenko",
"authorGit": "https://github.com/DmitryBorisenko33",
"specialThanks": "",
"moduleName": "Loging",
"moduleVersion": "1.0",
"moduleDesc": "Расширение позволяющее логгировать любую величину в график",
"propInfo": {
"int": "Интервал",
"logid": "ID величины которую будем логгировать"
}
},
"defActive": true,
"devices": {
"esp32_4mb": [],
"esp8266_4mb": []
}
}