upd telegram_v2

This commit is contained in:
Mit4el
2023-10-07 09:40:45 +03:00
parent 2e3506d67c
commit e35225e7be

View File

@@ -57,21 +57,12 @@ public:
void loop() void loop()
{ {
if (_receiveMsg) if (_receiveMsg && isNetworkActive())
{ {
_myBot->tick(); _myBot->tick();
} }
// Далее вызов doByInterval для обработки комманд // Далее вызов doByInterval для обработки комманд
if (enableDoByInt) IoTItem::loop();
{
currentMillis = millis();
difference = currentMillis - prevMillis;
if (difference >= _interval)
{
prevMillis = millis();
this->doByInterval();
}
}
} }
void doByInterval() void doByInterval()
@@ -80,6 +71,7 @@ public:
IoTValue execute(String command, std::vector<IoTValue> &param) IoTValue execute(String command, std::vector<IoTValue> &param)
{ {
if (!isNetworkActive()) return {};
if (command == "sendMsg") if (command == "sendMsg")
{ {
if (param.size()) if (param.size())
@@ -268,6 +260,7 @@ public:
void sendTelegramMsg(bool often, String msg) void sendTelegramMsg(bool often, String msg)
{ {
if (!isNetworkActive()) return;
if (often) if (often)
{ {
_myBot->sendMessage(msg, _chatID); _myBot->sendMessage(msg, _chatID);
@@ -286,12 +279,14 @@ public:
void sendFoto(uint8_t *buf, uint32_t length, const String &name) void sendFoto(uint8_t *buf, uint32_t length, const String &name)
{ {
if (!isNetworkActive()) return;
_myBot->sendFile(buf, length, FB_PHOTO, name, _chatID); _myBot->sendFile(buf, length, FB_PHOTO, name, _chatID);
SerialPrint("<-", F("Telegram"), "chat ID: " + _chatID + ", send foto from esp-cam"); SerialPrint("<-", F("Telegram"), "chat ID: " + _chatID + ", send foto from esp-cam");
} }
void editFoto(uint8_t *buf, uint32_t length, const String &name) void editFoto(uint8_t *buf, uint32_t length, const String &name)
{ {
if (!isNetworkActive()) return;
_myBot->editFile(buf, length, FB_PHOTO, name, _myBot->lastBotMsg(), _chatID); _myBot->editFile(buf, length, FB_PHOTO, name, _myBot->lastBotMsg(), _chatID);
SerialPrint("<-", F("Telegram"), "chat ID: " + _chatID + ", edit foto from esp-cam"); SerialPrint("<-", F("Telegram"), "chat ID: " + _chatID + ", edit foto from esp-cam");
} }
@@ -332,13 +327,13 @@ public:
SerialPrint("<-", F("Telegram"), "download from: " + _chatID + ", file: " + msg.fileName + " size = " + String(_size) + " byte"); SerialPrint("<-", F("Telegram"), "download from: " + _chatID + ", file: " + msg.fileName + " size = " + String(_size) + " byte");
_myBot->sendMessage("Download Ok, size = " + String(_size) + " byte", _chatID); _myBot->sendMessage("Download Ok, size = " + String(_size) + " byte", _chatID);
} }
return _size;
} }
else else
{ {
SerialPrint("E", F("Telegram"), F("file write error")); SerialPrint("E", F("Telegram"), F("file write error"));
_myBot->sendMessage(F("file write error"), _chatID); _myBot->sendMessage(F("file write error"), _chatID);
} }
return _size;
} }
IoTItem *getTlgrmDriver() IoTItem *getTlgrmDriver()