//Disini saya menggunakan ESP32 Dev Kit
#include "ArduinoJson.h"
#include "CTBot.h"
#include "DHT.h"
#define DHTPIN 5
#define DHTTYPE DHT22 //Inisialisasi tipe DHT
CTBot mybot;
String ssid = "Wokwi-GUEST";
String pass = "";
String token = "6492432846:AAGH6BWy1IBcbsUt1zLrIZfATN7Cw-HJd-o";
const int id = 850395768;
int led = 2;
int led2 = 4;
float temperature;
float humidity;
DHT dht (DHTPIN,DHTTYPE);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(led, OUTPUT);
pinMode(led2, OUTPUT);
Serial.println("Memulai telegram bot");
mybot.wifiConnect(ssid, pass);
mybot.setTelegramToken(token);
if(mybot.testConnection())
Serial.println("Mantap Sukses");
else
Serial.println("Coba Funbot Cek Lagi Librarynya ");
dht.begin();
}
void loop() {
humidity = dht.readHumidity();
temperature = dht.readTemperature();
TBMessage msg;
if(mybot.getNewMessage(msg)){
Serial.println("Pesan masuk : "+msg.text);
String pesan = msg.text;
if(pesan=="On"){
//digitalWrite(led, LOW); //led Relay trigger LOW
digitalWrite(led, HIGH);
mybot.sendMessage(id, "OK Funbot Led Biru Dinyalakan");
}
else if (pesan=="Off"){
//digitalWrite(led, HIGH); //led Relay trigger LOW
digitalWrite(led, LOW);
mybot.sendMessage(id, "Siap Funbot Led Biru Dimatikan");
}
else if (pesan=="On2"){
//digitalWrite(led, HIGH); //led Relay trigger LOW
digitalWrite(led2, HIGH);
mybot.sendMessage(id, "Siap Funbot Led Merah Dinyalakan");
}
else if (pesan=="Off2"){
//digitalWrite(led, HIGH); //led Relay trigger LOW
digitalWrite(led2, LOW);
mybot.sendMessage(id, "Siap Funbot Led Merah Dimatikan");
}
else if (pesan=="Suhu"){
String msg = "Okey Funbot Suhu adalah ";
msg += msg.concat(temperature);
msg += " C";
mybot.sendMessage(id,msg, "");
}
else if (pesan=="Kelembaban"){
String msg = "Okey Funbot Kelembaban adalah ";
msg += msg.concat(humidity);
msg += " %";
mybot.sendMessage(id,msg, "");
}
}
}