Created
August 8, 2018 10:22
-
-
Save yakutozcan/6fdc80499183ea9ea63349e98fd6b965 to your computer and use it in GitHub Desktop.
iot telegrambot esp8266
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "CTBot.h" | |
CTBot myBot; | |
String ssid = "WIFI ADI"; | |
String pass = "SIFRE"; | |
String token = "TELEGRAM API KEY"; | |
uint8_t led = D4; | |
void setup() { | |
// initialize the Serial | |
Serial.begin(115200); | |
Serial.println("Starting TelegramBot..."); | |
// connect the ESP8266 to the desired access point | |
myBot.wifiConnect(ssid, pass); | |
// 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"); | |
// set the pin connected to the LED to act as output pin | |
pinMode(led, OUTPUT); | |
digitalWrite(led, HIGH); // turn off the led (inverted logic!) | |
} | |
void loop() { | |
TBMessage msg; | |
if (myBot.getNewMessage(msg)) { | |
Serial.println(msg.text); | |
if (msg.text.equalsIgnoreCase("/ac")) { | |
digitalWrite(led, LOW); | |
myBot.sendMessage(msg.sender.id, "Acildi"); | |
} | |
else if (msg.text.equalsIgnoreCase("/kapat")) { | |
digitalWrite(led, HIGH); | |
myBot.sendMessage(msg.sender.id, "Kapandi"); | |
} | |
else { | |
String reply; | |
reply = (String)"H.g. " + msg.sender.username + (String)". Komutlar: /ac ve /kapat"; | |
myBot.sendMessage(msg.sender.id, reply); | |
} | |
} | |
// wait 500 milliseconds | |
delay(500); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment