#include "DHTesp.h"
#include <ESP32Servo.h>
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h>
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27
#define LCD_COLUMNS 16
#define LCD_LINES 2
#define WIFI_SSID "Wokwi-GUEST"
#define WIFI_PASSWORD ""
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
#define BOT_TOKEN "7727304613:AAHLM0KtJvvqF0zWudXHGG9AlW5VuReHbwg"
const unsigned long BOT_MTBS = 1000;
WiFiClientSecure secured_client;
UniversalTelegramBot bot(BOT_TOKEN, secured_client);
unsigned long bot_lasttime;
bool g = true;
#define DHT_PIN 2
#define DHT_PIN A18
#define DHT_PIN1 A19
int t,h;
int t1,h1;
String h3,h4;
int d = 0;
DHTesp dhtSensor;
DHTesp dhtSensor1;
Servo servo;
bool z = false;
Servo servo1;
Servo servo2;
int pos;
bool y = false;
String nn = "\n";
void handleNewMessages(int numNewMessages)
{
Serial.print("handleNewMessages ");
Serial.println(numNewMessages);
for (int i = 0; i < numNewMessages; i++)
{
String chat_id = bot.messages[i].chat_id;
String text = bot.messages[i].text;
String from_name = bot.messages[i].from_name;
if (from_name == "")
from_name = "Guest";
if (text == "/vent")
{
g = !g;
if(g == true){
bot.sendMessage(chat_id, "вентелятор был включен", "");
}
if(g == false){
bot.sendMessage(chat_id, "вентелятор был выключен", "");
}
}
if (text == "/status")
{
if(g == true){
bot.sendMessage(chat_id, "вентелятор включен", "");
}
if(g == false){
bot.sendMessage(chat_id, "вентелятор выключен", "");
}
}
if (text == "/start")
{
String welcome = "Вас приветствует бот Умной сушилки,вот мои команды:" + nn;
welcome += "/vent: включать или выключить вентелятор." + nn;
welcome += "/status_vent: узнать статус работы вентелятора." + nn;
bot.sendMessage(chat_id, welcome, "Markdown");
}
}
}
void setup() {
Serial.begin(115200);
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
dhtSensor1.setup(DHT_PIN1, DHTesp::DHT22);
servo.attach(18);
servo1.attach(19);
servo2.attach(23);
Serial.begin(115200);
Serial.println();
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
// attempt to connect to Wifi network:
Serial.print("Connecting to Wifi SSID ");
Serial.print(WIFI_SSID);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
secured_client.setCACert(TELEGRAM_CERTIFICATE_ROOT); // Add root certificate for api.telegram.org
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(500);
}
Serial.print("\nWiFi connected. IP address: ");
Serial.println(WiFi.localIP());
Serial.print("Retrieving time: ");
configTime(0, 0, "pool.ntp.org"); // get UTC time via NTP
time_t now = time(nullptr);
while (now < 24 * 3600)
{
Serial.print(".");
delay(100);
now = time(nullptr);
}
Serial.println(now);
lcd.init();
lcd.backlight();
// Print something
}
void loop() {
TempAndHumidity data1 = dhtSensor1.getTempAndHumidity();
TempAndHumidity data = dhtSensor.getTempAndHumidity();
t = data.temperature;
h = data.humidity;
t1 = data1.temperature;
h1 = data1.humidity;
h3 = h;
h4 = h1;
lcd.setCursor(1, 0);
lcd.print("ext hum:");
lcd.setCursor(10, 0);
lcd.print(h3);
lcd.setCursor(1, 1);
lcd.print("int hum:");
lcd.setCursor(10, 1);
lcd.print(h4);
if (h <= 14) {
if(y == true) {
servo.write(180);
delay(2000);
servo.write(90);
y = false;
z = true;
}
}
else{
y = true;
}
if (z == true) {
servo1.write(0);
}
if (z == false) {
servo1.write(90);
}
if(g == true){
for ( d = 0 ; d <= 180 ; ++d)
{
servo2.write(d);
delay(2);
}
for ( d = 180 ; d >= 0 ; --d)
{
servo2.write(d);
delay(2);
}
}
if(g == false){
servo2.write(0);
}
{
if (millis() - bot_lasttime > BOT_MTBS)
{
int numNewMessages = bot.getUpdates(bot.last_message_received + 1);
while (numNewMessages)
{
Serial.println("got response");
handleNewMessages(numNewMessages);
numNewMessages = bot.getUpdates(bot.last_message_received + 1);
}
bot_lasttime = millis();
}
}
}Board not found
wokwi-custom-board
wokwi-custom-board