Browse Source

Use AsyncTelegram2 instead of Universal-Arduino-Telegram-Bot.

Thomas Buck 1 year ago
parent
commit
fc77898f94
4 changed files with 86 additions and 100 deletions
  1. 1
    1
      README.md
  2. 1
    2
      include/config.h
  3. 2
    2
      platformio.ini
  4. 82
    95
      src/WifiStuff.cpp

+ 1
- 1
README.md View File

32
 Look for the chat ID in the log and put it into wifi.h in TRUSTED_IDS.
32
 Look for the chat ID in the log and put it into wifi.h in TRUSTED_IDS.
33
 
33
 
34
     echo '#define TELEGRAM_TOKEN "XXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"' >> include/wifi.h
34
     echo '#define TELEGRAM_TOKEN "XXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"' >> include/wifi.h
35
-    echo '#define TRUSTED_IDS { "1234", "5678" }' >> include/wifi.h
35
+    echo '#define TRUSTED_IDS { 1234, 5678 }' >> include/wifi.h
36
 
36
 
37
 MQTT is far less resource intensive, but also does not provide a bridge to the Internet.
37
 MQTT is far less resource intensive, but also does not provide a bridge to the Internet.
38
 Enable it like this.
38
 Enable it like this.

+ 1
- 2
include/config.h View File

52
 #define LED_INIT_BLINK_INTERVAL 500
52
 #define LED_INIT_BLINK_INTERVAL 500
53
 #define LED_CONNECT_BLINK_INTERVAL 250
53
 #define LED_CONNECT_BLINK_INTERVAL 250
54
 #define LED_ERROR_BLINK_INTERVAL 100
54
 #define LED_ERROR_BLINK_INTERVAL 100
55
-#define TELEGRAM_UPDATE_INTERVAL_SLOW (10 * 1000)
56
-#define TELEGRAM_UPDATE_INTERVAL_FAST (2 * 1000)
55
+#define TELEGRAM_UPDATE_INTERVAL (2 * 1000)
57
 #define MQTT_RECONNECT_INTERVAL (5 * 1000)
56
 #define MQTT_RECONNECT_INTERVAL (5 * 1000)
58
 
57
 
59
 // each attempt takes LED_CONNECT_BLINK_INTERVAL ms
58
 // each attempt takes LED_CONNECT_BLINK_INTERVAL ms

+ 2
- 2
platformio.ini View File

23
     https://github.com/tobiasschuerg/InfluxDB-Client-for-Arduino.git
23
     https://github.com/tobiasschuerg/InfluxDB-Client-for-Arduino.git
24
     https://github.com/RobTillaart/PCF8574
24
     https://github.com/RobTillaart/PCF8574
25
     https://github.com/bblanchon/ArduinoJson
25
     https://github.com/bblanchon/ArduinoJson
26
-    https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot
26
+    https://github.com/cotestatnt/AsyncTelegram2
27
     https://github.com/knolleary/pubsubclient.git#2d228f2f862a95846c65a8518c79f48dfc8f188c
27
     https://github.com/knolleary/pubsubclient.git#2d228f2f862a95846c65a8518c79f48dfc8f188c
28
 
28
 
29
 [env:esp32_main]
29
 [env:esp32_main]
40
     https://github.com/tobiasschuerg/InfluxDB-Client-for-Arduino.git
40
     https://github.com/tobiasschuerg/InfluxDB-Client-for-Arduino.git
41
     https://github.com/RobTillaart/PCF8574
41
     https://github.com/RobTillaart/PCF8574
42
     https://github.com/bblanchon/ArduinoJson
42
     https://github.com/bblanchon/ArduinoJson
43
-    https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot
43
+    https://github.com/cotestatnt/AsyncTelegram2
44
     https://github.com/knolleary/pubsubclient.git#2d228f2f862a95846c65a8518c79f48dfc8f188c
44
     https://github.com/knolleary/pubsubclient.git#2d228f2f862a95846c65a8518c79f48dfc8f188c
45
 
45
 
46
 [env:arduino_ui]
46
 [env:arduino_ui]

