267 Scenario bug fully fixed Stable

This commit is contained in:
Dmitry Borisenko
2020-11-07 01:11:32 +03:00
parent 1f46226a46
commit 709a1fe1f7
30 changed files with 177 additions and 57 deletions

View File

@@ -24,6 +24,7 @@ public:
String setEventSign = selectFromMarkerToMarker(condition, " ", 1);
String setEventValue = selectFromMarkerToMarker(condition, " ", 2);
if (!isDigitStr(setEventValue)) setEventValue = jsonReadStr(configLiveJson, setEventValue);
String incommingEventValue = jsonReadStr(configLiveJson, incommingEvent);
if (incommingEvent == setEvent) {

View File

@@ -0,0 +1,70 @@
#pragma once
#include <Arduino.h>
#include "Cmd.h"
#include "Global.h"
class Scenario {
public:
void loop() {
String allBlocks = scenario;
allBlocks.replace("\r\n", "\n");
allBlocks.replace("\r", "\n");
allBlocks += "\n";
String incommingEvent = selectToMarker(eventBuf, ",");
String incommingEventKey = selectToMarker(incommingEvent, " ");
String incommingEventValue = selectToMarkerLast(incommingEvent, " ");
while (allBlocks.length() > 1) {
String oneBlock = selectToMarker(allBlocks, "end\n");
String condition = selectToMarker(oneBlock, "\n");
String setEventKey = selectFromMarkerToMarker(condition, " ", 0);
if (incommingEventKey == setEventKey) {
String setEventSign = selectFromMarkerToMarker(condition, " ", 1);
String setEventValue = selectFromMarkerToMarker(condition, " ", 2);
if (!isDigitStr(setEventValue)) setEventValue = jsonReadStr(configLiveJson, setEventValue);
boolean flag = false;
if (setEventSign == "=") {
flag = incommingEventValue == setEventValue;
}
else if (setEventSign == "!=") {
flag = incommingEventValue != setEventValue;
}
else if (setEventSign == "<") {
flag = incommingEventValue.toFloat() < setEventValue.toFloat();
}
else if (setEventSign == ">") {
flag = incommingEventValue.toFloat() > setEventValue.toFloat();
}
else if (setEventSign == ">=") {
flag = incommingEventValue.toFloat() >= setEventValue.toFloat();
}
else if (setEventSign == "<=") {
flag = incommingEventValue.toFloat() <= setEventValue.toFloat();
}
if (flag) {
//SerialPrint("I", "Scenario", "incomming Event Value: " + incommingEventValue);
//SerialPrint("I", "Scenario", "set Event Value: " + setEventValue);
oneBlock = deleteBeforeDelimiter(oneBlock, "\n");
oneBlock.replace("end", "");
SerialPrint("I", "Scenario", condition + " \n" + oneBlock);
spaceCmdExecute(oneBlock);
}
}
allBlocks = deleteBeforeDelimiter(allBlocks, "end\n");
}
eventBuf = deleteBeforeDelimiter(eventBuf, ",");
}
};
extern Scenario* myScenario;

View File

@@ -3,11 +3,11 @@
//===========Firmware=============================================================================================================================================
#ifdef ESP8266
#define FIRMWARE_NAME "esp8266-iotm"
#define FIRMWARE_VERSION 266
#define FIRMWARE_VERSION 267
#endif
#ifdef ESP32
#define FIRMWARE_NAME "esp32-iotm"
#define FIRMWARE_VERSION 266
#define FIRMWARE_VERSION 267
#endif
#define FLASH_4MB true
@@ -105,4 +105,8 @@ enum LedStatus_t {
enum ConfigType_t {
CT_CONFIG,
CT_SCENARIO
};
};
//07.11.2020
//RAM: [===== ] 46.8% (used 38376 bytes from 81920 bytes)
//Flash: [===== ] 54.2% (used 566004 bytes from 1044464 bytes)

View File

@@ -93,7 +93,7 @@ extern void servo_();
extern void setLedStatus(LedStatus_t);
//Scenario
extern void eventGen(String event_name, String number);
extern void eventGen2(String eventName, String eventValue);
extern String add_set(String param_name);
//Timers

View File

@@ -52,7 +52,7 @@ class ButtonInClass : public LineParsing {
}
void switchChangeVirtual(String key, String state) {
eventGen(key, "");
eventGen2(key, state);
jsonWriteInt(configLiveJson, key, state.toInt());
publishStatus(key, state);
}

View File

@@ -32,7 +32,7 @@ public:
else {
digitalWrite(pinInt, !state.toInt());
}
eventGen(key, "");
eventGen2(key, state);
jsonWriteInt(configLiveJson, key, state.toInt());
publishStatus(key, state);
}

View File

