From 6c0a456fd0d372eefff35171e70044bad7448dea Mon Sep 17 00:00:00 2001 From: biver Date: Thu, 20 Oct 2022 00:15:08 +0300 Subject: [PATCH 1/3] =?UTF-8?q?=D0=9A=D0=BE=D1=80=D1=80=D0=B5=D0=BA=D1=82?= =?UTF-8?q?=D0=B8=D1=80=D1=83=D0=B5=D0=BC=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D1=83=20=D1=82=D0=B0=D0=B9=D0=BC=D0=B5=D1=80=D0=B0=20=D1=81=20?= =?UTF-8?q?=D1=83=D1=87=D0=B5=D1=82=D0=BE=D0=BC=20=D0=B2=D0=BE=D0=B7=D0=BC?= =?UTF-8?q?=D0=BE=D0=B6=D0=BD=D0=BE=D1=81=D1=82=D0=B8=20=D1=81=D0=BE=D1=85?= =?UTF-8?q?=D1=80=D0=B0=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=81=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D0=BE=D1=8F=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/virtual/Timer/Timer.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/modules/virtual/Timer/Timer.cpp b/src/modules/virtual/Timer/Timer.cpp index e5cc7039..f843206f 100644 --- a/src/modules/virtual/Timer/Timer.cpp +++ b/src/modules/virtual/Timer/Timer.cpp @@ -9,7 +9,6 @@ class Timer : public IoTItem { bool _unfin = false; bool _ticker = false; bool _repeat = false; - bool _needSave = false; bool _pause = false; int _initValue; @@ -17,20 +16,20 @@ class Timer : public IoTItem { Timer(String parameters): IoTItem(parameters) { jsonRead(parameters, "countDown", _initValue); _unfin = !_initValue; - value.valD = _initValue; - if (_initValue) value.valD = value.valD + 1; // +1 - компенсируем ранний вычет счетчика, ранний вычет, чтоб после события значение таймера не исказилось. - // +0 - если изначально установили бесконечный счет + + if (!_needSave) { + value.valD = _initValue; + if (_initValue) value.valD = value.valD + 1; // +1 - компенсируем ранний вычет счетчика, ранний вычет, чтоб после события значение таймера не исказилось. + } jsonRead(parameters, "ticker", _ticker); jsonRead(parameters, "repeat", _repeat); - jsonRead(parameters, "needSave", _needSave); // нужно сохранять счетчик в постоянную память } void doByInterval() { if (!_unfin && value.valD >= 0 && !_pause) { if (_repeat && value.valD == 0) value.valD = _initValue; value.valD--; - if (_needSave) needSave = true; if (value.valD == 0) { regEvent(value.valD, "Time's up"); } From c89127c067fdd578940915736c16c27b7426442d Mon Sep 17 00:00:00 2001 From: biver Date: Thu, 20 Oct 2022 00:16:02 +0300 Subject: [PATCH 2/3] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D1=8F?= =?UTF-8?q?=D0=B5=D0=BC=20=D0=B2=20=D0=B1=D0=B0=D0=B7=D0=BE=D0=B2=D1=8B?= =?UTF-8?q?=D0=B5=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D0=B8=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=B4=D0=B4=D0=B5=D1=80=D0=B6=D0=BA=D1=83=20=D1=81=D0=BE=D1=85?= =?UTF-8?q?=D1=80=D0=B0=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=81=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D0=BE=D1=8F=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/exec/ButtonIn/modinfo.json | 1 + src/modules/exec/ButtonOut/modinfo.json | 1 + src/modules/virtual/VButton/modinfo.json | 1 + src/modules/virtual/Variable/modinfo.json | 6 +++++- 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/modules/exec/ButtonIn/modinfo.json b/src/modules/exec/ButtonIn/modinfo.json index 549eec8c..7ab286b7 100644 --- a/src/modules/exec/ButtonIn/modinfo.json +++ b/src/modules/exec/ButtonIn/modinfo.json @@ -9,6 +9,7 @@ "widget": "toggle", "page": "Кнопки", "descr": "Освещение", + "needSave": 0, "int": 0, "pin": 16, "execLevel": "1", diff --git a/src/modules/exec/ButtonOut/modinfo.json b/src/modules/exec/ButtonOut/modinfo.json index 160527a7..abfdac70 100644 --- a/src/modules/exec/ButtonOut/modinfo.json +++ b/src/modules/exec/ButtonOut/modinfo.json @@ -5,6 +5,7 @@ "name": "Управление пином", "type": "Writing", "subtype": "ButtonOut", + "needSave": 0, "id": "btn", "widget": "toggle", "page": "Кнопки", diff --git a/src/modules/virtual/VButton/modinfo.json b/src/modules/virtual/VButton/modinfo.json index ee31eddf..80ed2d53 100644 --- a/src/modules/virtual/VButton/modinfo.json +++ b/src/modules/virtual/VButton/modinfo.json @@ -6,6 +6,7 @@ "type": "Reading", "subtype": "VButton", "id": "vbtn", + "needSave": 0, "widget": "toggle", "page": "Кнопки", "descr": "Кнопка", diff --git a/src/modules/virtual/Variable/modinfo.json b/src/modules/virtual/Variable/modinfo.json index c6607ccc..940ca4c0 100644 --- a/src/modules/virtual/Variable/modinfo.json +++ b/src/modules/virtual/Variable/modinfo.json @@ -6,6 +6,7 @@ "type": "Reading", "subtype": "Variable", "id": "value", + "needSave": 0, "widget": "inputDgt", "page": "Ввод", "descr": "Введите число", @@ -18,6 +19,7 @@ "type": "Reading", "subtype": "Variable", "id": "time", + "needSave": 0, "widget": "inputTm", "page": "Ввод", "descr": "Введите время", @@ -30,6 +32,7 @@ "type": "Reading", "subtype": "Variable", "id": "time", + "needSave": 0, "widget": "inputDate", "page": "Ввод", "descr": "Введите дату", @@ -42,6 +45,7 @@ "type": "Reading", "subtype": "Variable", "id": "txt", + "needSave": 0, "widget": "inputTxt", "page": "Ввод", "descr": "Введите текст", @@ -65,7 +69,7 @@ "moduleDesc": "Специальный системный модуль для использования переменных в процессе автоматизации как элементов конфигурации.", "propInfo": { "int": "Не используется", - "val": "Не используется" + "val": "Значение при старте" } }, "defActive": true, From b8e76e19b89e410fa528fd3de5d38cea7c430d92 Mon Sep 17 00:00:00 2001 From: biver Date: Thu, 20 Oct 2022 00:18:41 +0300 Subject: [PATCH 3/3] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D1=8F?= =?UTF-8?q?=D0=B5=D0=BC=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D1=8E=20?= =?UTF-8?q?=D1=81=D0=BE=D1=85=D1=80=D0=B0=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D1=81=D0=BE=D1=81=D1=82=D0=BE=D1=8F=D0=BD=D0=B8=D1=8F=20=D1=8D?= =?UTF-8?q?=D0=BB=D0=B5=D0=BC=D0=B5=D0=BD=D1=82=D0=BE=D0=B2=20=D0=BD=D0=B0?= =?UTF-8?q?=20flash?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data_svelte/items.json | 481 ++++++++++++++++++++++++++++++--- data_svelte/values.json | 3 + data_svelte_lite/settings.json | 3 +- data_svelte_lite/values.json | 3 + include/EspFileSystem.h | 1 + include/Global.h | 2 + include/classes/IoTItem.h | 9 +- myProfile.json | 2 +- platformio.ini | 5 +- src/EspFileSystem.cpp | 8 + src/Global.cpp | 6 +- src/Main.cpp | 26 +- src/PeriodicTasks.cpp | 4 +- src/classes/IoTItem.cpp | 32 ++- src/modules/API.cpp | 34 +++ 15 files changed, 540 insertions(+), 79 deletions(-) create mode 100644 data_svelte/values.json create mode 100644 data_svelte_lite/values.json diff --git a/data_svelte/items.json b/data_svelte/items.json index fd9eb626..7ec9b010 100644 --- a/data_svelte/items.json +++ b/data_svelte/items.json @@ -7,7 +7,34 @@ "header": "Виртуальные элементы" }, { - "name": "1. Таймер", + "name": "1. График", + "type": "Writing", + "subtype": "Loging", + "id": "log", + "widget": "chart2", + "page": "Графики", + "descr": "Температура", + "num": 1, + "int": 5, + "logid": "t", + "points": 300 + }, + { + "name": "2. График дневного расхода", + "type": "Writing", + "subtype": "LogingDaily", + "id": "log", + "widget": "chart3", + "page": "Графики", + "descr": "Температура", + "num": 2, + "int": 1, + "logid": "t", + "points": 365, + "test": 0 + }, + { + "name": "3. Таймер", "type": "Writing", "subtype": "Timer", "id": "timer", @@ -19,73 +46,227 @@ "ticker": 1, "repeat": 1, "needSave": 0, - "num": 1 + "num": 3 }, { - "name": "2. Окно ввода числа (переменная)", + "name": "4. Окно ввода числа (переменная)", "type": "Reading", "subtype": "Variable", "id": "value", + "needSave": 0, "widget": "inputDgt", "page": "Ввод", "descr": "Введите число", "int": "0", "val": "0.0", - "num": 2 + "num": 4 }, { - "name": "3. Окно ввода времени", + "name": "5. Окно ввода времени", "type": "Reading", "subtype": "Variable", "id": "time", + "needSave": 0, "widget": "inputTm", "page": "Ввод", "descr": "Введите время", "int": "0", "val": "02:00", - "num": 3 + "num": 5 }, { - "name": "4. Окно ввода даты", + "name": "6. Окно ввода даты", "type": "Reading", "subtype": "Variable", "id": "time", + "needSave": 0, "widget": "inputDate", "page": "Ввод", "descr": "Введите дату", "int": "0", "val": "24.05.2022", - "num": 4 + "num": 6 }, { - "name": "5. Окно ввода текста", + "name": "7. Окно ввода текста", "type": "Reading", "subtype": "Variable", "id": "txt", + "needSave": 0, "widget": "inputTxt", "page": "Ввод", "descr": "Введите текст", "int": "0", "val": "текст", - "num": 5 + "num": 7 }, { - "name": "6. Виртуальная кнопка", + "name": "8. Виртуальная кнопка", "type": "Reading", "subtype": "VButton", "id": "vbtn", + "needSave": 0, "widget": "toggle", "page": "Кнопки", "descr": "Кнопка", "int": "0", "val": "0", - "num": 6 + "num": 8 }, { "header": "Сенсоры" }, { - "name": "7. DS18B20 Температура", + "name": "9. Acs712 Ток", + "type": "Reading", + "subtype": "Acs712", + "id": "amp", + "widget": "anydataAmp", + "page": "Сенсоры", + "descr": "Ток", + "round": 3, + "pin": 39, + "int": 5, + "num": 9 + }, + { + "name": "10. AHTXX Температура", + "type": "Reading", + "subtype": "AhtXXt", + "id": "Temp20", + "widget": "anydataTmp", + "page": "Сенсоры", + "descr": "AHTXX Температура", + "int": 15, + "addr": "0x38", + "shtType": 1, + "round": 1, + "num": 10 + }, + { + "name": "11. AHTXX Влажность", + "type": "Reading", + "subtype": "AhtXXh", + "id": "Hum20", + "widget": "anydataHum", + "page": "Сенсоры", + "descr": "AHTXX Влажность", + "int": 15, + "addr": "0x38", + "shtType": 1, + "round": 1, + "num": 11 + }, + { + "name": "12. Аналоговый сенсор", + "type": "Reading", + "subtype": "AnalogAdc", + "id": "t", + "widget": "anydataTmp", + "page": "Сенсоры", + "descr": "Температура", + "map": "1,1024,1,100", + "plus": 0, + "multiply": 1, + "round": 1, + "pin": 0, + "int": 15, + "avgSteps": 1, + "num": 12 + }, + { + "name": "13. BME280 Температура", + "type": "Reading", + "subtype": "Bme280t", + "id": "tmp3", + "widget": "anydataTmp", + "page": "Сенсоры", + "descr": "Температура", + "int": 15, + "addr": "0x77", + "round": 1, + "num": 13 + }, + { + "name": "14. BME280 Давление", + "type": "Reading", + "subtype": "Bme280p", + "id": "Press3", + "widget": "anydataMm", + "page": "Сенсоры", + "descr": "Давление", + "int": 15, + "addr": "0x77", + "round": 1, + "num": 14 + }, + { + "name": "15. BME280 Влажность", + "type": "Reading", + "subtype": "Bme280h", + "id": "Hum3", + "widget": "anydataHum", + "page": "Сенсоры", + "descr": "Влажность", + "int": 15, + "addr": "0x77", + "round": 1, + "num": 15 + }, + { + "name": "16. BMP280 Температура", + "type": "Reading", + "subtype": "Bmp280t", + "id": "tmp3", + "widget": "anydataTmp", + "page": "Сенсоры", + "descr": "280 Температура", + "int": 15, + "addr": "0x77", + "round": 1, + "num": 16 + }, + { + "name": "17. BMP280 Давление", + "type": "Reading", + "subtype": "Bmp280p", + "id": "Press3", + "widget": "anydataMm", + "page": "Сенсоры", + "descr": "280 Давление", + "int": 15, + "addr": "0x77", + "round": 1, + "num": 17 + }, + { + "name": "18. DHT11 Температура", + "type": "Reading", + "subtype": "Dht1122t", + "id": "tmp3", + "widget": "anydataTmp", + "page": "Сенсоры", + "descr": "Температура", + "int": 15, + "pin": 0, + "senstype": "dht11", + "num": 18 + }, + { + "name": "19. DHT11 Влажность", + "type": "Reading", + "subtype": "Dht1122h", + "id": "Hum3", + "widget": "anydataHum", + "page": "Сенсоры", + "descr": "Влажность", + "int": 15, + "pin": 0, + "senstype": "dht11", + "num": 19 + }, + { + "name": "20. DS18B20 Температура", "type": "Reading", "subtype": "Ds18b20", "id": "dstmp", @@ -97,11 +278,153 @@ "index": 0, "addr": "", "round": 1, - "num": 7 + "num": 20 }, { - "name": "8. Сканер кнопок 433 MHz", - "num": 8, + "name": "21. GY21 Температура", + "type": "Reading", + "subtype": "GY21t", + "id": "tmp4", + "widget": "anydataTmp", + "page": "Сенсоры", + "descr": "Температура", + "round": 1, + "int": 15, + "num": 21 + }, + { + "name": "22. GY21 Влажность", + "type": "Reading", + "subtype": "GY21h", + "id": "Hum4", + "widget": "anydataHum", + "page": "Сенсоры", + "descr": "Влажность", + "round": 1, + "int": 15, + "num": 22 + }, + { + "name": "23. HDC1080 Температура", + "type": "Reading", + "subtype": "Hdc1080t", + "id": "Temp1080", + "widget": "anydataTmp", + "page": "Сенсоры", + "descr": "1080 Температура", + "int": 15, + "addr": "0x40", + "round": 1, + "num": 23 + }, + { + "name": "24. HDC1080 Влажность", + "type": "Reading", + "subtype": "Hdc1080h", + "id": "Hum1080", + "widget": "anydataHum", + "page": "Сенсоры", + "descr": "1080 Влажность", + "int": 15, + "addr": "0x40", + "round": 1, + "num": 24 + }, + { + "name": "25. MAX6675 Температура", + "type": "Reading", + "subtype": "Max6675t", + "id": "maxtmp", + "widget": "anydataTmp", + "page": "Сенсоры", + "descr": "MAX Температура", + "int": 15, + "DO": 12, + "CS": 13, + "CLK": 14, + "num": 25 + }, + { + "name": "26. PZEM 004t Напряжение", + "type": "Reading", + "subtype": "Pzem004v", + "id": "v", + "widget": "anydataVlt", + "page": "PZEM", + "descr": "Напряжение", + "int": 15, + "addr": "0xF8", + "round": 1, + "num": 26 + }, + { + "name": "27. PZEM 004t Сила тока", + "type": "Reading", + "subtype": "Pzem004a", + "id": "a", + "widget": "anydataAmp", + "page": "PZEM", + "descr": "Сила тока", + "int": 15, + "addr": "0xF8", + "round": 1, + "num": 27 + }, + { + "name": "28. PZEM 004t Мощность", + "type": "Reading", + "subtype": "Pzem004w", + "id": "w", + "widget": "anydataWt", + "page": "PZEM", + "descr": "Мощность", + "int": 15, + "addr": "0xF8", + "round": 1, + "num": 28 + }, + { + "name": "29. PZEM 004t Энергия", + "type": "Reading", + "subtype": "Pzem004wh", + "id": "wh", + "widget": "anydataWth", + "page": "PZEM", + "descr": "Энергия", + "int": 15, + "addr": "0xF8", + "round": 1, + "num": 29 + }, + { + "name": "30. PZEM 004t Частота", + "type": "Reading", + "subtype": "Pzem004hz", + "id": "hz", + "widget": "anydataHtz", + "page": "PZEM", + "descr": "Частота", + "int": 15, + "addr": "0xF8", + "round": 1, + "num": 30 + }, + { + "name": "31. PZEM 004t Косинус", + "type": "Reading", + "subtype": "Pzem004pf", + "id": "pf", + "widget": "anydata", + "page": "PZEM", + "descr": "Косинус F", + "int": 15, + "addr": "0xF8", + "round": 1, + "num": 31 + }, + { + "name": "32. Сканер кнопок 433 MHz", + "num": 32, "type": "Reading", "subtype": "RCswitch", "id": "rsw", @@ -110,8 +433,56 @@ "pinTx": 12 }, { - "name": "9. HC-SR04 Ультразвуковой дальномер", - "num": 9, + "name": "33. Sht20 Температура", + "type": "Reading", + "subtype": "Sht20t", + "id": "tmp2", + "widget": "anydataTmp", + "page": "Сенсоры", + "descr": "Температура", + "int": 15, + "round": 1, + "num": 33 + }, + { + "name": "34. Sht20 Влажность", + "type": "Reading", + "subtype": "Sht20h", + "id": "Hum2", + "widget": "anydataHum", + "page": "Сенсоры", + "descr": "Влажность", + "int": 15, + "round": 1, + "num": 34 + }, + { + "name": "35. Sht30 Температура", + "type": "Reading", + "subtype": "Sht30t", + "id": "tmp30", + "widget": "anydataTmp", + "page": "Сенсоры", + "descr": "SHT30 Температура", + "int": 15, + "round": 1, + "num": 35 + }, + { + "name": "36. Sht30 Влажность", + "type": "Reading", + "subtype": "Sht30h", + "id": "Hum30", + "widget": "anydataHum", + "page": "Сенсоры", + "descr": "SHT30 Влажность", + "int": 15, + "round": 1, + "num": 36 + }, + { + "name": "37. HC-SR04 Ультразвуковой дальномер", + "num": 37, "type": "Reading", "subtype": "Sonar", "id": "sonar", @@ -122,29 +493,44 @@ "pinEcho": 4, "int": 5 }, + { + "name": "38. UART", + "type": "Reading", + "subtype": "UART", + "page": "", + "descr": "", + "widget": "nil", + "id": "u", + "tx": 12, + "rx": 13, + "speed": 9600, + "num": 38 + }, { "header": "Исполнительные устройства" }, { - "name": "10. Кнопка подключенная к пину", + "name": "39. Кнопка подключенная к пину", "type": "Writing", "subtype": "ButtonIn", "id": "btn", "widget": "toggle", "page": "Кнопки", "descr": "Освещение", + "needSave": 0, "int": 0, "pin": 16, "execLevel": "1", "pinMode": "INPUT", "debounceDelay": 50, "fixState": 0, - "num": 10 + "num": 39 }, { - "name": "11. Управление пином", + "name": "40. Управление пином", "type": "Writing", "subtype": "ButtonOut", + "needSave": 0, "id": "btn", "widget": "toggle", "page": "Кнопки", @@ -152,10 +538,24 @@ "int": 0, "inv": 0, "pin": 2, - "num": 11 + "num": 40 }, { - "name": "12. Расширитель портов Mcp23017", + "name": "41. Сервопривод", + "type": "Writing", + "subtype": "IoTServo", + "id": "servo", + "widget": "range", + "page": "servo", + "descr": "угол", + "int": 1, + "pin": 12, + "apin": -1, + "amap": "0, 4096, 0, 180", + "num": 41 + }, + { + "name": "42. Расширитель портов Mcp23017", "type": "Reading", "subtype": "Mcp23017", "id": "Mcp", @@ -165,10 +565,23 @@ "int": "0", "addr": "0x20", "index": 1, - "num": 12 + "num": 42 }, { - "name": "13. Расширитель портов Pcf8574", + "name": "43. MP3 плеер", + "type": "Reading", + "subtype": "Mp3", + "id": "mp3", + "widget": "", + "page": "", + "descr": "", + "int": 1, + "pins": "14,12", + "volume": 20, + "num": 43 + }, + { + "name": "44. Расширитель портов Pcf8574", "type": "Reading", "subtype": "Pcf8574", "id": "Pcf", @@ -178,10 +591,10 @@ "int": "0", "addr": "0x20", "index": 1, - "num": 13 + "num": 44 }, { - "name": "14. PWM ESP8266", + "name": "45. PWM ESP8266", "type": "Writing", "subtype": "Pwm8266", "id": "pwm", @@ -193,10 +606,10 @@ "freq": 5000, "val": 0, "apin": -1, - "num": 14 + "num": 45 }, { - "name": "15. Телеграм-Лайт", + "name": "46. Телеграм-Лайт", "type": "Writing", "subtype": "TelegramLT", "id": "tg", @@ -205,13 +618,13 @@ "descr": "", "token": "", "chatID": "", - "num": 15 + "num": 46 }, { "header": "Экраны" }, { - "name": "16. LCD экран 2004", + "name": "47. LCD экран 2004", "type": "Reading", "subtype": "Lcd2004", "id": "Lcd", @@ -223,10 +636,10 @@ "size": "20,4", "coord": "0,0", "id2show": "id датчика", - "num": 16 + "num": 47 }, { - "name": "17. LCD экран 1602", + "name": "48. LCD экран 1602", "type": "Reading", "subtype": "Lcd2004", "id": "Lcd", @@ -238,6 +651,6 @@ "size": "16,2", "coord": "0,0", "id2show": "id датчика", - "num": 17 + "num": 48 } ] \ No newline at end of file diff --git a/data_svelte/values.json b/data_svelte/values.json new file mode 100644 index 00000000..0e0dcd23 --- /dev/null +++ b/data_svelte/values.json @@ -0,0 +1,3 @@ +{ + +} \ No newline at end of file diff --git a/data_svelte_lite/settings.json b/data_svelte_lite/settings.json index f83115c2..e6d79494 100644 --- a/data_svelte_lite/settings.json +++ b/data_svelte_lite/settings.json @@ -19,5 +19,6 @@ "pinSCL": 0, "pinSDA": 0, "i2cFreq": 100000, - "settings_": "" + "settings_": "", + "wg": "group1" } \ No newline at end of file diff --git a/data_svelte_lite/values.json b/data_svelte_lite/values.json new file mode 100644 index 00000000..0e0dcd23 --- /dev/null +++ b/data_svelte_lite/values.json @@ -0,0 +1,3 @@ +{ + +} \ No newline at end of file diff --git a/include/EspFileSystem.h b/include/EspFileSystem.h index 5554dd49..81a6a660 100644 --- a/include/EspFileSystem.h +++ b/include/EspFileSystem.h @@ -38,6 +38,7 @@ extern void globalVarsSync(); extern String getParamsJson(); extern void syncSettingsFlashJson(); +extern void syncValuesFlashJson(); extern const String getChipId(); extern void setChipId(); diff --git a/include/Global.h b/include/Global.h index 3f036530..a8ae38d9 100644 --- a/include/Global.h +++ b/include/Global.h @@ -83,7 +83,9 @@ extern WebSocketsServer standWebSocket; ***********************************************глобальные переменные************************************************** **********************************************************************************************************************/ extern String settingsFlashJson; +extern String valuesFlashJson; extern String errorsHeapJson; +extern bool needSaveValues; // buf extern String orderBuf; diff --git a/include/classes/IoTItem.h b/include/classes/IoTItem.h index 555c3a35..62884956 100644 --- a/include/classes/IoTItem.h +++ b/include/classes/IoTItem.h @@ -6,9 +6,6 @@ struct IoTValue { String valS = ""; bool isDecimal = true; - - uint8_t* extBinInfo = NULL; // дополнительные бинарные данные из модуля - size_t extBinInfoSize = 0; // размер дополнительных данных в байтах }; class IoTItem { @@ -38,12 +35,11 @@ class IoTItem { bool iAmDead = false; // признак необходимости удалить объект из базы bool iAmLocal = true; // признак того, что айтем был создан локально - bool needSave = false; bool enableDoByInt = true; virtual IoTGpio* getGpioDriver(); - virtual void setValue(IoTValue Value); - virtual void setValue(String valStr); + virtual void setValue(IoTValue Value, bool generateEvent = true); + virtual void setValue(String valStr, bool generateEvent = true); String getRoundValue(); //методы для графиков @@ -54,6 +50,7 @@ class IoTItem { virtual void setTodayDate(); protected: + bool _needSave = false; // признак необходимости сохранять и загружать значение элемента на flash String _subtype; String _id; unsigned long _interval; diff --git a/myProfile.json b/myProfile.json index ca456f09..3c0ddde3 100644 --- a/myProfile.json +++ b/myProfile.json @@ -24,7 +24,7 @@ }, "projectProp": { "platformio": { - "default_envs": "esp8266_1mb_ota" + "default_envs": "esp8266_4mb" } }, "modules": { diff --git a/platformio.ini b/platformio.ini index 4660c6a7..311b037d 100644 --- a/platformio.ini +++ b/platformio.ini @@ -83,11 +83,10 @@ build_src_filter = ${env:esp32_4mb_fromitems.build_src_filter} [platformio] -default_envs = esp8266_1mb_ota -data_dir = data_svelte_lite +default_envs = esp8266_4mb +data_dir = data_svelte [common_env_data] -upload_port = COM4 lib_deps_external = bblanchon/ArduinoJson @6.18.0 knolleary/PubSubClient diff --git a/src/EspFileSystem.cpp b/src/EspFileSystem.cpp index 9ede484a..5f8619e8 100644 --- a/src/EspFileSystem.cpp +++ b/src/EspFileSystem.cpp @@ -14,6 +14,10 @@ void globalVarsSync() { settingsFlashJson = readFile(F("settings.json"), 4096); settingsFlashJson.replace("\r\n", ""); + valuesFlashJson = readFile(F("values.json"), 4096); + valuesFlashJson.replace("\r\n", ""); + + mqttPrefix = jsonReadStr(settingsFlashJson, F("mqttPrefix")); mqttRootDevice = mqttPrefix + "/" + chipId; jsonWriteStr_(settingsFlashJson, "root", mqttRootDevice); @@ -34,6 +38,10 @@ void syncSettingsFlashJson() { writeFile(F("settings.json"), settingsFlashJson); } +void syncValuesFlashJson() { + writeFile(F("values.json"), valuesFlashJson); +} + const String getChipId() { return String(ESP_getChipId()) + "-" + String(ESP_getFlashChipId()); } diff --git a/src/Global.cpp b/src/Global.cpp index b05c868e..2be45040 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -31,8 +31,10 @@ WebSocketsServer standWebSocket = WebSocketsServer(81); **********************************************************************************************************************/ IoTGpio IoTgpio(0); -String settingsFlashJson = "{}"; //переменная в которой хранятся все настройки, находится в оперативной памяти и синхронизированна с flash памятью -String errorsHeapJson = "{}"; //переменная в которой хранятся все ошибки, находится в оперативной памяти только +String settingsFlashJson = "{}"; // переменная в которой хранятся все настройки, находится в оперативной памяти и синхронизированна с flash памятью +String valuesFlashJson = "{}"; // переменная в которой хранятся все значения элементов, которые необходимо сохранить на flash. Находится в оперативной памяти и синхронизированна с flash памятью +String errorsHeapJson = "{}"; // переменная в которой хранятся все ошибки, находится в оперативной памяти только +bool needSaveValues = false; // признак необходимости сбросить значения элементов на flash // buf String orderBuf = ""; diff --git a/src/Main.cpp b/src/Main.cpp index dce96513..4c7a8dd8 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -149,6 +149,14 @@ void loop() { loopPeriod = millis() - st; if (loopPeriod > 2) Serial.println(loopPeriod); #endif + + // сохраняем значения IoTItems в файл каждую секунду, если были изменения (установлены маркеры на сохранение) + if (needSaveValues && millis()%1000 == 0) { + syncValuesFlashJson(); + needSaveValues = false; + delay(1); + Serial.println("syncValuesFlashJson()"); + } } //отправка json @@ -162,24 +170,6 @@ void loop() { // delay(1); // } -// сохраняем значения IoTItems в файл каждую секунду, если были изменения (установлены маркеры на сохранение) -// currentMillis = millis(); -// if (currentMillis - prevMillis >= 1000) { -// prevMillis = millis(); -// volStrForSave = ""; -// for (std::list::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) { -// if ((*it)->needSave) { -// (*it)->needSave = false; -// volStrForSave = volStrForSave + (*it)->getID() + "=" + (*it)->getValue() + ";"; -// } -// } -// -// if (volStrForSave != "") { -// Serial.print("volStrForSave: "); -// Serial.println(volStrForSave.c_str()); -// } -//} - // File dir = FileFS.open("/", "r"); // String out; // printDirectory(dir, out); diff --git a/src/PeriodicTasks.cpp b/src/PeriodicTasks.cpp index e44f5ecc..73e14dcc 100644 --- a/src/PeriodicTasks.cpp +++ b/src/PeriodicTasks.cpp @@ -34,16 +34,18 @@ void periodicTasksInit() { void printGlobalVarSize() { size_t settingsFlashJsonSize = settingsFlashJson.length(); // SerialPrint(F("i"), F("settingsFlashJson"), String(settingsFlashJsonSize)); + size_t valuesFlashJsonSize = valuesFlashJson.length(); size_t errorsHeapJsonSize = errorsHeapJson.length(); // SerialPrint(F("i"), F("errorsHeapJson"), String(errorsHeapJsonSize)); size_t devListHeapJsonSize = devListHeapJson.length(); // SerialPrint(F("i"), F("devListHeapJson"), String(devListHeapJsonSize)); - SerialPrint(F("i"), F("Var summ sz"), String(settingsFlashJsonSize + errorsHeapJsonSize + devListHeapJsonSize)); + SerialPrint(F("i"), F("Var summ sz"), String(settingsFlashJsonSize + valuesFlashJsonSize + errorsHeapJsonSize + devListHeapJsonSize)); size_t halfBuffer = JSON_BUFFER_SIZE / 2; if (settingsFlashJsonSize > halfBuffer || + valuesFlashJsonSize > halfBuffer || errorsHeapJsonSize > halfBuffer || devListHeapJsonSize > halfBuffer) { SerialPrint(F("EE"), F("Json"), F("Insufficient buffer size!!!")); diff --git a/src/classes/IoTItem.cpp b/src/classes/IoTItem.cpp index 4f3cb1a4..02061f9d 100644 --- a/src/classes/IoTItem.cpp +++ b/src/classes/IoTItem.cpp @@ -20,11 +20,11 @@ IoTItem::IoTItem(String parameters) { String valAsStr; if (jsonRead(parameters, F("val"), valAsStr, false)) // значение переменной или датчика при инициализации если есть в конфигурации - if (value.isDecimal = isDigitDotCommaStr(valAsStr)) { - value.valD = valAsStr.toFloat(); - } else { - value.valS = valAsStr; - } + setValue(valAsStr, false); + + jsonRead(parameters, F("needSave"), _needSave, false); + if (_needSave && jsonRead(valuesFlashJson, _id, valAsStr, false)) // пробуем достать из сохранения значение элемента, если указано, что нужно сохранять + setValue(valAsStr, false); String map; jsonRead(parameters, F("map"), map, false); @@ -58,27 +58,33 @@ String IoTItem::getValue() { } //определяем тип прилетевшей величины -void IoTItem::setValue(String valStr) { +void IoTItem::setValue(String valStr, bool generateEvent) { if (value.isDecimal = isDigitDotCommaStr(valStr)) { value.valD = valStr.toFloat(); } else { value.valS = valStr; } - setValue(value); + if (generateEvent) setValue(value, generateEvent); } // -void IoTItem::setValue(IoTValue Value) { +void IoTItem::setValue(IoTValue Value, bool generateEvent) { value = Value; - if (value.isDecimal) { - regEvent(value.valD, ""); - } else { - regEvent(value.valS, ""); - } + if (generateEvent) + if (value.isDecimal) { + regEvent(value.valD, ""); + } else { + regEvent(value.valS, ""); + } } //когда событие случилось void IoTItem::regEvent(String value, String consoleInfo = "") { + if (_needSave) { + jsonWriteStr_(valuesFlashJson, _id, value); + needSaveValues = true; + } + generateEvent(_id, value); publishStatusMqtt(_id, value); diff --git a/src/modules/API.cpp b/src/modules/API.cpp index 4efeb752..ab864765 100644 --- a/src/modules/API.cpp +++ b/src/modules/API.cpp @@ -1,14 +1,31 @@ #include "ESPConfiguration.h" +void* getAPI_Loging(String subtype, String params); +void* getAPI_LogingDaily(String subtype, String params); void* getAPI_Timer(String subtype, String params); void* getAPI_Variable(String subtype, String params); void* getAPI_VButton(String subtype, String params); +void* getAPI_Acs712(String subtype, String params); +void* getAPI_AhtXX(String subtype, String params); +void* getAPI_AnalogAdc(String subtype, String params); +void* getAPI_Bme280(String subtype, String params); +void* getAPI_Bmp280(String subtype, String params); +void* getAPI_Dht1122(String subtype, String params); void* getAPI_Ds18b20(String subtype, String params); +void* getAPI_GY21(String subtype, String params); +void* getAPI_Hdc1080(String subtype, String params); +void* getAPI_Max6675(String subtype, String params); +void* getAPI_Pzem004(String subtype, String params); void* getAPI_RCswitch(String subtype, String params); +void* getAPI_Sht20(String subtype, String params); +void* getAPI_Sht30(String subtype, String params); void* getAPI_Sonar(String subtype, String params); +void* getAPI_UART(String subtype, String params); void* getAPI_ButtonIn(String subtype, String params); 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_Pcf8574(String subtype, String params); void* getAPI_Pwm8266(String subtype, String params); void* getAPI_TelegramLT(String subtype, String params); @@ -16,15 +33,32 @@ void* getAPI_Lcd2004(String subtype, String params); void* getAPI(String subtype, String params) { void* tmpAPI; +if ((tmpAPI = getAPI_Loging(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_LogingDaily(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_VButton(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_Acs712(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_AhtXX(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_AnalogAdc(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_Bme280(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_Bmp280(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_Dht1122(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Ds18b20(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_GY21(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_Hdc1080(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_Max6675(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_Pzem004(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_RCswitch(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_Sht20(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_Sht30(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Sonar(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_UART(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_ButtonIn(subtype, params)) != nullptr) return tmpAPI; 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_Pcf8574(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Pwm8266(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_TelegramLT(subtype, params)) != nullptr) return tmpAPI;