Добавляем расширенные данные к IoTValue и отключение doByInterval при Int = 0 чтоб пользователь не создавал частые генерации событий

This commit is contained in:
2022-06-02 23:17:52 +03:00
parent 1e947eb48d
commit 72c36a25a7
2 changed files with 13 additions and 6 deletions

View File

@@ -6,6 +6,9 @@ struct IoTValue {
float valD = 0;
String valS = "";
bool isDecimal = true;
uint8_t *extBinInfo = NULL; // дополнительные бинарные данные из модуля
size_t extBinInfoSize = 0; // размер дополнительных данных в байтах
};
class IoTItem {
@@ -29,12 +32,13 @@ class IoTItem {
unsigned long prevMillis;
unsigned long difference;
IoTValue value; // хранение основного значения, котрое обновляется из сценария, execute(), loop() или doByInterval()
IoTValue value; // хранение основного значения, которое обновляется из сценария, execute(), loop() или doByInterval()
bool iAmDead = false; // признак необходимости удалить объект из базы
bool iAmLocal = true; // признак локальной переменной
bool needSave = false;
bool enableDoByInt = true;
virtual IoTGpio* getGpioDriver();
virtual iarduino_RTC_BASE* getRtcDriver();

View File

@@ -7,6 +7,7 @@
IoTItem::IoTItem(String parameters) {
jsonRead(parameters, F("int"), _interval);
if (_interval == 0) enableDoByInt = false;
_interval = _interval * 1000;
jsonRead(parameters, F("subtype"), _subtype);
jsonRead(parameters, F("id"), _id);
@@ -57,11 +58,13 @@ String IoTItem::getValue() {
}
void IoTItem::loop() {
currentMillis = millis();
difference = currentMillis - prevMillis;
if (difference >= _interval) {
prevMillis = millis();
this->doByInterval();
if (enableDoByInt) {
currentMillis = millis();
difference = currentMillis - prevMillis;
if (difference >= _interval) {
prevMillis = millis();
this->doByInterval();
}
}
}