+ 82
- 95
src/WifiStuff.cpp View File

49
 #ifdef TELEGRAM_TOKEN
49
 #ifdef TELEGRAM_TOKEN
50
 
50
 
51
 #include <WiFiClientSecure.h>
51
 #include <WiFiClientSecure.h>
52
-#include <UniversalTelegramBot.h>
52
+#include <AsyncTelegram2.h>
53
 
53
 
54
 //#define TELEGRAM_LOG_TIMINGS
54
 //#define TELEGRAM_LOG_TIMINGS
55
 
55
 
56
 #if defined(ARDUINO_ARCH_ESP8266)
56
 #if defined(ARDUINO_ARCH_ESP8266)
57
-X509List cert(TELEGRAM_CERTIFICATE_ROOT);
57
+X509List cert(telegram_cert);
58
 #endif
58
 #endif
59
 
59
 
60
 WiFiClientSecure secured_client;
60
 WiFiClientSecure secured_client;
61
-UniversalTelegramBot bot(TELEGRAM_TOKEN, secured_client);
62
-unsigned long last_telegram_time = 0;
63
-String trusted_chat_ids[] = TRUSTED_IDS;
61
+AsyncTelegram2 bot(secured_client);
62
+int64_t trusted_chat_ids[] = TRUSTED_IDS;
64
 
63
 
65
 enum telegram_state {
64
 enum telegram_state {
66
     BOT_IDLE,
65
     BOT_IDLE,
70
 };
69
 };
71
 
70
 
72
 enum telegram_state bot_state = BOT_IDLE;
71
 enum telegram_state bot_state = BOT_IDLE;
73
-String bot_lock = "";
72
+int64_t bot_lock = 0;
74
 
73
 
75
 #endif // TELEGRAM_TOKEN
74
 #endif // TELEGRAM_TOKEN
76
 
75
 
