mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-30 20:09:14 +03:00
Merge pull request #110 from biveraxe/ver3
Работаем со временем в сценариях и температурой сразу на нескольких линиях
This commit is contained in:
@@ -10,10 +10,14 @@ class Scenario {
|
|||||||
if (!jsonReadBool(configSetupJson, "scen")) {
|
if (!jsonReadBool(configSetupJson, "scen")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String allBlocks = scenario;
|
String allBlocks = scenario;
|
||||||
allBlocks += "\n";
|
allBlocks += "\n";
|
||||||
|
|
||||||
String incommingEvent = selectToMarker(eventBuf, ",");
|
String incommingEvent = selectToMarker(eventBuf, ",");
|
||||||
|
if (incommingEvent == "") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
String incommingEventKey = selectToMarker(incommingEvent, " ");
|
String incommingEventKey = selectToMarker(incommingEvent, " ");
|
||||||
String incommingEventValue = selectToMarkerLast(incommingEvent, " ");
|
String incommingEventValue = selectToMarkerLast(incommingEvent, " ");
|
||||||
@@ -159,18 +163,20 @@ class Scenario {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
bool isScenarioNeedToDo(String &condition, String &incommingEventKey, String &incommingEventValue, int type) {
|
bool isScenarioNeedToDo(String &condition, String &incommingEventKey, String &incommingEventValue, int type) {
|
||||||
bool res = false;
|
if (condition == "") return false;
|
||||||
String setEventKey = selectFromMarkerToMarker(condition, " ", 0);
|
String setEventKey = selectFromMarkerToMarker(condition, " ", 0);
|
||||||
if (isEventExist(incommingEventKey, setEventKey)) {
|
if (isEventExist(incommingEventKey, setEventKey)) {
|
||||||
String setEventSign;
|
String setEventSign;
|
||||||
String setEventValue;
|
String setEventValue;
|
||||||
if (type == 1) preCalculation(condition, setEventSign, setEventValue);
|
String cloneOfIncommingEventValue = incommingEventValue; //клонируем для изменения в preCalculation и передачи для проверки по условиям
|
||||||
|
if (type == 1) preCalculation(condition, setEventSign, cloneOfIncommingEventValue, setEventValue);
|
||||||
if (type == 2) preCalculationGisteresis(condition, setEventSign, setEventValue);
|
if (type == 2) preCalculationGisteresis(condition, setEventSign, setEventValue);
|
||||||
if (isConditionMatch(setEventSign, incommingEventValue, setEventValue)) {
|
if (isConditionMatch(setEventSign, cloneOfIncommingEventValue, setEventValue)) {
|
||||||
res = true;
|
return true;
|
||||||
}
|
}
|
||||||
|
//SerialPrint("I", "incommingEventKey", incommingEventKey);
|
||||||
}
|
}
|
||||||
return res;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isScenarioNeedToDoJson(String &condition) {
|
bool isScenarioNeedToDoJson(String &condition) {
|
||||||
@@ -178,8 +184,9 @@ class Scenario {
|
|||||||
String setEventKey = selectFromMarkerToMarker(condition, " ", 0);
|
String setEventKey = selectFromMarkerToMarker(condition, " ", 0);
|
||||||
String setEventSign;
|
String setEventSign;
|
||||||
String setEventValue;
|
String setEventValue;
|
||||||
preCalculation(condition, setEventSign, setEventValue);
|
|
||||||
String jsonValue = getValue(setEventKey);
|
String jsonValue = getValue(setEventKey);
|
||||||
|
preCalculation(condition, setEventSign, jsonValue, setEventValue);
|
||||||
if (isConditionMatch(setEventSign, jsonValue, setEventValue)) {
|
if (isConditionMatch(setEventSign, jsonValue, setEventValue)) {
|
||||||
res = true;
|
res = true;
|
||||||
}
|
}
|
||||||
@@ -200,13 +207,24 @@ class Scenario {
|
|||||||
// return res;
|
// return res;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
void preCalculation(String &condition, String &setEventSign, String &setEventValue) {
|
void preCalculation(String &condition, String &setEventSign, String &incommingEventValue, String &setEventValue) {
|
||||||
setEventSign = selectFromMarkerToMarker(condition, " ", 1);
|
setEventSign = selectFromMarkerToMarker(condition, " ", 1);
|
||||||
setEventValue = selectFromMarkerToMarker(condition, " ", 2);
|
setEventValue = selectFromMarkerToMarker(condition, " ", 2);
|
||||||
|
|
||||||
if (!isDigitDotCommaStr(setEventValue)) {
|
if (!isDigitDotCommaStr(setEventValue)) {
|
||||||
|
if (isTimeStr(incommingEventValue)) {
|
||||||
|
int hhLStr = selectToMarker(incommingEventValue, ":").toInt();
|
||||||
|
int mmLStr = selectToMarkerLast(incommingEventValue, ":").toInt();
|
||||||
|
int hhRStr = selectToMarker(setEventValue, ":").toInt();
|
||||||
|
int mmRStr = selectToMarkerLast(setEventValue, ":").toInt();
|
||||||
|
|
||||||
|
incommingEventValue = hhLStr*60 + mmLStr;
|
||||||
|
setEventValue = hhRStr*60 + mmRStr;
|
||||||
|
} else {
|
||||||
setEventValue = getValue(setEventValue);
|
setEventValue = getValue(setEventValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void preCalculationGisteresis(String &condition, String &setEventSign, String &setEventValue) {
|
void preCalculationGisteresis(String &condition, String &setEventSign, String &setEventValue) {
|
||||||
setEventSign = selectFromMarkerToMarker(condition, " ", 1);
|
setEventSign = selectFromMarkerToMarker(condition, " ", 1);
|
||||||
@@ -228,14 +246,20 @@ class Scenario {
|
|||||||
|
|
||||||
bool isEventExist(String &incommingEventKey, String &setEventKey) {
|
bool isEventExist(String &incommingEventKey, String &setEventKey) {
|
||||||
bool res = false;
|
bool res = false;
|
||||||
if (incommingEventKey == setEventKey) {
|
if (incommingEventKey != "not found" && incommingEventKey == setEventKey) {
|
||||||
res = true;
|
res = true;
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isConditionMatch(String &setEventSign, String &incommingEventValue, String &setEventValue) {
|
bool isConditionMatch(String &setEventSign, String &incommingEventValue, String &setEventValue) {
|
||||||
|
if (setEventValue == "no value") return false;
|
||||||
|
|
||||||
boolean flag = false;
|
boolean flag = false;
|
||||||
|
//SerialPrint("I", "setEventSign", setEventSign);
|
||||||
|
//SerialPrint("I", "incommingEventValue", incommingEventValue);
|
||||||
|
//SerialPrint("I", "setEventValue", setEventValue);
|
||||||
|
//SerialPrint("I", "==========", "===============");
|
||||||
if (setEventSign == "=") {
|
if (setEventSign == "=") {
|
||||||
flag = incommingEventValue == setEventValue;
|
flag = incommingEventValue == setEventValue;
|
||||||
} else if (setEventSign == "!=") {
|
} else if (setEventSign == "!=") {
|
||||||
@@ -249,6 +273,7 @@ class Scenario {
|
|||||||
} else if (setEventSign == "<=") {
|
} else if (setEventSign == "<=") {
|
||||||
flag = incommingEventValue.toFloat() <= setEventValue.toFloat();
|
flag = incommingEventValue.toFloat() <= setEventValue.toFloat();
|
||||||
}
|
}
|
||||||
|
|
||||||
return flag;
|
return flag;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ size_t itemsCount(String& str, const char* delim);
|
|||||||
|
|
||||||
boolean isDigitStr(const String& str);
|
boolean isDigitStr(const String& str);
|
||||||
|
|
||||||
|
boolean isTimeStr(const String& str);
|
||||||
|
|
||||||
boolean isDigitDotCommaStr(const String& str);
|
boolean isDigitDotCommaStr(const String& str);
|
||||||
|
|
||||||
String prettyBytes(size_t size);
|
String prettyBytes(size_t size);
|
||||||
|
|||||||
@@ -32,6 +32,10 @@ class SensorDallas {
|
|||||||
String _addr;
|
String _addr;
|
||||||
unsigned int _pin;
|
unsigned int _pin;
|
||||||
unsigned int _index;
|
unsigned int _index;
|
||||||
|
|
||||||
|
//для работы библиотеки с несколькими линиями необходимо обеспечить каждый экземпляр класса ссылками на объекты настроенные на эти линии
|
||||||
|
OneWire* oneWire;
|
||||||
|
DallasTemperature* sensors;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern MySensorDallasVector* mySensorDallas2;
|
extern MySensorDallasVector* mySensorDallas2;
|
||||||
|
|||||||
@@ -155,6 +155,18 @@ boolean isDigitStr(const String& str) {
|
|||||||
return str.length();
|
return str.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean isTimeStr(const String& str) {
|
||||||
|
|
||||||
|
for (size_t i = 0; i < str.length(); i++) {
|
||||||
|
char latter = str.charAt(i);
|
||||||
|
if (!isDigit(latter) && latter != ':') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (str.charAt(2) != ':') return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
boolean isDigitDotCommaStr(const String& str) {
|
boolean isDigitDotCommaStr(const String& str) {
|
||||||
for (size_t i = 0; i < str.length(); i++) {
|
for (size_t i = 0; i < str.length(); i++) {
|
||||||
char latter = str.charAt(i);
|
char latter = str.charAt(i);
|
||||||
|
|||||||
@@ -6,12 +6,13 @@
|
|||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include "DallasTemperature.h"
|
#include "DallasTemperature.h"
|
||||||
#include "Utils/StringUtils.h"
|
#include "Utils/StringUtils.h"
|
||||||
|
#include <map>
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
//ИНТЕГРИРУЮ: переменные необходимые для работы интегрируемой библиотеки. Аналог Arduino
|
//ИНТЕГРИРУЮ: переменные необходимые для работы интегрируемой библиотеки. Аналог Arduino
|
||||||
OneWire* oneWire;
|
std::map<int, OneWire*> oneWireTemperatureArray;
|
||||||
DallasTemperature sensors;
|
std::map<int, DallasTemperature*> sensorsTemperatureArray;
|
||||||
|
|
||||||
//ИНТЕГРИРУЮ:
|
//ИНТЕГРИРУЮ:
|
||||||
//Для каждого датчика указанного в конфигурации вызывается конструктор для настройки перед запуском. Аналог функции setup() в Arduino.
|
//Для каждого датчика указанного в конфигурации вызывается конструктор для настройки перед запуском. Аналог функции setup() в Arduino.
|
||||||
@@ -26,10 +27,20 @@ SensorDallas::SensorDallas(unsigned long interval, unsigned int pin, unsigned in
|
|||||||
|
|
||||||
//ИНТЕГРИРУЮ:
|
//ИНТЕГРИРУЮ:
|
||||||
//вызываем необходимые инициирующие функции интегрируемой библиотеки
|
//вызываем необходимые инициирующие функции интегрируемой библиотеки
|
||||||
|
//учитываем, что библиотека может работать с несколькими линиями на разных пинах, поэтому инициируем библиотеку, если линия ранее не использовалась
|
||||||
|
if (oneWireTemperatureArray.find(_pin) == oneWireTemperatureArray.end()) {
|
||||||
oneWire = new OneWire((uint8_t)_pin);
|
oneWire = new OneWire((uint8_t)_pin);
|
||||||
sensors.setOneWire(oneWire);
|
sensors = new DallasTemperature();
|
||||||
sensors.begin();
|
sensors->setOneWire(oneWire);
|
||||||
sensors.setResolution(12);
|
sensors->begin();
|
||||||
|
sensors->setResolution(12);
|
||||||
|
|
||||||
|
oneWireTemperatureArray[_pin] = oneWire;
|
||||||
|
sensorsTemperatureArray[_pin] = sensors;
|
||||||
|
} else {
|
||||||
|
oneWire = oneWireTemperatureArray[_pin];
|
||||||
|
sensors = sensorsTemperatureArray[_pin];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//ИНТЕГРИРУЮ: оставляем как есть или развиваем, если нужно правильно завершить работу с интегрируемой библиотекой после отключения датчика
|
//ИНТЕГРИРУЮ: оставляем как есть или развиваем, если нужно правильно завершить работу с интегрируемой библиотекой после отключения датчика
|
||||||
@@ -48,18 +59,18 @@ void SensorDallas::loop() {
|
|||||||
//ИНТЕГРИРУЮ: вызывается из цикла loop каждый установленный временно интервал в параметрах датчика. Необходимо изменить для чтения данных из датчика.
|
//ИНТЕГРИРУЮ: вызывается из цикла loop каждый установленный временно интервал в параметрах датчика. Необходимо изменить для чтения данных из датчика.
|
||||||
void SensorDallas::readDallas() {
|
void SensorDallas::readDallas() {
|
||||||
//запускаем опрос измерений у всех датчиков на линии
|
//запускаем опрос измерений у всех датчиков на линии
|
||||||
sensors.requestTemperatures();
|
sensors->requestTemperatures();
|
||||||
|
|
||||||
//Определяем адрес. Если парамтер addr не установлен, то узнаем адрес по индексу
|
//Определяем адрес. Если парамтер addr не установлен, то узнаем адрес по индексу
|
||||||
DeviceAddress deviceAddress;
|
DeviceAddress deviceAddress;
|
||||||
if (_addr == "") {
|
if (_addr == "") {
|
||||||
sensors.getAddress(deviceAddress, _index);
|
sensors->getAddress(deviceAddress, _index);
|
||||||
} else {
|
} else {
|
||||||
string2hex(_addr.c_str(), deviceAddress);
|
string2hex(_addr.c_str(), deviceAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
//получаем температуру по адресу
|
//получаем температуру по адресу
|
||||||
float value = sensors.getTempC(deviceAddress);
|
float value = sensors->getTempC(deviceAddress);
|
||||||
|
|
||||||
//ИНТЕГРИРУЮ: блок генерации уведомлений в ядре системы. Стоит обратить внимание только на формат выводимого сообщения в консоли.
|
//ИНТЕГРИРУЮ: блок генерации уведомлений в ядре системы. Стоит обратить внимание только на формат выводимого сообщения в консоли.
|
||||||
eventGen2(_key, String(value));
|
eventGen2(_key, String(value));
|
||||||
|
|||||||
Reference in New Issue
Block a user