1
1
/* ******************************************************************
2
- * An example of bot that echos back any messages received *
3
- * *
4
- * written by Giacarlo Bacchio (Gianbacchio on Github) *
5
- * adapted by Brian Lough *
6
- *******************************************************************/
2
+ * An example of bot that echos back any messages received *
3
+ * *
4
+ * written by Giacarlo Bacchio (Gianbacchio on Github) *
5
+ * adapted by Brian Lough *
6
+ *******************************************************************/
7
7
#include < ESP8266WiFi.h>
8
8
#include < WiFiClientSecure.h>
9
9
#include < UniversalTelegramBot.h>
@@ -22,7 +22,6 @@ int Bot_mtbs = 1000; //mean time between scan messages
22
22
long Bot_lasttime; // last time messages' scan has been done
23
23
24
24
void setup () {
25
-
26
25
Serial.begin (115200 );
27
26
28
27
// Set WiFi to station mode and disconnect from an AP if it was Previously
@@ -35,30 +34,30 @@ void setup() {
35
34
Serial.print (" Connecting Wifi: " );
36
35
Serial.println (ssid);
37
36
WiFi.begin (ssid, password);
37
+
38
38
while (WiFi.status () != WL_CONNECTED) {
39
39
Serial.print (" ." );
40
40
delay (500 );
41
41
}
42
+
42
43
Serial.println (" " );
43
44
Serial.println (" WiFi connected" );
44
- Serial.println (" IP address: " );
45
- IPAddress ip = WiFi.localIP ();
46
- Serial.println (ip);
47
-
48
-
45
+ Serial.print (" IP address: " );
46
+ Serial.println (WiFi.localIP ());
49
47
}
50
48
51
49
void loop () {
52
-
53
50
if (millis () > Bot_lasttime + Bot_mtbs) {
54
51
int numNewMessages = bot.getUpdates (bot.last_message_received + 1 );
52
+
55
53
while (numNewMessages) {
56
54
Serial.println (" got response" );
57
- for (int i=0 ; i<numNewMessages; i++) {
55
+ for (int i=0 ; i<numNewMessages; i++) {
58
56
bot.sendMessage (bot.messages [i].chat_id , bot.messages [i].text , " " );
59
57
}
60
58
numNewMessages = bot.getUpdates (bot.last_message_received + 1 );
61
59
}
60
+
62
61
Bot_lasttime = millis ();
63
62
}
64
63
}
0 commit comments