diff --git a/data/items/button-out.npin.txt b/data/items/button-out.npin.txt index 380b815f..33bb17da 100644 --- a/data/items/button-out.npin.txt +++ b/data/items/button-out.npin.txt @@ -1 +1 @@ -0;button-out;id;toggleSunMoon;Кнопки;Освещение;order;st[0] \ No newline at end of file +0;button-out;id;toggle;Кнопки;Освещение;order;st[0] \ No newline at end of file diff --git a/include/Class/ScenarioClass.h b/include/Class/ScenarioClass.h index 3a241112..051b4939 100644 --- a/include/Class/ScenarioClass.h +++ b/include/Class/ScenarioClass.h @@ -72,15 +72,18 @@ class Scenario { } else if (_conditionSign == "!=") { flag = _eventValue != _conditionValue; } else if (_conditionSign == "<") { - flag = _eventValue.toInt() < _conditionValue.toInt(); + flag = _eventValue.toFloat() < _conditionValue.toFloat(); } else if (_conditionSign == ">") { - flag = _eventValue.toInt() > _conditionValue.toInt(); + flag = _eventValue.toFloat() > _conditionValue.toFloat(); } else if (_conditionSign == ">=") { - flag = _eventValue.toInt() >= _conditionValue.toInt(); + flag = _eventValue.toFloat() >= _conditionValue.toFloat(); } else if (_conditionSign == "<=") { - flag = _eventValue.toInt() <= _conditionValue.toInt(); + flag = _eventValue.toFloat() <= _conditionValue.toFloat(); } + Serial.println("event Value: " + _eventValue); + Serial.println("cond Value: " + _conditionValue); + if (flag) Serial.println("I Scenario event: " + _condition); return flag; @@ -97,7 +100,7 @@ class Scenario { this->calculate2(); if (this->isConditionSatisfied()) { //если вошедшее событие выполняет условие сценария _scenBlok = deleteBeforeDelimiter(_scenBlok, "\n"); - //Serial.println(" [>] Making: " + _scenBlok); + Serial.println(" [>] Making: " + _scenBlok); spaceCmdExecute(_scenBlok); } } diff --git a/include/Consts.h b/include/Consts.h index 61cbf9e1..8b842ee9 100644 --- a/include/Consts.h +++ b/include/Consts.h @@ -31,7 +31,7 @@ //#define MDNS_ENABLED //#define WEBSOCKET_ENABLED //#define LAYOUT_IN_RAM -#define UDP_ENABLED +//#define UDP_ENABLED //#define SSDP_ENABLED //=========Sensors enable/disable================================================================================================================================= diff --git a/include/items/ButtonOutClass.h b/include/items/ButtonOutClass.h index 46590814..bd3587c3 100644 --- a/include/items/ButtonOutClass.h +++ b/include/items/ButtonOutClass.h @@ -5,8 +5,8 @@ #include "Global.h" class ButtonOutClass : public LineParsing { - public: - ButtonOutClass() : LineParsing(){}; +public: + ButtonOutClass() : LineParsing() {}; void init() { if (_pin != "") { @@ -28,12 +28,13 @@ class ButtonOutClass : public LineParsing { if (inv == "") { digitalWrite(pinInt, state.toInt()); - } else { + } + else { digitalWrite(pinInt, !state.toInt()); } eventGen(key, ""); jsonWriteInt(configLiveJson, key, state.toInt()); - publishStatus(key, state); + publishStatus(key, state); } }; diff --git a/include/items/SensorDallasClass.h b/include/items/SensorDallasClass.h index 203bd7f0..c5b7b3dc 100644 --- a/include/items/SensorDallasClass.h +++ b/include/items/SensorDallasClass.h @@ -5,8 +5,8 @@ #include "items/SensorConvertingClass.h" class SensorDallasClass : public SensorConvertingClass { - public: - SensorDallasClass() : SensorConvertingClass(){}; +public: + SensorDallasClass() : SensorConvertingClass() {}; void SensorDallasInit() { oneWire = new OneWire((uint8_t)_pin.toInt()); @@ -36,7 +36,7 @@ class SensorDallasClass : public SensorConvertingClass { float valueFl = this->correction(key, value); eventGen(key, ""); jsonWriteStr(configLiveJson, key, String(valueFl)); - publishStatus(key, String(valueFl)); + publishStatus(key, String(valueFl)); SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl)); } } diff --git a/src/Scenario.cpp b/src/Scenario.cpp index 2399d178..ce0ec90d 100644 --- a/src/Scenario.cpp +++ b/src/Scenario.cpp @@ -8,68 +8,68 @@ boolean isScenarioEnabled() { return jsonReadBool(configSetupJson, "scen") && eventBuf != ""; } -void loopScenario() { - if (!isScenarioEnabled()) { - return; - } - String scenarioTmp = scenario; - scenarioTmp += "\n"; - scenarioTmp.replace("\r\n", "\n"); - scenarioTmp.replace("\r", "\n"); - - while (scenarioTmp.length()) { - String scenBlok = selectToMarker(scenarioTmp, "end"); //выделяем первый сценарий - if (!scenBlok.length()) { - return; - } - - size_t i = 0; - i++; - if (scenario_line_status[i] == 1) { - String condition = selectToMarker(scenBlok, "\n"); //выделяем условие - - String conditionParam = selectFromMarkerToMarker(condition, " ", 0); //выделяем параметр условия - String order = eventBuf; - String eventParam = selectToMarker(order, ","); //выделяем параметр события - - if (conditionParam == eventParam) { //если поступившее событие равно событию заданному buttonSet1 в файле начинаем его обработку - - String conditionSign = selectFromMarkerToMarker(condition, " ", 1); //выделяем знак (=) - - String conditionValue = selectFromMarkerToMarker(condition, " ", 2); //выделяем значение (1) - - boolean flag = false; - - String eventParam = jsonReadStr(configLiveJson, conditionParam); //получаем значение этого параметра события из json - - if (conditionSign == "=") { - flag = eventParam == conditionValue; - } else if (conditionSign == "!=") { - flag = eventParam != conditionValue; - } else if (conditionSign == "<") { - flag = eventParam.toInt() < conditionValue.toInt(); - } else if (conditionSign == ">") { - flag = eventParam.toInt() > conditionValue.toInt(); - } else if (conditionSign == ">=") { - flag = eventParam.toInt() >= conditionValue.toInt(); - } else if (conditionSign == "<=") { - flag = eventParam.toInt() <= conditionValue.toInt(); - } - - if (flag) { - scenBlok = deleteBeforeDelimiter(scenBlok, "\n"); // удаляем строку самого сценария оставляя только команды - SerialPrint("I","module","do: " + scenBlok); - spaceCmdExecute(scenBlok); // выполняем все команды - } - } - } - scenarioTmp = deleteBeforeDelimiter(scenarioTmp, "end\n"); //удаляем первый сценарий - } - - String eventBufTmp = eventBuf; //читаем файл событий - eventBufTmp = deleteBeforeDelimiter(eventBufTmp, ","); //удаляем выполненное событие - eventBuf = eventBufTmp; //записываем обновленный файл событий -} +//void loopScenario() { +// if (!isScenarioEnabled()) { +// return; +// } +// String scenarioTmp = scenario; +// scenarioTmp += "\n"; +// scenarioTmp.replace("\r\n", "\n"); +// scenarioTmp.replace("\r", "\n"); +// +// while (scenarioTmp.length()) { +// String scenBlok = selectToMarker(scenarioTmp, "end"); //выделяем первый сценарий +// if (!scenBlok.length()) { +// return; +// } +// +// size_t i = 0; +// i++; +// if (scenario_line_status[i] == 1) { +// String condition = selectToMarker(scenBlok, "\n"); //выделяем условие +// +// String conditionParam = selectFromMarkerToMarker(condition, " ", 0); //выделяем параметр условия +// String order = eventBuf; +// String eventParam = selectToMarker(order, ","); //выделяем параметр события +// +// if (conditionParam == eventParam) { //если поступившее событие равно событию заданному buttonSet1 в файле начинаем его обработку +// +// String conditionSign = selectFromMarkerToMarker(condition, " ", 1); //выделяем знак (=) +// +// String conditionValue = selectFromMarkerToMarker(condition, " ", 2); //выделяем значение (1) +// +// boolean flag = false; +// +// String eventParam = jsonReadStr(configLiveJson, conditionParam); //получаем значение этого параметра события из json +// +// if (conditionSign == "=") { +// flag = eventParam == conditionValue; +// } else if (conditionSign == "!=") { +// flag = eventParam != conditionValue; +// } else if (conditionSign == "<") { +// flag = eventParam.toInt() < conditionValue.toInt(); +// } else if (conditionSign == ">") { +// flag = eventParam.toInt() > conditionValue.toInt(); +// } else if (conditionSign == ">=") { +// flag = eventParam.toInt() >= conditionValue.toInt(); +// } else if (conditionSign == "<=") { +// flag = eventParam.toInt() <= conditionValue.toInt(); +// } +// +// if (flag) { +// scenBlok = deleteBeforeDelimiter(scenBlok, "\n"); // удаляем строку самого сценария оставляя только команды +// SerialPrint("I","module","do: " + scenBlok); +// spaceCmdExecute(scenBlok); // выполняем все команды +// } +// } +// } +// scenarioTmp = deleteBeforeDelimiter(scenarioTmp, "end\n"); //удаляем первый сценарий +// } +// +// String eventBufTmp = eventBuf; //читаем файл событий +// eventBufTmp = deleteBeforeDelimiter(eventBufTmp, ","); //удаляем выполненное событие +// eventBuf = eventBufTmp; //записываем обновленный файл событий +//} void eventGen(String event_name, String number) { if (!jsonReadBool(configSetupJson, "scen")) { @@ -78,18 +78,18 @@ void eventGen(String event_name, String number) { eventBuf = event_name + number + ","; } -String add_set(String str) { - String num1 = str.substring(str.length() - 1); - String num2 = str.substring(str.length() - 2, str.length() - 1); - if (isDigitStr(num1) && isDigitStr(num2)) { - str = str.substring(0, str.length() - 2) + "Set" + num2 + num1; - } else { - if (isDigitStr(num1)) { - str = str.substring(0, str.length() - 1) + "Set" + num1; - } - } - return str; -} +//String add_set(String str) { +// String num1 = str.substring(str.length() - 1); +// String num2 = str.substring(str.length() - 2, str.length() - 1); +// if (isDigitStr(num1) && isDigitStr(num2)) { +// str = str.substring(0, str.length() - 2) + "Set" + num2 + num1; +// } else { +// if (isDigitStr(num1)) { +// str = str.substring(0, str.length() - 1) + "Set" + num1; +// } +// } +// return str; +//} //button-out1 = 1 //button-out2 1