Добавить telegram-dht22.ino
This commit is contained in:
commit
dfc2ac9689
73
telegram-dht22.ino
Normal file
73
telegram-dht22.ino
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
// Lollin S2 mini
|
||||||
|
// Wemos Lollin32 Lite
|
||||||
|
|
||||||
|
#include <Wire.h>
|
||||||
|
#include <WiFi.h>
|
||||||
|
#include <DHT.h>
|
||||||
|
#include <WiFiClientSecure.h>
|
||||||
|
#include <UniversalTelegramBot.h>
|
||||||
|
|
||||||
|
#define DHTPIN 19
|
||||||
|
#define DHTTYPE DHT22
|
||||||
|
|
||||||
|
const char* ssid = "*******";
|
||||||
|
const char* password = "*******";
|
||||||
|
|
||||||
|
const char* botToken = "7787485954:AAEydfsdfsbZVGXsGwMDTZg-w_g";
|
||||||
|
const char* chatID = "-4766145654";
|
||||||
|
|
||||||
|
DHT dht(DHTPIN, DHTTYPE);
|
||||||
|
WiFiClientSecure client;
|
||||||
|
UniversalTelegramBot bot(botToken, client);
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
Wire.begin();
|
||||||
|
dht.begin();
|
||||||
|
|
||||||
|
WiFi.begin(ssid, password);
|
||||||
|
Serial.print("Connecting to WiFi");
|
||||||
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
|
delay(500);
|
||||||
|
Serial.print(".");
|
||||||
|
}
|
||||||
|
Serial.println();
|
||||||
|
Serial.print("Connected with IP: ");
|
||||||
|
Serial.println(WiFi.localIP());
|
||||||
|
|
||||||
|
client.setInsecure(); // Отключаем проверку сертификатов
|
||||||
|
|
||||||
|
sendSensorData(String(chatID));
|
||||||
|
|
||||||
|
Serial.println("Going to deep sleep for 10 seconds...");
|
||||||
|
WiFi.disconnect(true);
|
||||||
|
WiFi.mode(WIFI_OFF);
|
||||||
|
|
||||||
|
Serial.print("Controller uptime before sleep: ");
|
||||||
|
Serial.print(millis() / 1000);
|
||||||
|
Serial.println(" seconds");
|
||||||
|
|
||||||
|
esp_sleep_enable_timer_wakeup(10 * 60 * 1000000);
|
||||||
|
esp_deep_sleep_start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void sendSensorData(String chat_id) {
|
||||||
|
float humidity = dht.readHumidity();
|
||||||
|
float temperature = dht.readTemperature();
|
||||||
|
|
||||||
|
if (isnan(humidity) || isnan(temperature)) {
|
||||||
|
Serial.println("Failed to read from DHT sensor!");
|
||||||
|
bot.sendMessage(chat_id, "Failed to read from DHT sensor!", "");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String message = "DHT Температура: " + String(temperature, 1) + " °C\n";
|
||||||
|
message += "DHT Влажность: " + String(humidity, 1) + " %";
|
||||||
|
|
||||||
|
bot.sendMessage(chat_id, message, "");
|
||||||
|
Serial.println("Message sent: " + message);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// Пустой, т.к. вся логика в setup()
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user