#include <FastBot.h>
#include <DHT.h>
#define WIFI_SSID "Wokwi-GUEST"
#define WIFI_PASS ""
#define BOT_TOKEN "7438971079:AAENnR370xUwjhV9-CJ_l2lCCZ_erlrDUw4"
FastBot bot(BOT_TOKEN);
const int pinLed1=12;
const int pinLed2=13;
#define DHTPIN 5
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
float h;
float t;
void setup() {
pinMode(pinLed1, OUTPUT);
pinMode(pinLed2, OUTPUT);
connectWiFi();
bot.attach(newMsg);
dht.begin();
Serial.begin(9600);
}
void newMsg ( FB_msg& msg ) {
if ( msg. text == "/start" ){
bot.sendMessage ( "Привіт!" , msg. chatID ) ;
}
else if ( msg. text == "/led1_on" ){
digitalWrite ( pinLed1, HIGH ) ;
bot.sendMessage ( "Світло в кімнаті1 ввімкнено! " , msg. chatID );
}
else if ( msg. text == "/led1_off" ){
digitalWrite ( pinLed1, LOW) ;
bot.sendMessage ( "Світло в кімнаті1 вимкнено! " , msg. chatID );
}
else if ( msg. text == "/led2_on" ){
bot.sendMessage ( "Світло в кімнаті2 ввімкнено! " , msg. chatID );
digitalWrite ( pinLed2, HIGH ) ;
}
else if ( msg. text == "/led2_off" ){
digitalWrite ( pinLed2, LOW) ;
bot.sendMessage ( "Світло в кімнаті2 вимкнено! " , msg. chatID );
}
else if ( msg. text == "/temperature" ){
String mess="Температура повітря кімнати: "+ String(t)+"°C";
bot.sendMessage (mess , msg. chatID );
}
else if ( msg. text == "/humidity" ){
String mess="Вологість повітря кімнати: "+ String(h)+"%";
bot.sendMessage (mess , msg. chatID );
}
}
void loop() {
h = dht.readHumidity();
t = dht.readTemperature();
bot.tick();
}
void connectWiFi() {
delay(2000);
Serial.begin(115200);
Serial.println();
WiFi.begin(WIFI_SSID, WIFI_PASS);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
if (millis() > 15000) ESP.restart();
}
Serial.println("Connected");
}