#include "CTBot.h"
CTBot myBot;
#include "DHTesp.h"
String ssid = "Wokwi-GUEST";
String pass = "";
String token = "5956994748:AAHivhUI4KAON_lSpvRdorsiwdnW8mSw_3A";
const int lampu = 2;
#define dhtpin 15
#define dhtType DHT22
DHTesp dhtSensor;
void setup() {
Serial.begin(115200);
Serial.println("Starting TelegramBot...");
myBot.wifiConnect(ssid, pass);
myBot.setTelegramToken(token);
if (myBot.testConnection())
Serial.println("\nKoneksi Ke Telegram BOT Berhasil!");
else
Serial.println("\nTidak Terkoneksi Ke Telegram BOT");
pinMode(lampu, OUTPUT);
digitalWrite(lampu, HIGH);
}
void loop() {
TBMessage msg;
if (myBot.getNewMessage(msg)) {
if (msg.text.equalsIgnoreCase("On")) { //Perintah dari telegram ke perangkat
digitalWrite(lampu, HIGH); //Lampu dihidupkan
Serial.println("\nLampu Dihidupkan");
myBot.sendMessage(msg.sender.id, "The Led is now ON"); //Balasan dari perangkat ke Bot Telegram
}
else if (msg.text.equalsIgnoreCase("Off")) { //Perintah dari telegram ke perangkat
digitalWrite(lampu, LOW); //Lampu dimatikan
Serial.println("\nLampu Dimatikan");
myBot.sendMessage(msg.sender.id, "The Led is now OFF"); //Balasan dari perangkat ke Bot Telegram
} else { // otherwise...
// generate the message for the sender
String reply;
reply = (String)"Welcome " + msg.sender.username +
(String)". Silahkan gunakan perintah On atau Off.";
myBot.sendMessage(msg.sender.id, reply); // and send it
}
delay(10000);
}
}