@@ -29,7 +29,8 @@ int ledStatus = 0;
29
29
void handleNewMessages (int numNewMessages) {
30
30
Serial.println (" handleNewMessages" );
31
31
Serial.println (String (numNewMessages));
32
- for (int i=0 ; i<numNewMessages; i++) {
32
+
33
+ for (int i=0 ; i<numNewMessages; i++) {
33
34
String chat_id = String (bot.messages [i].chat_id );
34
35
String text = bot.messages [i].text ;
35
36
@@ -41,23 +42,27 @@ void handleNewMessages(int numNewMessages) {
41
42
ledStatus = 1 ;
42
43
bot.sendMessage (chat_id, " Led is ON" , " " );
43
44
}
45
+
44
46
if (text == " /ledoff" ) {
45
47
ledStatus = 0 ;
46
48
digitalWrite (ledPin, LOW); // turn the LED off (LOW is the voltage level)
47
49
bot.sendMessage (chat_id, " Led is OFF" , " " );
48
50
}
51
+
49
52
if (text == " /status" ) {
50
53
if (ledStatus){
51
54
bot.sendMessage (chat_id, " Led is ON" , " " );
52
55
} else {
53
56
bot.sendMessage (chat_id, " Led is OFF" , " " );
54
57
}
55
58
}
59
+
56
60
if (text == " /start" ) {
57
- String welcome = " Welcome, " + from_name + " , from FlashLedBot, your personal Bot on ESP8266\n " ;
58
- welcome = welcome + " /ledon : to switch the Led ON\n " ;
59
- welcome = welcome + " /ledoff : to switch the Led OFF\n " ;
60
- welcome = welcome + " /status : Returns current status of LED\n " ;
61
+ String welcome = " Welcome to Universal Arduino Telegram Bot library, " + from_name + " .\n " ;
62
+ welcome += " This is Flash Led Bot example.\n\n " ;
63
+ welcome += " /ledon : to switch the Led ON\n " ;
64
+ welcome += " /ledoff : to switch the Led OFF\n " ;
65
+ welcome += " /status : Returns current status of LED\n " ;
61
66
bot.sendMessage (chat_id, welcome, " Markdown" );
62
67
}
63
68
}
@@ -77,31 +82,32 @@ void setup() {
77
82
Serial.print (" Connecting Wifi: " );
78
83
Serial.println (ssid);
79
84
WiFi.begin (ssid, password);
85
+
80
86
while (WiFi.status () != WL_CONNECTED) {
81
87
Serial.print (" ." );
82
88
delay (500 );
83
89
}
90
+
84
91
Serial.println (" " );
85
92
Serial.println (" WiFi connected" );
86
- Serial.println (" IP address: " );
87
- IPAddress ip = WiFi.localIP ();
88
- Serial.println (ip);
93
+ Serial.print (" IP address: " );
94
+ Serial.println (WiFi.localIP ());
89
95
90
96
pinMode (ledPin, OUTPUT); // initialize digital ledPin as an output.
91
97
delay (10 );
92
98
digitalWrite (ledPin, LOW); // initialize pin as off
93
-
94
99
}
95
100
96
101
void loop () {
97
-
98
102
if (millis () > Bot_lasttime + Bot_mtbs) {
99
103
int numNewMessages = bot.getUpdates (bot.last_message_received + 1 );
104
+
100
105
while (numNewMessages) {
101
106
Serial.println (" got response" );
102
107
handleNewMessages (numNewMessages);
103
108
numNewMessages = bot.getUpdates (bot.last_message_received + 1 );
104
109
}
110
+
105
111
Bot_lasttime = millis ();
106
112
}
107
113
}
0 commit comments