-
Notifications
You must be signed in to change notification settings - Fork 0
/
Q6 telegrambot.ino
65 lines (52 loc) · 1.68 KB
/
Q6 telegrambot.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "CTBot.h"
//#include <ESP8266WiFi.h>
CTBot myBot;
String ssid = "Wokwi-GUEST";
String pass = "";
String token = "5777617746:AAECsvxuYC4aO4KyjsNU139VfaTx0GEu--w";
int ledPin = 2;
void setup() {
Serial.begin(115200);
delay(10);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
myBot.wifiConnect(ssid, pass);
Serial.println("Starting TelegramBot...");
// connect the ESP8266 to the desired access point
// set the telegram bot token
myBot.setTelegramToken(token);
// check if all things are ok
if (myBot.testConnection())
Serial.println("\ntestConnection OK");
else
Serial.println("\ntestConnection NOK");
digitalWrite(ledPin, HIGH);
}
void loop() {
// a variable to store telegram message data
TBMessage msg;
// if there is an incoming message...
if (CTBotMessageText == myBot.getNewMessage(msg)) {
if (msg.text.equalsIgnoreCase("OFF")) {
digitalWrite(ledPin, LOW);
myBot.sendMessage(msg.sender.id, "Light is now OFF");
}
else if (msg.text.equalsIgnoreCase("ON")) {
digitalWrite(ledPin, HIGH);
myBot.sendMessage(msg.sender.id, "Light is now ON");
}
else {
// generate the message for the sender
String reply;
reply = (String)"Try Only ON or OFF.";
myBot.sendMessage(msg.sender.id, reply);
}
}
// wait 500 milliseconds
delay(500);
}