mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 22:52:19 +03:00
добавляем функцию отправки сообщений в телеграм для дневного графика
This commit is contained in:
@@ -1,24 +1,19 @@
|
||||
#include "Global.h"
|
||||
#include "classes/IoTItem.h"
|
||||
|
||||
class TelegramLT : public IoTItem
|
||||
{
|
||||
|
||||
public:
|
||||
class TelegramLT : public IoTItem {
|
||||
public:
|
||||
String _prevMsg = "";
|
||||
String _token;
|
||||
String _chatID;
|
||||
|
||||
TelegramLT(String parameters) : IoTItem(parameters)
|
||||
{
|
||||
TelegramLT(String parameters) : IoTItem(parameters) {
|
||||
jsonRead(parameters, "token", _token);
|
||||
jsonRead(parameters, "chatID", _chatID);
|
||||
}
|
||||
|
||||
void sendTelegramMsg(bool often, String msg)
|
||||
{
|
||||
if (WiFi.status() == WL_CONNECTED && (often || !often && _prevMsg != msg))
|
||||
{
|
||||
void sendTelegramMsg(bool often, String msg) {
|
||||
if (WiFi.status() == WL_CONNECTED && (often || !often && _prevMsg != msg)) {
|
||||
WiFiClient client;
|
||||
HTTPClient http;
|
||||
http.begin(client, "http://live-control.com/iotm/telegram.php");
|
||||
@@ -29,14 +24,11 @@ public:
|
||||
SerialPrint("<-", F("Telegram"), "chat ID: " + _chatID + ", msg: " + msg);
|
||||
SerialPrint("->", F("Telegram"), "chat ID: " + _chatID + ", server: " + httpResponseCode);
|
||||
|
||||
if (!strstr(payload.c_str(), "{\"ok\":true"))
|
||||
{
|
||||
if (!strstr(payload.c_str(), "{\"ok\":true")) {
|
||||
value.valD = 0;
|
||||
Serial.printf("Telegram error, msg from server: %s\n", payload.c_str());
|
||||
regEvent(value.valD, payload);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
value.valD = 1;
|
||||
regEvent(value.valD, payload);
|
||||
}
|
||||
@@ -45,27 +37,20 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
IoTValue execute(String command, std::vector<IoTValue> ¶m)
|
||||
{
|
||||
if (param.size() == 1)
|
||||
{
|
||||
IoTValue execute(String command, std::vector<IoTValue> ¶m) {
|
||||
if (param.size() == 1) {
|
||||
String strTmp;
|
||||
if (param[0].isDecimal && param[0].valS == "")
|
||||
strTmp = param[0].valD;
|
||||
else
|
||||
strTmp = param[0].valS;
|
||||
|
||||
if (command == "sendMsg")
|
||||
{
|
||||
if (param.size())
|
||||
{
|
||||
if (command == "sendMsg") {
|
||||
if (param.size()) {
|
||||
sendTelegramMsg(false, strTmp);
|
||||
}
|
||||
}
|
||||
else if (command == "sendOftenMsg")
|
||||
{
|
||||
if (param.size())
|
||||
{
|
||||
} else if (command == "sendOftenMsg") {
|
||||
if (param.size()) {
|
||||
sendTelegramMsg(true, strTmp);
|
||||
}
|
||||
}
|
||||
@@ -76,14 +61,10 @@ public:
|
||||
~TelegramLT(){};
|
||||
};
|
||||
|
||||
void *getAPI_TelegramLT(String subtype, String param)
|
||||
{
|
||||
if (subtype == F("TelegramLT"))
|
||||
{
|
||||
void *getAPI_TelegramLT(String subtype, String param) {
|
||||
if (subtype == F("TelegramLT")) {
|
||||
return new TelegramLT(param);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user