From 9ac72f14e065d17d7ac6a029fda02e59e98950da Mon Sep 17 00:00:00 2001 From: Dmitry Borisenko <49808844+DmitryBorisenko33@users.noreply.github.com> Date: Fri, 18 Dec 2020 14:28:31 +0100 Subject: [PATCH] telegram --- include/Global.h | 1 + src/Global.cpp | 5 +++-- src/Telegram.cpp | 22 ++++++++++------------ src/Web.cpp | 11 +++++------ 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/include/Global.h b/include/Global.h index b4ca622a..bdd63086 100644 --- a/include/Global.h +++ b/include/Global.h @@ -54,6 +54,7 @@ extern String configSetupJson; //все настройки extern String configLiveJson; //все данные с датчиков (связан с mqtt) extern String configStoreJson; //все данные которые должны сохраняться extern String configOptionJson; //для трансфера +extern String telegramMsgJson; extern String getValue(String& key); // Mqtt diff --git a/src/Global.cpp b/src/Global.cpp index 1cd2a46c..93db61b1 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -10,7 +10,7 @@ WiFiClient espClient; PubSubClient mqtt(espClient); StringCommand sCmd; AsyncWebServer server(80); -OneWire *oneWire; +OneWire* oneWire; DallasTemperature sensors; /* @@ -25,6 +25,7 @@ String configSetupJson = "{}"; String configLiveJson = "{}"; String configStoreJson = "{}"; String configOptionJson = "{}"; +String telegramMsgJson = "{}"; // Mqtt String chipId = ""; @@ -70,7 +71,7 @@ String presetName; String serverIP; // Scenario -int scenario_line_status[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; +int scenario_line_status[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; int lastVersion; boolean busScanFlag = false; diff --git a/src/Telegram.cpp b/src/Telegram.cpp index 6663b20c..af81e785 100644 --- a/src/Telegram.cpp +++ b/src/Telegram.cpp @@ -70,23 +70,21 @@ void telegramMsgParse(String msg) { } void sendTelegramMsg() { + String id = sCmd.next(); String msg = sCmd.next(); - String type = sCmd.next(); msg.replace("#", " "); - if (type == "1") { - static String prevMsg; - if (prevMsg != msg) { - prevMsg = msg; - if (msg != "na") { - myBot->sendMessage(jsonReadInt(configSetupJson, "chatId"), msg); - } - SerialPrint("<-", "Telegram", "chat ID: " + String(jsonReadInt(configSetupJson, "chatId")) + ", msg: " + msg); - } - } - else if (type == "2") { + if (id == "often") { myBot->sendMessage(jsonReadInt(configSetupJson, "chatId"), msg); SerialPrint("<-", "Telegram", "chat ID: " + String(jsonReadInt(configSetupJson, "chatId")) + ", msg: " + msg); } + else { + String prevMsg = jsonReadStr(telegramMsgJson, id); + if (prevMsg != msg) { + jsonWriteStr(telegramMsgJson, id, msg); + myBot->sendMessage(jsonReadInt(configSetupJson, "chatId"), msg); + SerialPrint("<-", "Telegram", "chat ID: " + String(jsonReadInt(configSetupJson, "chatId")) + ", msg: " + msg); + } + } } bool isTelegramEnabled() { diff --git a/src/Web.cpp b/src/Web.cpp index 6027fcc5..e3ff767e 100644 --- a/src/Web.cpp +++ b/src/Web.cpp @@ -26,12 +26,11 @@ void web_init() { if (request->hasArg(F("addPreset"))) { addPreset2(request->getParam(F("addPreset"))->value().toInt()); - if (FLASH_SIZE_1MB) { - jsonWriteStr(configSetupJson, F("warning1"), F("

Присеты не доступны, модуль на 1mb

")); - } - else { - jsonWriteStr(configSetupJson, F("warning1"), F("

Требуется перезагрузка

")); - } +#ifdef FLASH_SIZE_1MB + jsonWriteStr(configSetupJson, F("warning1"), F("

Присеты не доступны, модуль на 1mb

")); +#else + jsonWriteStr(configSetupJson, F("warning1"), F("

Требуется перезагрузка

")); +#endif request->redirect(F("/?set.device")); }