@@ -16,13 +16,13 @@ class InputClass : public LineParsing {
}
void inputSetFloat(String key, String state) {
eventGen(key, "");
eventGen2(key, state);
jsonWriteFloat(configLiveJson, key, state.toFloat());
publishStatus(key, state);
}
void inputSetStr(String key, String state) {
eventGen(key, "");
eventGen2(key, state);
jsonWriteStr(configLiveJson, key, state);
publishStatus(key, state);
}

View File

@@ -15,7 +15,7 @@ class OutputTextClass : public LineParsing {
void OutputModuleChange(String key, String state) {
state.replace("#", " ");
eventGen(key, "");
eventGen2(key, state);
jsonWriteStr(configLiveJson, key, state);
publishStatus(key, state);
}

View File

@@ -22,7 +22,7 @@ class PwmOutClass : public LineParsing {
void pwmChange(String key, String pin, String state) {
int pinInt = pin.toInt();
analogWrite(pinInt, state.toInt());
eventGen(key, "");
eventGen2(key, state);
jsonWriteInt(configLiveJson, key, state.toInt());
publishStatus(key, state);
}

View File

@@ -26,7 +26,7 @@ class SensorAnalogClass : public SensorConvertingClass {
#endif
value = this->mapping(key, value);
float valueFl = this->correction(key, value);
eventGen(key, "");
eventGen2(key, String(valueFl));
jsonWriteStr(configLiveJson, key, String(valueFl));
publishStatus(key, String(valueFl));
SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl));

View File

@@ -25,7 +25,7 @@ class SensorBme280Class : public SensorConvertingClass {
float value;
value = bme.readTemperature();
float valueFl = this->correction(key, value);
eventGen(key, "");
eventGen2(key, String(valueFl));
jsonWriteStr(configLiveJson, key, String(valueFl));
publishStatus(key, String(valueFl));
SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl));
@@ -35,7 +35,7 @@ class SensorBme280Class : public SensorConvertingClass {
float value;
value = bme.readHumidity();
float valueFl = this->correction(key, value);
eventGen(key, "");
eventGen2(key, String(valueFl));
jsonWriteStr(configLiveJson, key, String(valueFl));
publishStatus(key, String(valueFl));
SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl));
@@ -46,7 +46,7 @@ class SensorBme280Class : public SensorConvertingClass {
value = bme.readPressure();
value = value / 1.333224 / 100;
float valueFl = this->correction(key, value);
eventGen(key, "");
eventGen2(key, String(valueFl));
jsonWriteStr(configLiveJson, key, String(valueFl));
publishStatus(key, String(valueFl));
SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl));

View File

@@ -26,7 +26,7 @@ class SensorBmp280Class : public SensorConvertingClass {
bmp_temp->getEvent(&temp_event);
value = temp_event.temperature;
float valueFl = this->correction(key, value);
eventGen(key, "");
eventGen2(key, String(valueFl));
jsonWriteStr(configLiveJson, key, String(valueFl));
publishStatus(key, String(valueFl));
SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl));
@@ -39,7 +39,7 @@ class SensorBmp280Class : public SensorConvertingClass {
value = pressure_event.pressure;
value = value / 1.333224;
float valueFl = this->correction(key, value);
eventGen(key, "");
eventGen2(key, String(valueFl));
jsonWriteStr(configLiveJson, key, String(valueFl));
publishStatus(key, String(valueFl));
SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl));

View File

@@ -41,7 +41,7 @@ class SensorDhtClass : public SensorConvertingClass {
if (String(value) != "nan") {
//value = this->mapping(key, value);
float valueFl = this->correction(key, value);
eventGen(key, "");
eventGen2(key, String(valueFl));
jsonWriteStr(configLiveJson, key, String(valueFl));
publishStatus(key, String(valueFl));
SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl));
@@ -65,7 +65,7 @@ class SensorDhtClass : public SensorConvertingClass {
if (String(value) != "nan") {
//value = this->mapping(key, value);
float valueFl = this->correction(key, value);
eventGen(key, "");
eventGen2(key, String(valueFl));
jsonWriteStr(configLiveJson, key, String(valueFl));
publishStatus(key, String(valueFl));
SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl));

View File

@@ -35,7 +35,7 @@
// }
//
// int valueFl = this->correction(key, value);
// eventGen(key, "");
// eventGen2(key, String(valueFl));
// jsonWriteStr(configLiveJson, key, String(valueFl));
// publishStatus(key, String(valueFl));
// SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl) + ", Slave dev addr: " + String(slaveAddress) + ", Register: " + String(regAddress));

View File

@@ -40,7 +40,7 @@ class SensorUltrasonic : public SensorConvertingClass {
value = this->mapping(key, value);
float valueFl = this->correction(key, value);
eventGen(key, "");
eventGen2(key, String(valueFl));
jsonWriteStr(configLiveJson, key, String(valueFl));
publishStatus(key, String(valueFl));
SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl));