diff --git a/data/config.json b/data/config.json index 48676490..bf6da577 100644 --- a/data/config.json +++ b/data/config.json @@ -3,8 +3,8 @@ "chipID": "", "apssid": "IoTmanager", "appass": "", - "routerssid": "rise", - "routerpass": "hostel3333", + "routerssid": "VOLODYA", + "routerpass": "BELCHENKO", "timezone": 2, "ntp": "pool.ntp.org", "mqttServer": "91.204.228.124", diff --git a/data/set.device.json b/data/set.device.json index 2b24c230..345d62eb 100644 --- a/data/set.device.json +++ b/data/set.device.json @@ -43,7 +43,7 @@ }, { "type": "h4", - "title": "LittleFS version: 265" + "title": "LittleFS version: 266" }, { "type": "hr" diff --git a/include/Consts.h b/include/Consts.h index 89f366ba..a81d1977 100644 --- a/include/Consts.h +++ b/include/Consts.h @@ -3,11 +3,11 @@ //===========Firmware============================================================================================================================================= #ifdef ESP8266 #define FIRMWARE_NAME "esp8266-iotm" -#define FIRMWARE_VERSION 265 +#define FIRMWARE_VERSION 266 #endif #ifdef ESP32 #define FIRMWARE_NAME "esp32-iotm" -#define FIRMWARE_VERSION 265 +#define FIRMWARE_VERSION 266 #endif #define FLASH_4MB true diff --git a/include/Telegram.h b/include/Telegram.h index 1524373e..69a75811 100644 --- a/include/Telegram.h +++ b/include/Telegram.h @@ -1,6 +1,8 @@ #pragma once +#include "Global.h" extern void sendTelegramMsg(); extern void telegramInit(); extern void handleTelegram(); -extern bool isTelegramEnabled(); \ No newline at end of file +extern bool isTelegramEnabled(); +extern void telegramMsgParse(String msg); \ No newline at end of file diff --git a/src/Class/ScenarioClass.cpp b/src/Class/ScenarioClass.cpp index d066cc62..b7de405e 100644 --- a/src/Class/ScenarioClass.cpp +++ b/src/Class/ScenarioClass.cpp @@ -1,2 +1,9 @@ #include "Class/ScenarioClass.h" -Scenario* myScenario; \ No newline at end of file +Scenario* myScenario; + +void eventGen(String event_name, String number) { + if (!jsonReadBool(configSetupJson, "scen")) { + return; + } + eventBuf += event_name + number + ","; +} \ No newline at end of file diff --git a/src/Scenario.cpp b/src/Scenario.cpp deleted file mode 100644 index ce0ec90d..00000000 --- a/src/Scenario.cpp +++ /dev/null @@ -1,97 +0,0 @@ -#include "Cmd.h" -#include "Global.h" -#include "Class/ScenarioClass.h" - - - -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 eventGen(String event_name, String number) { - if (!jsonReadBool(configSetupJson, "scen")) { - return; - } - 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; -//} - -//button-out1 = 1 -//button-out2 1 -//button-out3 1 -//end \ No newline at end of file diff --git a/src/Telegram.cpp b/src/Telegram.cpp index a79524c2..46973e42 100644 --- a/src/Telegram.cpp +++ b/src/Telegram.cpp @@ -1,5 +1,5 @@ #include "Telegram.h" -#include "Global.h" + CTBot* myBot{ nullptr }; @@ -29,24 +29,38 @@ void handleTelegram() { static unsigned long prevMillis; unsigned long currentMillis = millis(); unsigned long difference = currentMillis - prevMillis; - if (difference >= 1000) { + if (difference >= 5000) { prevMillis = millis(); if (myBot->getNewMessage(msg)) { SerialPrint("->", "Telegram", "chat ID: " + String(msg.sender.id) + ", msg: " + String(msg.text)); jsonWriteInt(configSetupJson, "chatId", msg.sender.id); saveConfig(); - orderBuf += String(msg.text) + ","; - myBot->sendMessage(jsonReadInt(configSetupJson, "chatId"), msg.text); - SerialPrint("<-", "Telegram", "chat ID: " + String(jsonReadInt(configSetupJson, "chatId")) + ", msg: " + String(msg.text)); + telegramMsgParse(String(msg.text)); } } - } + } + } +} + +void telegramMsgParse(String msg) { + SerialPrint("<-", "Telegram", "chat ID: " + String(jsonReadInt(configSetupJson, "chatId")) + ", msg: " + String(msg)); + if (msg.indexOf("order") != -1) { + msg = deleteBeforeDelimiter(msg, " "); + orderBuf += String(msg) + ","; + myBot->sendMessage(jsonReadInt(configSetupJson, "chatId"), "order done"); + } + else if (msg.indexOf("get") != -1) { + msg = deleteBeforeDelimiter(msg, " "); + myBot->sendMessage(jsonReadInt(configSetupJson, "chatId"), jsonReadStr(configLiveJson, msg)); + } + else { + myBot->sendMessage(jsonReadInt(configSetupJson, "chatId"), "wrong order, use 'get id' to get value, or 'order id value' to send order"); } } void sendTelegramMsg() { String msg = sCmd.next(); - msg.replace("#"," "); + msg.replace("#", " "); myBot->sendMessage(jsonReadInt(configSetupJson, "chatId"), msg); SerialPrint("<-", "Telegram", "chat ID: " + String(jsonReadInt(configSetupJson, "chatId")) + ", msg: " + msg); }