From e0ec19c5f79438d6424c363988918484e96570a6 Mon Sep 17 00:00:00 2001 From: Ilya Belyakov Date: Sat, 6 Jan 2024 17:30:23 +0500 Subject: [PATCH] =?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=BC=D0=B0=D1=82=D0=B5=D0=BC=D0=B0?= =?UTF-8?q?=D1=82=D0=B8=D0=BA=D1=83=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8?= =?UTF-8?q?=D1=8E=20=D0=B2=D1=85=D0=BE=D0=B6=D0=B4=D0=B5=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=20=D1=82=D0=B5=D0=BA=D1=83=D1=89=D0=B5=D0=B3=D0=BE=20=D0=B2?= =?UTF-8?q?=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=B8=20=D0=B2=20=D0=BF=D0=B5?= =?UTF-8?q?=D1=80=D0=B8=D0=BE=D0=B4=20=D0=92=20=D0=BF=D0=B0=D0=BF=D0=BA?= =?UTF-8?q?=D0=B5=20=D1=81=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D0=B5=D0=BC=20?= =?UTF-8?q?=D0=B5=D1=81=D1=82=D1=8C=20=D0=BF=D1=80=D0=B8=D0=BC=D0=B5=D1=80?= =?UTF-8?q?=20=D1=82=D0=B0=D0=B9=D0=BC=D0=B5=D1=80=D0=B0=20=D1=81=20=D0=B8?= =?UTF-8?q?=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=D0=BC=20=D0=BD=D0=BE=D0=B2=D0=BE=D0=B9=20=D1=84?= =?UTF-8?q?=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/virtual/Math/Math.cpp | 22 +- src/modules/virtual/Math/TimerRelay.json | 258 +++++++++++++++++++++++ src/modules/virtual/Math/modinfo.json | 10 +- 3 files changed, 286 insertions(+), 4 deletions(-) create mode 100644 src/modules/virtual/Math/TimerRelay.json diff --git a/src/modules/virtual/Math/Math.cpp b/src/modules/virtual/Math/Math.cpp index 7b14c396..d726d2dc 100644 --- a/src/modules/virtual/Math/Math.cpp +++ b/src/modules/virtual/Math/Math.cpp @@ -31,6 +31,18 @@ private: return mktime(&t); } + bool nowInTimePeriod(String startTime, String endTime) { + int h1 = selectToMarker(startTime, ":").toInt(); + int min1 = selectToMarkerLast(startTime, ":").toInt(); + int h2 = selectToMarker(endTime, ":").toInt(); + int min2 = selectToMarkerLast(endTime, ":").toInt(); + + int nowMinutes = _time_local.hour * 60 + _time_local.minute; + + return nowMinutes >= h1 * 60 + min1 && nowMinutes <= h2 * 60 + min2; + } + + public: IoTMath(String parameters) : IoTItem(parameters) {} @@ -42,7 +54,7 @@ public: //SerialPrint("i", F("IoTMath"), F("Mapping value done.")); return valTmp; } else if(command == "convertTime" && param.size() == 5) { - time_t unixTime = convertTime(param[0].valD, param[1].valD, param[2].valD, param[3].valD, param[4].valD); + uint32_t unixTime = convertTime(param[0].valD, param[1].valD, param[2].valD, param[3].valD, param[4].valD); if (unixTime == -1) { SerialPrint("E", F("IoTMath"), F("Failed to convert time.")); @@ -51,8 +63,12 @@ public: IoTValue valTmp; valTmp.isDecimal = true; - valTmp.valD = unixTime; - //SerialPrint("i", F("IoTMath"), F("Time conversion done.")); + valTmp.valD = static_cast< float > (unixTime); + return valTmp; + } else if(command == "nowInTimePeriod" && param.size() == 2) { + IoTValue valTmp; + valTmp.isDecimal = true; + valTmp.valD = nowInTimePeriod(param[0].valS, param[1].valS); return valTmp; } diff --git a/src/modules/virtual/Math/TimerRelay.json b/src/modules/virtual/Math/TimerRelay.json new file mode 100644 index 00000000..7a74884a --- /dev/null +++ b/src/modules/virtual/Math/TimerRelay.json @@ -0,0 +1,258 @@ +{ + "mark": "iotm", + "config": [ + { + "global": 0, + "type": "Writing", + "subtype": "ButtonOut", + "needSave": "1", + "id": "rel1", + "widget": "toggle", + "page": "Свет 1", + "descr": " Реле 1", + "int": 0, + "inv": "1", + "pin": "32" + }, + { + "global": 0, + "type": "Writing", + "subtype": "ButtonOut", + "needSave": "1", + "id": "rel2", + "widget": "toggle", + "page": "Свет 2", + "descr": " Реле 2", + "int": 0, + "inv": "1", + "pin": "33" + }, + { + "global": 0, + "type": "Reading", + "subtype": "RTC", + "id": "rtc", + "widget": "anydataDef", + "page": "Система", + "descr": "Время", + "chipCode": "3", + "timeFormat": "d-m-Y H:i:s", + "RST": -1, + "CLK": -1, + "DAT": -1, + "ticker": 0, + "int": 5, + "btn-setUTime": "0", + "btn-setSysTime": "nil" + }, + { + "global": 0, + "type": "Reading", + "subtype": "AnalogBtn", + "id": "btn1", + "widget": "nil", + "page": "Свет 1", + "descr": "Кнопка 1", + "pin": "34", + "aValue": 0, + "delta": 50 + }, + { + "global": 0, + "type": "Reading", + "subtype": "AnalogBtn", + "id": "btn2", + "widget": "nil", + "page": "Свет 2", + "descr": "Кнопка 2", + "pin": "34", + "aValue": "1910", + "delta": 50 + }, + { + "global": 0, + "type": "Reading", + "subtype": "IoTMath", + "id": "math", + "widget": "anydataValue", + "page": "Математика", + "descr": "" + }, + { + "global": 0, + "type": "Reading", + "subtype": "Variable", + "id": "start11", + "needSave": "1", + "widget": "inputTm", + "page": "Свет 1", + "descr": " Старт 1", + "int": "0", + "val": "0.0", + "map": "1024,1024,1,100", + "plus": 0, + "multiply": 1, + "round": 0 + }, + { + "global": 0, + "type": "Reading", + "subtype": "Variable", + "id": "stop11", + "needSave": "1", + "widget": "inputTm", + "page": "Свет 1", + "descr": " Стоп 1", + "int": "0", + "val": "0.0", + "map": "1024,1024,1,100", + "plus": 0, + "multiply": 1, + "round": 0 + }, + { + "global": 0, + "type": "Reading", + "subtype": "Variable", + "id": "start12", + "needSave": "1", + "widget": "inputTm", + "page": "Свет 1", + "descr": "Старт 2", + "int": "0", + "val": "0.0", + "map": "1024,1024,1,100", + "plus": 0, + "multiply": 1, + "round": 0 + }, + { + "global": 0, + "type": "Reading", + "subtype": "Variable", + "id": "stop12", + "needSave": "1", + "widget": "inputTm", + "page": "Свет 1", + "descr": "Стоп 2", + "int": "0", + "val": "0.0", + "map": "1024,1024,1,100", + "plus": 0, + "multiply": 1, + "round": 0 + }, + { + "global": 0, + "type": "Reading", + "subtype": "Variable", + "id": "start21", + "needSave": "1", + "widget": "inputTm", + "page": "Свет 2", + "descr": " Старт 1", + "int": "0", + "val": "0.0", + "map": "1024,1024,1,100", + "plus": 0, + "multiply": 1, + "round": 0 + }, + { + "global": 0, + "type": "Reading", + "subtype": "Variable", + "id": "stop21", + "needSave": "1", + "widget": "inputTm", + "page": "Свет 2", + "descr": " Стоп 1", + "int": "0", + "val": "0.0", + "map": "1024,1024,1,100", + "plus": 0, + "multiply": 1, + "round": 0 + }, + { + "global": 0, + "type": "Reading", + "subtype": "Variable", + "id": "start22", + "needSave": "1", + "widget": "inputTm", + "page": "Свет 2", + "descr": "Старт 2", + "int": "0", + "val": "0.0", + "map": "1024,1024,1,100", + "plus": 0, + "multiply": 1, + "round": 0 + }, + { + "global": 0, + "type": "Reading", + "subtype": "Variable", + "id": "stop22", + "needSave": "1", + "widget": "inputTm", + "page": "Свет 2", + "descr": "Стоп 2", + "int": "0", + "val": "0.0", + "map": "1024,1024,1,100", + "plus": 0, + "multiply": 1, + "round": 0 + }, + { + "global": 0, + "type": "Writing", + "subtype": "Cron", + "id": "timer", + "widget": "anydataRed", + "page": "Система", + "descr": "Будильник", + "int": 1, + "val": "0 * * * * *", + "formatNextAlarm": "%H:%M:%S", + "needSave": 0 + }, + { + "global": 0, + "type": "Reading", + "subtype": "VButton", + "id": "rel1on", + "needSave": "1", + "widget": "toggle", + "page": "Свет 1", + "descr": " Работать", + "int": "0", + "val": "0" + }, + { + "global": 0, + "type": "Reading", + "subtype": "VButton", + "id": "rel2on", + "needSave": "1", + "widget": "toggle", + "page": "Свет 2", + "descr": " Работать", + "int": "0", + "val": "0" + } + ] +} + +scenario=>if btn1>0 then rel1 = 1- rel1 +if btn2>0 then rel2 = 1- rel2 + +if timer == 0 | start11 | stop11 | start12 | stop12 | start21 | stop21 | start22 | stop22 then { +if rel1on then +if math.nowInTimePeriod(start11, stop11) | math.nowInTimePeriod(start12, stop12) then rel1=1 else rel1=0 + +if rel2on then +if math.nowInTimePeriod(start21, stop21) | math.nowInTimePeriod(start22, stop22) then rel2=1 else rel2=0 +} \ No newline at end of file diff --git a/src/modules/virtual/Math/modinfo.json b/src/modules/virtual/Math/modinfo.json index 6265e85b..27080b3c 100644 --- a/src/modules/virtual/Math/modinfo.json +++ b/src/modules/virtual/Math/modinfo.json @@ -38,10 +38,18 @@ }, { "name": "convertTime", - "descr": "Перевести время из формата d-m-Y H:i:s например, 13-08-2023 16:24:00 в юникс-время ", + "descr": "Перевести время из формата d-m-Y H:i:s например, 13-08-2023 16:24:00 в юникс-время", "params": [ "tm.convertTime(13, 08, 2023, 16, 24); - передаем пять целых чисел. секунды подставятся в ноль" ] + }, + { + "name": "nowInTimePeriod", + "descr": "Проверяет входит ли текущее время в указанный период. Возвращает 1 если входит, 0 если нет.", + "params": [ + "Начало периода в формате HH:MM", + "Конец периода в формате HH:MM" + ] } ] },