#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h>
#include "DHTesp.h"
const int DHTPIN = 2; // DHT 11
DHTesp dht;
// Initialize Telegram BOT
#define BOTtoken "7216705800:AAFdrWirnE8CukNenvrGnVJUdEM2NKMyXJk" // your Bot Token (Get from Botfather)
#define chat_id "7147950852"
// Initialize Wifi connection to the router
char ssid[] = "Wokwi-GUEST"; //nama hotspot yang digunakan
char password[] = ""; //password hotspot yang digunakan
UniversalTelegramBot bot(BOTtoken);
void setup() {
Serial.begin(115200);
dht.setup(DHTPIN, DHTesp::DHT22);
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);
// attempt to connect to Wifi network:
Serial.print("Connecting Wifi: ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println("");
Serial.println("WiFi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
float h = dht.getHumidity();
float t = dht.getTemperature();
Serial.print(F("Humidity: "));
Serial.print(h);
Serial.print(F("% Temperature: "));
Serial.print(t);
Serial.println(F("°C "));
delay (3000);
if ( h >35 and t>25 ){
bot.sendChatAction(chat_id, "typing");
delay (3000);
String suhu = "intensitas Kelembaban : " ;
suhu += int(h);
suhu += "%\n";
suhu += "intensitas Suhu: ";
suhu += int (t);
suhu += "°C \n";
suhu += "Ruangan Suhu Panas sekali dan gerah ";
bot.sendMessage(chat_id, suhu, "");
Serial.println ("mengirim ke telegram");
}
}