From 6ae001232d979dfcf6a8723d5e7a82ffd4811d62 Mon Sep 17 00:00:00 2001 From: Dmitry Borisenko <49808844+DmitryBorisenko33@users.noreply.github.com> Date: Sun, 3 Jan 2021 02:14:12 +0100 Subject: [PATCH] telegram --- data/config.json | 1 + data/set.telegram.json.gz | Bin 857 -> 907 bytes data_ungzip/set.telegram.json | 10 ++++++++++ src/FileSystem.cpp | 2 +- src/Telegram.cpp | 7 +++++-- src/Web.cpp | 6 ++++++ src/items/vLogging.cpp | 6 +++--- 7 files changed, 26 insertions(+), 6 deletions(-) diff --git a/data/config.json b/data/config.json index 1e32fc2a..139fc773 100644 --- a/data/config.json +++ b/data/config.json @@ -21,6 +21,7 @@ "telegramApi": "1416711569:AAEI0j83GmXqwzb_gnK1B0Am0gDwZoJt5xo", "telegonof": "0", "teleginput": "0", + "autos": "1", "weblogin": "admin", "webpass": "admin", "MqttIn": "0", diff --git a/data/set.telegram.json.gz b/data/set.telegram.json.gz index 8386cf0920a5893d9689e849e263f2c930853178..e8810e9b6b47105c6d1a6e5b6fae0e90e9459881 100644 GIT binary patch literal 907 zcmV;619bc!iwFpg5Ak0F0CQz@E_7vVWoL3>Z7ynaZ*Bm!R_{*RFcAMfiFdF-8(#?j znWh$)*w7?COhVhfRsG;LZt69)v&3OVs1i^iG!2buFTg7lwu%B>_X_qK?d&v7Cnamq zn4&cHoqcz|-<{7rn0kcJbeXdXb%N;}D(E>#79!DnKt$-xzYjQ@o{Lp3W{&xp_rpk~ zHO0Bel#2r}q;0xZP`7xc0yeBAG?*_fno-@3HOuk*nHjiFtXPTXPr>ydN`?^0Gv_wXVVuQ6r2 z*!j~DE(^+;UbB$qz9ble*DATZT+^e8L#g^>mz1ldTr2U$h+`nas049|!x^unp^@L@ zt-MoT)T!*MV|9kqvFyk@c)zPd*_OR@e2}!~L%SP=!f;$Hj%)}776ZcsV%CxrNza^ zd7B2Fi}!Ps!F52!qMe{91!<(FW8J2E$b_&lTL&DJS%P~Ih1bXr<|PhX)+5pE=6VJ0 zNPTZ|e`B`f;&KgSUTmVoeVh0>wB$8Vz+GyineCVQ$)iYR`PimmkV7k817xt>@p;H> zOIw7EGq2Y4lSdx5ZOR-l75SAHvagQx6@lQux787Ji9=`sH>PpKIfA|_J0S1KYuVO! ziE6QuKP-FQBmRwH}5q39QOokQa>ds<+&3%o!9wWgCcTCMVLWUSgVU8 zIW;u)jLZ7ynaZ*BmsR^4jbFciKY^c_UX)|lT)-UG@sn8|}!B;|%P@ zg<>2ZopW^l^(lu7j}R)fIBQeOFH}%nuYpsHSSvmefxGhF=d7?CiyX|X@MpyfB9WFf zmLpRR_Q8<0=@@?3;O#cpFv@7ME|)^8YsQk*c>OFS94i*A#p|cwdJ?4|Oe9f;!G|%4 z1D9y0_6F!qnN&C-_wbP6F6s9ZSrR68h$jq_v~l2wLL~1mXW4fs>!f>l5s25AvOR45 z>j<|5I+9oNEbZJe{L=hkS=9z zAadm^|3IE2$oCG(YjrBe@`t)mpFnzw)Uh1H^9`0m`5Uxuva6A}g>oc|ta>CG4^t3( zJuTaJ+KY#~sAXe;c6a8Q$*fySp|#Cj)4-mUo?;}=livSh-`?9rf_Dg;Yv?}Fi;4Md zmu9Chqm(0$W*`J-nV9hw?`PpfI6#T7c!HAf8jUAWIYAT=5%+#LGn?Z<6xl~=3cFG+ zl^$13>bnj;s89ybN9JamV<-jbrM9DH(tQ+$u({NQJSZ~+cOeS5SDmbz9BSE(SW8>A zHrxmLj^N(rQq#e$4)EOAM3Z|a@hYh7_K?pVYNExRm-?xqNMv}}q=8>SYiI6OjET54af$p8g7yZJn3&5dp&j8Gh!1o9k07aTs zgIdwusuguP-~(mcn%jgNeX`e54v0r!Dx)Dv8yuJWRF7|^O?$+w>i%uO5ILkRLLwTh z_0mjFLz%G}vh-*e*r67yvgetNewMessage(msg)) { SerialPrint("->", "Telegram", "chat ID: " + String(msg.sender.id) + ", msg: " + String(msg.text)); - jsonWriteInt(configSetupJson, "chatId", msg.sender.id); - saveConfig(); + if (jsonReadBool(configSetupJson, "autos")) { + jsonWriteInt(configSetupJson, "chatId", msg.sender.id); + saveConfig(); + } telegramMsgParse(String(msg.text)); } } @@ -61,6 +63,7 @@ void telegramMsgParse(String msg) { myBot->sendMessage(jsonReadInt(configSetupJson, "chatId"), list); SerialPrint("<-", "Telegram", "chat ID: " + String(jsonReadInt(configSetupJson, "chatId")) + "\n" + list); } else { + myBot->sendMessage(jsonReadInt(configSetupJson, "chatId"), "ID: " + chipId + ", Name: " + jsonReadStr(configSetupJson, F("name"))); myBot->sendMessage(jsonReadInt(configSetupJson, "chatId"), F("Wrong order, use /all to get all values, /get_id to get value, or /set_id_value to set value")); } } diff --git a/src/Web.cpp b/src/Web.cpp index a1ed35ea..50343648 100644 --- a/src/Web.cpp +++ b/src/Web.cpp @@ -255,6 +255,12 @@ void web_init() { saveConfig(); request->send(200); } + if (request->hasArg("autos")) { + bool value = request->getParam("autos")->value().toInt(); + jsonWriteBool(configSetupJson, "autos", value); + saveConfig(); + request->send(200); + } if (request->hasArg("chatId")) { jsonWriteStr(configSetupJson, "chatId", request->getParam("chatId")->value()); saveConfig(); diff --git a/src/items/vLogging.cpp b/src/items/vLogging.cpp index 51f8a3f7..9edf1710 100644 --- a/src/items/vLogging.cpp +++ b/src/items/vLogging.cpp @@ -62,15 +62,15 @@ void LoggingClass::execute(String keyOrValue) { } if (loggingValue != "") { - if (cnt >= _maxPoints) { //удаляем старую строку и добавляем новую + if (cnt >= _maxPoints) { //удаляем старую строку и добавляем новую String logData = readFile(filename, 20480); //10240 SerialPrint("I", "Logging", "Free heap " + String(ESP.getFreeHeap())); if (logData == "large") { SerialPrint("E", "Logging", "File is very large"); } - //for (int i = 0; i < 5; i++) { + logData = deleteBeforeDelimiter(logData, "\r\n"); - //} + if (timeNow->hasTimeSynced()) { logData += timeNow->getTimeUnix() + " " + loggingValue + "\r\n";