#include <WiFi.h>
#include <WiFiClientSecure.h>
#include "RTClib.h"
#include <LiquidCrystal_I2C.h>
#include <ESP32Servo.h>
#include <FastLED.h>
#include "DHTesp.h"
#include <UniversalTelegramBot.h>
#define WIFI_SSID "Wokwi-GUEST"
#define WIFI_PASSWORD ""
#define BOT_TOKEN "6861468909:AAGMN3OKma5DOZVTWmyuvA0KBZEinEwNJ84" //<--------------------------- вставьте токен бота
#define BUZZER 4
const unsigned long BOT_MTBS = 1000;
WiFiClientSecure secured_client;
UniversalTelegramBot bot(BOT_TOKEN, secured_client);
unsigned long bot_lasttime;
#define LAMPA 16
#define LDR 18
CRGB leds[LAMPA];
#define LED_PIN 19
#define COLOR_ORDER GRB
#define CHIPSET WS2812
const int DHT_PIN = 23;
int temp ;
int hum;
String temp1;
String hum1;
DHTesp dhtSensor;
LiquidCrystal_I2C lcd(0x27, 20,4);
const int servoPin = 5;
const int servoPin15 = 15;
Servo servo1;
Servo servo2;
int pos = 0;
RTC_DS1307 rtc;
#define DS1307_ADDRESS 0x68
String t;
int i = 0;
String vent;
String heating;
String status;
String svet;
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 == "/Humidity")
{
bot.sendMessage(chat_id,String(hum1), "");
}
if (text == "/status")
{
bot.sendMessage(chat_id,status, "");
}
if (text == "/svet")
{
bot.sendMessage(chat_id,svet, "");
}
if (text == "/temperature")
{
bot.sendMessage(chat_id,String(temp1), "");
}
if (text == "/start")
{
String welcome = "привет, " + from_name + ".\n";
welcome += "/temperature : Нажми чтобы узнать сколько градусов в офисе\n";
welcome += "/Humidity : Нажми чтобы узнать какая влажность в офисе\n";
welcome += "/status : Нажми чтобы узнать состояние отопления и системы кондиционирования\n";
welcome += "/svet : Нажми чтобы узнать состояние света";
bot.sendMessage(chat_id, welcome, "Markdown");
}
}
}
void setup()
{
Serial.print("Connecting to Wifi SSID ");
Serial.print(WIFI_SSID);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
secured_client.setCACert(TELEGRAM_CERTIFICATE_ROOT);
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");
time_t now = time(nullptr);
while (now < 24 * 3600)
{
Serial.print(".");
delay(100);
now = time(nullptr);
}
Serial.println(now);
servo1.attach(servoPin, 500, 2400);
servo2.attach(servoPin15, 500, 2400);
lcd.init();
lcd.backlight();
Serial.begin(115200);
pinMode(BUZZER, OUTPUT);
pinMode(LDR, INPUT);
FastLED.addLeds<NEOPIXEL, LED_PIN>(leds,LAMPA);
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
if (! rtc.begin())
{
Serial.println("Couldn't find RTC");
Serial.flush();
abort();
}
}
void loop()
{
DateTime now = rtc.now();
int year = now.year();
int mon = now.month();
int day = now.day();
int hour = now.hour();
int minut = now.minute();
int sec = now.second();
TempAndHumidity data = dhtSensor.getTempAndHumidity();
temp = data.temperature;
hum = data.humidity;
temp1 = temp;
hum1 = hum;
lcd.setCursor(0, 0);
lcd.print("Temperature - ");
lcd.setCursor(15, 0);
lcd.print(temp1);
lcd.setCursor(0, 1);
lcd.print("Humidity - ");
lcd.setCursor(14, 1);
lcd.print(hum1);
delay(10);
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();
}
if (hour == 11 && minut <= 20 || hour == 14 && minut <= 30 || hour == 17 && minut <= 20)
{
lcd.setCursor(0, 3);
lcd.print("coffee time");
while (i < 3) {
tone(BUZZER, 330, 125);
delay(125);
tone(BUZZER, 294, 125);
delay(125);
tone(BUZZER, 262, 125);
delay(124);
tone(BUZZER, 494, 125);
delay(125);
tone(BUZZER, 440, 125);
delay(125);
tone(BUZZER, 494, 125);
delay(125);
tone(BUZZER, 262, 125);
delay(125);
tone(BUZZER, 294, 125);
delay(125);
tone(BUZZER, 330, 250);
delay(250);
tone(BUZZER, 165, 250);
delay(250);
tone(BUZZER, 440, 250);
delay(250);
i++;
}
}
else
{
lcd.setCursor(0, 3);
lcd.print("works time");
i = 0;
}
if (temp >= 25)
{
vent = "vent: on";
lcd.setCursor(0, 2);
lcd.print(vent);
for (pos = 0; pos <=180; pos += 1) {
servo2.write(pos);
delay(5);}
}
else
{
vent = "vent:off";
lcd.setCursor(0, 2);
lcd.print(vent);
servo2.write(0);
}
if (temp <= 18)
{
heating = "heating: on ";
lcd.setCursor(9, 2);
lcd.print(heating);
servo1.write(90);
delay(15);
}
else
{
heating = "heating:off ";
lcd.setCursor(9, 2);
lcd.print(heating);
servo1.write(0);
delay(15);
}
status = vent + "" + heating;
if (hour > 8 && hour < 20)
{
if (digitalRead(LDR) == LOW)
{
svet = "svet: off ";
fill_solid( leds, LAMPA, CRGB::Black);
FastLED.show();
delay(10);
}
else
{
svet = "svet: on ";
fill_solid( leds, LAMPA, CRGB::White);
FastLED.show();
delay(10);
}
}
else
{
svet = "svet: off ";
fill_solid( leds, LAMPA, CRGB::Black);
FastLED.show();
delay(10);
}
}Board not found
wokwi-custom-board
wokwi-custom-board