Добавил событие об успешной отправке

This commit is contained in:
avaksru
2022-10-20 10:09:16 +03:00
parent f480295d0c
commit cc92500008
2 changed files with 31 additions and 20 deletions

View File

@@ -9,14 +9,16 @@ public:
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)) {
{
if (WiFi.status() == WL_CONNECTED && (often || !often && _prevMsg != msg))
{
WiFiClient client;
HTTPClient http;
http.begin(client, "http://live-control.com/iotm/telegram.php");
@@ -27,12 +29,16 @@ public:
SerialPrint("<-", F("Telegram"), "chat ID: " + _chatID + ", msg: " + msg);
SerialPrint("->", F("Telegram"), "chat ID: " + _chatID + ", server: " + httpResponseCode);
if (!strstr(payload.c_str(), "{\"ok\":true")) {
value.valD = 1;
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 {
value.valD = 0;
}
else
{
value.valD = 1;
regEvent(value.valD, payload);
}
http.end();
_prevMsg = msg;
@@ -41,7 +47,8 @@ public:
IoTValue execute(String command, std::vector<IoTValue> &param)
{
if (param.size() == 1) {
if (param.size() == 1)
{
String strTmp;
if (param[0].isDecimal && param[0].valS == "")
strTmp = param[0].valD;