146
 void wifi_broadcast_state_change(const char *s) {
145
 void wifi_broadcast_state_change(const char *s) {
147
 #ifdef TELEGRAM_TOKEN
146
 #ifdef TELEGRAM_TOKEN
148
     for (int n = 0; n < (sizeof(trusted_chat_ids) / sizeof(trusted_chat_ids[0])); n++) {
147
     for (int n = 0; n < (sizeof(trusted_chat_ids) / sizeof(trusted_chat_ids[0])); n++) {
149
-        bot.sendMessage(trusted_chat_ids[n], "New state: " + String(s), "");
148
+        bot.sendTo(trusted_chat_ids[n], "New state: " + String(s));
150
     }
149
     }
151
 #endif // TELEGRAM_TOKEN
150
 #endif // TELEGRAM_TOKEN
152
 
151
 
158
 
157
 
159
 #ifdef TELEGRAM_TOKEN
158
 #ifdef TELEGRAM_TOKEN
160
 
159
 
161
-unsigned long telegram_update_interval() {
162
-    if (bot_state == BOT_IDLE) {
163
-        return TELEGRAM_UPDATE_INTERVAL_SLOW;
164
-    } else {
165
-        return TELEGRAM_UPDATE_INTERVAL_FAST;
166
-    }
167
-}
168
-
169
 String telegram_help() {
160
 String telegram_help() {
170
     String s = "Usage:\n";
161
     String s = "Usage:\n";
171
     s += "Send /auto and follow prompts.\n";
162
     s += "Send /auto and follow prompts.\n";
175
     return s;
166
     return s;
176
 }
167
 }
177
 
168
 
178
-void telegram_handle_message(int message_id) {
169
+void telegram_handle_message(TBMessage &msg) {
179
     if (!sm_is_idle()) {
170
     if (!sm_is_idle()) {
180
         debug.println("Telegram: message while machine in use");
171
         debug.println("Telegram: message while machine in use");
181
 
172
 
182
-        if (bot.messages[message_id].text == "/abort") {
173
+        if (msg.text == "/abort") {
183
             sm_bot_abort();
174
             sm_bot_abort();
184
-            bot.sendMessage(bot.messages[message_id].chat_id, "Aborted current cycle!", "");
175
+            bot.sendTo(msg.chatId, "Aborted current cycle!");
185
         } else {
176
         } else {
186
-            bot.sendMessage(bot.messages[message_id].chat_id, "Machine is already in use.\nPlease try again later.", "");
177
+            bot.sendTo(msg.chatId, "Machine is already in use.\nPlease try again later.");
187
         }
178
         }
188
 
179
 
189
         return;
180
         return;
190
     }
181
     }
191
 
182
 
192
-    if ((bot_state == BOT_IDLE) && (bot_lock == "")) {
193
-        bot_lock = bot.messages[message_id].chat_id;
183
+    if ((bot_state == BOT_IDLE) && (bot_lock == 0)) {
184
+        bot_lock = msg.chatId;
194
         debug.println("Telegram: locked to " + bot_lock);
185
         debug.println("Telegram: locked to " + bot_lock);
195
     }
186
     }
196
 
187
 
197
-    if (bot_lock != bot.messages[message_id].chat_id) {
198
-        debug.println("Telegram: bot locked. abort for chat " + bot.messages[message_id].chat_id);
199
-        bot.sendMessage(bot.messages[message_id].chat_id, "Bot is already in use.\nPlease try again later.", "");
188
+    if (bot_lock != msg.chatId) {
189
+        debug.println("Telegram: bot locked. abort for chat " + msg.chatId);
190
+        bot.sendTo(msg.chatId, "Bot is already in use.\nPlease try again later.");
200
         return;
191
         return;
201
     }
192
     }
202
 
193
 
203
     if (bot_state == BOT_IDLE) {
194
     if (bot_state == BOT_IDLE) {
204
-        if (bot.messages[message_id].text == "/auto") {
195
+        if (msg.text == "/auto") {
205
             String s = "Please enter fertilizer numbers.\n";
196
             String s = "Please enter fertilizer numbers.\n";
206
             s += "Valid numbers: 1 to " + String(PUMP_COUNT) + "\n";
197
             s += "Valid numbers: 1 to " + String(PUMP_COUNT) + "\n";
207
             s += "Send /none to skip.\n";
198
             s += "Send /none to skip.\n";
208
             s += "Send /abort to cancel.";
199
             s += "Send /abort to cancel.";
209
             bot_ferts.clear();
200
             bot_ferts.clear();
210
             bot_state = BOT_ASKED_FERT;
201
             bot_state = BOT_ASKED_FERT;
211
-            bot.sendMessage(bot.messages[message_id].chat_id, s, "");
212
-        } else if (bot.messages[message_id].text == "/abort") {
213
-            bot_lock = "";
214
-            bot.sendMessage(bot.messages[message_id].chat_id, "Nothing to abort.", "");
202
+            bot.sendTo(msg.chatId, s);
203
+        } else if (msg.text == "/abort") {
204
+            bot_lock = 0;
205
+            bot.sendTo(msg.chatId, "Nothing to abort.");
215
         } else {
206
         } else {
216
-            bot_lock = "";
217
-            bot.sendMessage(bot.messages[message_id].chat_id, telegram_help(), "");
207
+            bot_lock = 0;
208
+            bot.sendTo(msg.chatId, telegram_help());
218
         }
209
         }
219
     } else if (bot_state == BOT_ASKED_FERT) {
210
     } else if (bot_state == BOT_ASKED_FERT) {
220
-        if (bot.messages[message_id].text == "/abort") {
211
+        if (msg.text == "/abort") {
221
             bot_state = BOT_IDLE;
212
             bot_state = BOT_IDLE;
222
-            bot_lock = "";
223
-            bot.sendMessage(bot.messages[message_id].chat_id, "Aborted.", "");
213
+            bot_lock = 0;
214
+            bot.sendTo(msg.chatId, "Aborted.");
224
             return;
215
             return;
225
-        } else if (bot.messages[message_id].text != "/none") {
216
+        } else if (msg.text != "/none") {
226
             String buff;
217
             String buff;
227
-            for (int i = 0; i < bot.messages[message_id].text.length() + 1; i++) {
228
-                if ((i == bot.messages[message_id].text.length()) || (bot.messages[message_id].text[i] == ' ')) {
218
+            for (int i = 0; i < msg.text.length() + 1; i++) {
219
+                if ((i == msg.text.length()) || (msg.text[i] == ' ')) {
229
                     if (buff.length() > 0) {
220
                     if (buff.length() > 0) {
230
                         int n = buff.toInt() - 1;
221
                         int n = buff.toInt() - 1;
231
                         buff = "";
222
                         buff = "";
232
                         bot_ferts.set(n);
223
                         bot_ferts.set(n);
233
                     }
224
                     }
234
-                } else if ((bot.messages[message_id].text[i] >= '0') && (bot.messages[message_id].text[i] <= '9')) {
235
-                    buff += bot.messages[message_id].text[i];
225
+                } else if ((msg.text[i] >= '0') && (msg.text[i] <= '9')) {
226
+                    buff += msg.text[i];
236
                 } else {
227
                 } else {
237
                     bot_state = BOT_IDLE;
228
                     bot_state = BOT_IDLE;
238
-                    bot_lock = "";
239
-                    bot.sendMessage(bot.messages[message_id].chat_id, "Invalid input.\nAborted.", "");
229
+                    bot_lock = 0;
230
+                    bot.sendTo(msg.chatId, "Invalid input.\nAborted.");
240
                     return;
231
                     return;
241
                 }
232
                 }
242
             }
233
             }
247
         s += "Send /abort to cancel.";
238
         s += "Send /abort to cancel.";
248
         bot_plants.clear();
239
         bot_plants.clear();
249
         bot_state = BOT_ASKED_PLANTS;
240
         bot_state = BOT_ASKED_PLANTS;
250
-        bot.sendMessage(bot.messages[message_id].chat_id, s, "");
241
+        bot.sendTo(msg.chatId, s);
251
     } else if (bot_state == BOT_ASKED_PLANTS) {
242
     } else if (bot_state == BOT_ASKED_PLANTS) {
252
-        if (bot.messages[message_id].text == "/abort") {
243
+        if (msg.text == "/abort") {
253
             bot_state = BOT_IDLE;
244
             bot_state = BOT_IDLE;
254
-            bot_lock = "";
255
-            bot.sendMessage(bot.messages[message_id].chat_id, "Aborted.", "");
245
+            bot_lock = 0;
246
+            bot.sendTo(msg.chatId, "Aborted.");
256
             return;
247
             return;
257
         }
248
         }
258
 
249
 
259
         String buff;
250
         String buff;
260
-        for (int i = 0; i < bot.messages[message_id].text.length() + 1; i++) {
261
-            if ((i == bot.messages[message_id].text.length()) || (bot.messages[message_id].text[i] == ' ')) {
251
+        for (int i = 0; i < msg.text.length() + 1; i++) {
252
+            if ((i == msg.text.length()) || (msg.text[i] == ' ')) {
262
                 if (buff.length() > 0) {
253
                 if (buff.length() > 0) {
263
                     int n = buff.toInt() - 1;
254
                     int n = buff.toInt() - 1;
264
                     buff = "";
255
                     buff = "";
265
                     bot_plants.set(n);
256
                     bot_plants.set(n);
266
                 }
257
                 }
267
-            } else if ((bot.messages[message_id].text[i] >= '0') && (bot.messages[message_id].text[i] <= '9')) {
268
-                buff += bot.messages[message_id].text[i];
258
+            } else if ((msg.text[i] >= '0') && (msg.text[i] <= '9')) {
259
+                buff += msg.text[i];
269
             } else {
260
             } else {
270
                 bot_state = BOT_IDLE;
261
                 bot_state = BOT_IDLE;
271
-                bot_lock = "";
272
-                bot.sendMessage(bot.messages[message_id].chat_id, "Invalid input.\nAborted.", "");
262
+                bot_lock = 0;
263
+                bot.sendTo(msg.chatId, "Invalid input.\nAborted.");
273
                 return;
264
                 return;
274
             }
265
             }
275
         }
266
         }
276
 
267
 
277
         if (bot_plants.countSet() <= 0) {
268
         if (bot_plants.countSet() <= 0) {
278
             bot_state = BOT_IDLE;
269
             bot_state = BOT_IDLE;
279
-            bot_lock = "";
280
-            bot.sendMessage(bot.messages[message_id].chat_id, "No plants selected.\nAborted.", "");
270
+            bot_lock = 0;
271
+            bot.sendTo(msg.chatId, "No plants selected.\nAborted.");
281
             return;
272
             return;
282
         }
273
         }
283
 
274
 
284
 #ifdef FULLAUTO_MIN_PLANT_COUNT
275
 #ifdef FULLAUTO_MIN_PLANT_COUNT
285
         if (bot_plants.countSet() < FULLAUTO_MIN_PLANT_COUNT) {
276
         if (bot_plants.countSet() < FULLAUTO_MIN_PLANT_COUNT) {
286
             bot_state = BOT_IDLE;
277
             bot_state = BOT_IDLE;
287
-            bot_lock = "";
288
-            bot.sendMessage(bot.messages[message_id].chat_id, "Select at least " + String(FULLAUTO_MIN_PLANT_COUNT) + " plants.\nAborted.", "");
278
+            bot_lock = 0;
279
+            bot.sendTo(msg.chatId, "Select at least " + String(FULLAUTO_MIN_PLANT_COUNT) + " plants.\nAborted.");
289
             return;
280
             return;
290
         }
281
         }
291
 #endif
282
 #endif
304
         }
295
         }
305
         s += "\nOk? Send /begin to start or /abort to cancel.";
296
         s += "\nOk? Send /begin to start or /abort to cancel.";
306
         bot_state = BOT_ASKED_CONFIRM;
297
         bot_state = BOT_ASKED_CONFIRM;
307
-        bot.sendMessage(bot.messages[message_id].chat_id, s, "");
298
+        bot.sendTo(msg.chatId, s);
308
     } else if (bot_state == BOT_ASKED_CONFIRM) {
299
     } else if (bot_state == BOT_ASKED_CONFIRM) {
309
-        if (bot.messages[message_id].text == "/abort") {
300
+        if (msg.text == "/abort") {
310
             bot_state = BOT_IDLE;
301
             bot_state = BOT_IDLE;
311
-            bot_lock = "";
312
-            bot.sendMessage(bot.messages[message_id].chat_id, "Aborted.", "");
313
-        } else if (bot.messages[message_id].text == "/begin") {
302
+            bot_lock = 0;
303
+            bot.sendTo(msg.chatId, "Aborted.");
304
+        } else if (msg.text == "/begin") {
314
             bot_state = BOT_IDLE;
305
             bot_state = BOT_IDLE;
315
-            bot_lock = "";
316
-            bot.sendMessage(bot.messages[message_id].chat_id, "Auto watering cycle started.", "");
306
+            bot_lock = 0;
307
+            bot.sendTo(msg.chatId, "Auto watering cycle started.");
317
             sm_bot_start_auto(bot_ferts, bot_plants);
308
             sm_bot_start_auto(bot_ferts, bot_plants);
318
         } else {
309
         } else {
319
             bot_state = BOT_IDLE;
310
             bot_state = BOT_IDLE;
320
-            bot_lock = "";
321
-            bot.sendMessage(bot.messages[message_id].chat_id, "Unknown message.\nAborted.", "");
311
+            bot_lock = 0;
312
+            bot.sendTo(msg.chatId, "Unknown message.\nAborted.");
322
         }
313
         }
323
     } else {
314
     } else {
324
         debug.println("Telegram: invalid state");
315
         debug.println("Telegram: invalid state");
325
         bot_state = BOT_IDLE;
316
         bot_state = BOT_IDLE;
326
-        bot_lock = "";
327
-        bot.sendMessage(bot.messages[message_id].chat_id, "Internal error.\nPlease try again.", "");
317
+        bot_lock = 0;
318
+        bot.sendTo(msg.chatId, "Internal error.\nPlease try again.");
328
     }
319
     }
329
 }
320
 }
330
 
321
 
331
-void telegram_handler(int message_id) {
332
-    debug.println("Telegram: rx " + bot.messages[message_id].chat_id + " \"" + bot.messages[message_id].text + "\"");
322
+void telegram_handler(TBMessage &msg) {
323
+    debug.println("Telegram: rx " + String((long int)msg.chatId) + " \"" + msg.text + "\"");
333
 
324
 
334
     bool found = false;
325
     bool found = false;
335
     for (int n = 0; n < (sizeof(trusted_chat_ids) / sizeof(trusted_chat_ids[0])); n++) {
326
     for (int n = 0; n < (sizeof(trusted_chat_ids) / sizeof(trusted_chat_ids[0])); n++) {
336
-        if (trusted_chat_ids[n] == bot.messages[message_id].chat_id) {
327
+        if (trusted_chat_ids[n] == msg.chatId) {
337
             found = true;
328
             found = true;
338
             break;
329
             break;
339
         }
330
         }
340
     }
331
     }
341
     if (!found) {
332
     if (!found) {
342
-        bot.sendMessage(bot.messages[message_id].chat_id, "Sorry, not authorized!", "");
333
+        bot.sendTo(msg.chatId, "Sorry, not authorized!");
343
         return;
334
         return;
344
     }
335
     }
345
 
336
 
346
-    telegram_handle_message(message_id);
337
+    telegram_handle_message(msg);
347
 }
338
 }
348
 
339
 
349
 void telegram_poll() {
340
 void telegram_poll() {
351
     unsigned long start = millis();
342
     unsigned long start = millis();
352
 #endif // TELEGRAM_LOG_TIMINGS
343
 #endif // TELEGRAM_LOG_TIMINGS
353
 
344
 
354
-    while (int count = bot.getUpdates(bot.last_message_received + 1)) {
355
-        for (int i = 0; i < count; i++) {
356
-            telegram_handler(i);
357
-        }
345
+    TBMessage msg;
346
+    while (bot.getNewMessage(msg)) {
347
+        telegram_handler(msg);
358
     }
348
     }
359
 
349
 
360
 #ifdef TELEGRAM_LOG_TIMINGS
350
 #ifdef TELEGRAM_LOG_TIMINGS
365
 
355
 
366
 void telegram_hello() {
356
 void telegram_hello() {
367
     for (int n = 0; n < (sizeof(trusted_chat_ids) / sizeof(trusted_chat_ids[0])); n++) {
357
     for (int n = 0; n < (sizeof(trusted_chat_ids) / sizeof(trusted_chat_ids[0])); n++) {
368
-        bot.sendMessage(trusted_chat_ids[n], "Giess-o-mat v" FIRMWARE_VERSION " initialized.\nSend /auto to begin.", "");
358
+        bot.sendTo(trusted_chat_ids[n], "Giess-o-mat v" FIRMWARE_VERSION " initialized.\nSend /auto to begin.");
369
     }
359
     }
370
 }
360
 }
371
 #endif // TELEGRAM_TOKEN
361
 #endif // TELEGRAM_TOKEN
1058
     message += F("<p>\n");
1048
     message += F("<p>\n");
1059
 #ifdef TELEGRAM_TOKEN
1049
 #ifdef TELEGRAM_TOKEN
1060
     message += F("Telegram: ");
1050
     message += F("Telegram: ");
1061
-    message += TELEGRAM_UPDATE_INTERVAL_SLOW;
1062
-    message += F("ms / ");
1063
-    message += TELEGRAM_UPDATE_INTERVAL_FAST;
1051
+    message += TELEGRAM_UPDATE_INTERVAL;
1064
     message += F("ms\n");
1052
     message += F("ms\n");
1065
 #else
1053
 #else
1066
     message += F("Telegram bot not enabled!\n");
1054
     message += F("Telegram bot not enabled!\n");
1273
     WiFi.begin(WIFI_SSID, WIFI_PW);
1261
     WiFi.begin(WIFI_SSID, WIFI_PW);
1274
 
1262
 
1275
 #ifdef TELEGRAM_TOKEN
1263
 #ifdef TELEGRAM_TOKEN
1276
-    secured_client.setCACert(TELEGRAM_CERTIFICATE_ROOT);
1264
+    secured_client.setCACert(telegram_cert);
1277
 #endif // TELEGRAM_TOKEN
1265
 #endif // TELEGRAM_TOKEN
1278
 
1266
 
1279
     while (((ws = WiFi.status()) != WL_CONNECTED) && (connect_attempts < MAX_WIFI_CONNECT_ATTEMPTS)) {
1267
     while (((ws = WiFi.status()) != WL_CONNECTED) && (connect_attempts < MAX_WIFI_CONNECT_ATTEMPTS)) {
1330
     debug.println(" done!");
1318
     debug.println(" done!");
1331
     debug.println("WiFi: time is " + String(now));
1319
     debug.println("WiFi: time is " + String(now));
1332
 
1320
 
1333
-    debug.println("WiFi: initializing Telegram");
1334
-    const String commands = F("["
1335
-        "{\"command\":\"auto\", \"description\":\"Start automatic watering cycle\"},"
1336
-        "{\"command\":\"confirm\", \"description\":\"Proceed with any menu inputs\"},"
1337
-        "{\"command\":\"none\", \"description\":\"Proceed without menu input\"},"
1338
-        "{\"command\":\"abort\", \"description\":\"Cancel any menu inputs\"}"
1339
-    "]");
1340
-    bot.setMyCommands(commands);
1321
+    debug.print("WiFi: initializing Telegram... ");
1322
+    bot.setUpdateTime(TELEGRAM_UPDATE_INTERVAL);
1323
+    bot.setTelegramToken(TELEGRAM_TOKEN);
1324
+    bot.begin() ? debug.println("Ok") : debug.println("Error");
1325
+
1326
+    bot.setMyCommands("auto", "Start automatic watering cycle");
1327
+    bot.setMyCommands("confirm", "Proceed with any menu inputs");
1328
+    bot.setMyCommands("none", "Proceed without menu input");
1329
+    bot.setMyCommands("abort", "Cancel any menu inputs");
1330
+
1341
     telegram_hello();
1331
     telegram_hello();
1342
 #endif // TELEGRAM_TOKEN
1332
 #endif // TELEGRAM_TOKEN
1343
 
1333
 
1371
 #ifdef ARDUINO_ARCH_ESP8266
1361
 #ifdef ARDUINO_ARCH_ESP8266
1372
         MDNS.update();
1362
         MDNS.update();
1373
 #endif // ARDUINO_ARCH_ESP8266
1363
 #endif // ARDUINO_ARCH_ESP8266
1364
+
1365
+#ifdef TELEGRAM_TOKEN
1366
+        telegram_poll();
1367
+#endif // TELEGRAM_TOKEN
1374
     }
1368
     }
1375
 
1369
 
1376
     if ((millis() - last_websocket_update_time) >= WEBSOCKET_UPDATE_INTERVAL) {
1370
     if ((millis() - last_websocket_update_time) >= WEBSOCKET_UPDATE_INTERVAL) {
1385
     }
1379
     }
1386
 #endif // ENABLE_GPIO_TEST
1380
 #endif // ENABLE_GPIO_TEST
1387
 
1381
 
1388
-#ifdef TELEGRAM_TOKEN
1389
-    if ((millis() - last_telegram_time) >= telegram_update_interval()) {
1390
-        telegram_poll();
1391
-        last_telegram_time = millis();
1392
-    }
1393
-#endif // TELEGRAM_TOKEN
1394
-
1395
 #ifdef MQTT_HOST
1382
 #ifdef MQTT_HOST
1396
     if (!mqtt.connected() && ((millis() - last_mqtt_reconnect_time) >= MQTT_RECONNECT_INTERVAL)) {
1383
     if (!mqtt.connected() && ((millis() - last_mqtt_reconnect_time) >= MQTT_RECONNECT_INTERVAL)) {
1397
         last_mqtt_reconnect_time = millis();
1384
         last_mqtt_reconnect_time = millis();

Loading…
Cancel
Save