diff --git a/data/config.json b/data/config.json
index bf6da577..592a7138 100644
--- a/data/config.json
+++ b/data/config.json
@@ -13,7 +13,7 @@
"mqttUser": "rise",
"mqttPass": "23ri22se32",
"scen": "1",
- "telegramApi": "1425283609:AAFf3YO8ouCJF23kU8CMiU7XXy21MFhbn9w",
+ "telegramApi": "1416711569:AAEI0j83GmXqwzb_gnK1B0Am0gDwZoJt5xo",
"telegonof": "0",
"weblogin": "admin",
"webpass": "admin",
diff --git a/data/presets/dal.s.txt b/data/presets/dal.s.txt
index 43f05cc5..dc4c8c07 100644
--- a/data/presets/dal.s.txt
+++ b/data/presets/dal.s.txt
@@ -1,6 +1,8 @@
temp > inputU
button 0
+telegram нагрев#выключен 1
end
temp < inputL
button 1
+telegram нагрев#включен 1
end
\ No newline at end of file
diff --git a/data/presets/dht.c.txt b/data/presets/dht.c.txt
index 2c9acd11..35f8dd19 100644
--- a/data/presets/dht.c.txt
+++ b/data/presets/dht.c.txt
@@ -1,5 +1,5 @@
0;dht-hum;hum;anydataHum;Теплица;Влажность;1;pin[2];type[dht11];c[1]
-0;logging;log;chart;Теплица;Влажность;2;val[hum];int[60];cnt[100]
+0;logging;log;chart;Теплица;История;2;val[hum];int[60];cnt[100]
0;input-digit;inputU;inputDigit;Теплица;Верхний#порог;3;st[45]
0;input-digit;inputL;inputDigit;Теплица;Нижний#порог;4;st[35]
0;button-out;button;toggle;Теплица;Полив;5;pin[12];st[0]
\ No newline at end of file
diff --git a/data/presets/dht.s.txt b/data/presets/dht.s.txt
index bbf78407..f69cdc54 100644
--- a/data/presets/dht.s.txt
+++ b/data/presets/dht.s.txt
@@ -1,6 +1,8 @@
hum > inputU
button 0
+telegram полив#выключен 1
end
hum < inputL
button 1
+telegram полив#включен 1
end
\ No newline at end of file
diff --git a/data/set.device.json b/data/set.device.json
index 345d62eb..4ba722d1 100644
--- a/data/set.device.json
+++ b/data/set.device.json
@@ -87,8 +87,8 @@
"style": "display:inline",
"title": {
"#": "Выберите пресет из списка",
- "/set?addPreset=dal.c": "1.Термостат на основе ds18b20 (устройство держит заданный уровень температуры)",
- "/set?addPreset=dht.c": "2.Контроль влажности на основе DHT (устройство держит заданный уровень влажности)"
+ "/set?addPreset=dal.c": "1.Термостат на основе ds18b20 с оповещением в телеграм",
+ "/set?addPreset=dht.c": "2.Контроль влажности на основе DHT с оповещением в телеграм"
}
},
{
diff --git a/include/Class/ScenarioClass.h b/include/Class/ScenarioClass.h
deleted file mode 100644
index b3a1f064..00000000
--- a/include/Class/ScenarioClass.h
+++ /dev/null
@@ -1,128 +0,0 @@
-#pragma once
-#include
-#include "Cmd.h"
-#include "Global.h"
-
-class Scenario {
-protected:
- String _scenarioTmp;
- String _condition;
- String _conditionParam;
- String _conditionSign;
- String _conditionValue;
- String _scenBlok;
- String _event;
- String _eventParam;
- String _eventValue;
-
-public:
- Scenario() : _scenarioTmp{ "" },
- _condition{ "" },
- _conditionParam{ "" },
- _conditionSign{ "" },
- _conditionValue{ "" },
- _scenBlok{ "" },
- _event{ "" },
- _eventParam{ "" },
- _eventValue{ "" } {};
-
- void load() {
- _scenarioTmp = scenario;
- }
-
- void calculate1() {
- _scenBlok = selectToMarker(_scenarioTmp, "end\n");
- _condition = selectToMarker(_scenBlok, "\n");
- _eventParam = selectToMarker(eventBuf, ",");
- }
-
- bool isIncommingEventInScenario() {
- bool ret = false;
- if (_condition.indexOf(_eventParam) != -1) {
- ret = true;
- }
- return ret;
- }
-
- void calculate2() {
- _scenarioTmp += "\n";
- _scenarioTmp.replace("\r\n", "\n");
- _scenarioTmp.replace("\r", "\n");
-
- _conditionParam = selectFromMarkerToMarker(_condition, " ", 0);
- _conditionSign = selectFromMarkerToMarker(_condition, " ", 1);
- _conditionValue = selectFromMarkerToMarker(_condition, " ", 2);
- if (!isDigitStr(_conditionValue)) _conditionValue = jsonReadStr(configLiveJson, _conditionValue);
- _eventValue = jsonReadStr(configLiveJson, _conditionParam);
- }
-
- void delOneScenBlock() {
- _scenarioTmp = deleteBeforeDelimiter(_scenarioTmp, "end\n");
- }
-
- void delOneEvent() {
- eventBuf = deleteBeforeDelimiter(eventBuf, ",");
- }
-
- bool isConditionSatisfied() {
- boolean flag = false;
-
- if (_conditionSign == "=") {
- flag = _eventValue == _conditionValue;
- }
- else if (_conditionSign == "!=") {
- flag = _eventValue != _conditionValue;
- }
- else if (_conditionSign == "<") {
- flag = _eventValue.toFloat() < _conditionValue.toFloat();
- }
- else if (_conditionSign == ">") {
- flag = _eventValue.toFloat() > _conditionValue.toFloat();
- }
- else if (_conditionSign == ">=") {
- flag = _eventValue.toFloat() >= _conditionValue.toFloat();
- }
- else if (_conditionSign == "<=") {
- flag = _eventValue.toFloat() <= _conditionValue.toFloat();
- }
-
- if (flag) {
- //SerialPrint("I", "Scenario", "event value: " + _eventValue);
- //SerialPrint("I", "Scenario", "condition value: " + _conditionValue);
- SerialPrint("I", "Scenario", "event: " + _condition);
- }
-
- return flag;
- }
-
- void loop() {
- if (!this->isScenarioEnabled()) {
- return;
- }
- this->load(); //после этого мы получили все сценарии
- while (_scenarioTmp.length() > 1) {
- this->calculate1(); //расчет необходимый для ответа на следующий вопрос
- if (this->isIncommingEventInScenario()) { //если вошедшее событие есть в сценарии
- this->calculate2();
- if (this->isConditionSatisfied()) { //если вошедшее событие выполняет условие сценария
- _scenBlok = deleteBeforeDelimiter(_scenBlok, "\n");
- String forPrint = _scenBlok;
- forPrint.replace("end", "");
- forPrint.replace("\r\n", "");
- forPrint.replace("\r", "");
- forPrint.replace("\n", "");
- SerialPrint("I", "Scenario", "making: " + forPrint);
- spaceCmdExecute(_scenBlok);
- }
- }
- this->delOneScenBlock(); //удалим использованный блок
- }
- this->delOneEvent();
- }
-
- bool isScenarioEnabled() {
- return jsonReadBool(configSetupJson, "scen") && eventBuf != "";
- }
-};
-
-extern Scenario* myScenario;
\ No newline at end of file
diff --git a/include/Class/ScenarioClass2.h b/include/Class/ScenarioClass2.h
new file mode 100644
index 00000000..4b7434fb
--- /dev/null
+++ b/include/Class/ScenarioClass2.h
@@ -0,0 +1,68 @@
+#pragma once
+#include
+#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, ",");
+
+ while (allBlocks.length() > 1) {
+ String oneBlock = selectToMarker(allBlocks, "end\n");
+ String condition = selectToMarker(oneBlock, "\n");
+
+ String setEvent = selectFromMarkerToMarker(condition, " ", 0);
+ 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) {
+
+ 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 + " set:\n" + oneBlock);
+ spaceCmdExecute(oneBlock);
+ }
+ }
+ allBlocks = deleteBeforeDelimiter(allBlocks, "end\n");
+ }
+ eventBuf = deleteBeforeDelimiter(eventBuf, ",");
+ }
+};
+
+extern Scenario* myScenario;
\ No newline at end of file
diff --git a/include/Telegram.h b/include/Telegram.h
index 69a75811..9fd18857 100644
--- a/include/Telegram.h
+++ b/include/Telegram.h
@@ -5,4 +5,5 @@ extern void sendTelegramMsg();
extern void telegramInit();
extern void handleTelegram();
extern bool isTelegramEnabled();
-extern void telegramMsgParse(String msg);
\ No newline at end of file
+extern void telegramMsgParse(String msg);
+extern String returnListOfParams();
\ No newline at end of file
diff --git a/src/Class/ScenarioClass.cpp b/src/Class/ScenarioClass2.cpp
similarity index 72%
rename from src/Class/ScenarioClass.cpp
rename to src/Class/ScenarioClass2.cpp
index b7de405e..113a4ee3 100644
--- a/src/Class/ScenarioClass.cpp
+++ b/src/Class/ScenarioClass2.cpp
@@ -1,9 +1,10 @@
-#include "Class/ScenarioClass.h"
+#include "Class/ScenarioClass2.h"
Scenario* myScenario;
void eventGen(String event_name, String number) {
if (!jsonReadBool(configSetupJson, "scen")) {
return;
}
+ SerialPrint("", "", event_name);
eventBuf += event_name + number + ",";
}
\ No newline at end of file
diff --git a/src/Telegram.cpp b/src/Telegram.cpp
index 46973e42..89425e5a 100644
--- a/src/Telegram.cpp
+++ b/src/Telegram.cpp
@@ -43,28 +43,70 @@ void handleTelegram() {
}
void telegramMsgParse(String msg) {
- SerialPrint("<-", "Telegram", "chat ID: " + String(jsonReadInt(configSetupJson, "chatId")) + ", msg: " + String(msg));
- if (msg.indexOf("order") != -1) {
- msg = deleteBeforeDelimiter(msg, " ");
+ if (msg.indexOf("set") != -1) {
+ msg = deleteBeforeDelimiter(msg, "_");
+ msg.replace("_", " ");
orderBuf += String(msg) + ",";
myBot->sendMessage(jsonReadInt(configSetupJson, "chatId"), "order done");
+ SerialPrint("<-", "Telegram", "chat ID: " + String(jsonReadInt(configSetupJson, "chatId")) + ", msg: " + String(msg));
}
else if (msg.indexOf("get") != -1) {
- msg = deleteBeforeDelimiter(msg, " ");
+ msg = deleteBeforeDelimiter(msg, "_");
myBot->sendMessage(jsonReadInt(configSetupJson, "chatId"), jsonReadStr(configLiveJson, msg));
+ SerialPrint("<-", "Telegram", "chat ID: " + String(jsonReadInt(configSetupJson, "chatId")) + ", msg: " + String(msg));
+ }
+ else if (msg.indexOf("all") != -1) {
+ String list = returnListOfParams();
+ myBot->sendMessage(jsonReadInt(configSetupJson, "chatId"), list);
+ SerialPrint("<-", "Telegram", "chat ID: " + String(jsonReadInt(configSetupJson, "chatId")) + "\n" + list);
}
else {
- myBot->sendMessage(jsonReadInt(configSetupJson, "chatId"), "wrong order, use 'get id' to get value, or 'order id value' to send order");
+ myBot->sendMessage(jsonReadInt(configSetupJson, "chatId"), "Wrong order, use /all to get all values, /get_id to get value, or /set_id_value to set value");
}
}
void sendTelegramMsg() {
String msg = sCmd.next();
+ String type = sCmd.next();
msg.replace("#", " ");
- myBot->sendMessage(jsonReadInt(configSetupJson, "chatId"), msg);
- SerialPrint("<-", "Telegram", "chat ID: " + String(jsonReadInt(configSetupJson, "chatId")) + ", msg: " + msg);
+ if (type == "1") {
+ static String prevMsg;
+ if (prevMsg != msg) {
+ prevMsg = msg;
+ myBot->sendMessage(jsonReadInt(configSetupJson, "chatId"), msg);
+ SerialPrint("<-", "Telegram", "chat ID: " + String(jsonReadInt(configSetupJson, "chatId")) + ", msg: " + msg);
+ }
+ } else if (type == "2") {
+ myBot->sendMessage(jsonReadInt(configSetupJson, "chatId"), msg);
+ SerialPrint("<-", "Telegram", "chat ID: " + String(jsonReadInt(configSetupJson, "chatId")) + ", msg: " + msg);
+ }
}
bool isTelegramEnabled() {
return jsonReadBool(configSetupJson, "telegonof");
+}
+
+
+String returnListOfParams() {
+ String cmdStr = readFile(DEVICE_CONFIG_FILE, 4096);
+ cmdStr += "\r\n";
+ cmdStr.replace("\r\n", "\n");
+ cmdStr.replace("\r", "\n");
+ int count = 0;
+ String out;
+ while (cmdStr.length()) {
+ String buf = selectToMarker(cmdStr, "\n");
+ count++;
+ if (count > 1) {
+ String id = selectFromMarkerToMarker(buf, ";", 2);
+ String value = jsonReadStr(configLiveJson, id);
+ String page = selectFromMarkerToMarker(buf, ";", 4);
+ page.replace("#", " ");
+ String name = selectFromMarkerToMarker(buf, ";", 5);
+ name.replace("#", " ");
+ out += page + " " + " " + name + " " + value + "\n";
+ }
+ cmdStr = deleteBeforeDelimiter(cmdStr, "\n");
+ }
+ return out;
}
\ No newline at end of file
diff --git a/src/Utils/statUtils.cpp b/src/Utils/statUtils.cpp
index af789650..f924ec05 100644
--- a/src/Utils/statUtils.cpp
+++ b/src/Utils/statUtils.cpp
@@ -68,7 +68,7 @@ String addNewDevice() {
//==============================================
jsonWriteStr(json, "uniqueId", mac);
jsonWriteStr(json, "name", FIRMWARE_NAME);
- jsonWriteInt(json, "model", FIRMWARE_VERSION);
+ jsonWriteStr(json, "model", getChipId());
//==============================================
http.begin(client, serverIP + F(":8082/api/devices/"));
http.setAuthorization("admin", "admin");
diff --git a/src/main.cpp b/src/main.cpp
index fef52869..c10b8cbc 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -5,7 +5,7 @@
#include "Bus.h"
#include "Class/CallBackTest.h"
#include "Class/NotAsync.h"
-#include "Class/ScenarioClass.h"
+#include "Class/ScenarioClass2.h"
#include "Cmd.h"
#include "Global.h"
#include "Init.h"