Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <WiFiClientSecure.h>
- #include <UniversalTelegramBot.h>
- #include <ArduinoJson.h>
- #define BLYNK_TEMPLATE_ID "TMPL7C0ij_NC"
- #define BLYNK_DEVICE_NAME "مشروع الربطة الطبية"
- #define BLYNK_AUTH_TOKEN "g8sqyiqKXWL2duca0TiCnxH3JIUxDGXw";
- #define BLYNK_PRINT Serial
- #include <ESP8266WiFi.h>
- #include <BlynkSimpleEsp8266.h>
- #include "dht.h"
- dht DHT;
- #define DHTPIN 4
- char ssid[] = "network";
- char pass[] = "123456789";
- BlynkTimer timer;
- char auth[] = BLYNK_AUTH_TOKEN;
- // Wifi network station credentials
- #define WIFI_SSID "network"
- #define WIFI_PASSWORD "123456789"
- // Telegram BOT Token (Get from Botfather)
- #define BOT_TOKEN "2063122091:AAG3cC5dGoEsZm0rp0KO54ICHsEMT8nIugE"
- // Use @myidbot (IDBot) to find out the chat ID of an individual or a group
- // Also note that you need to click "start" on a bot before it can
- // message you
- #define CHAT_ID "473975732"
- X509List cert(TELEGRAM_CERTIFICATE_ROOT);
- WiFiClientSecure secured_client;
- UniversalTelegramBot bot(BOT_TOKEN, secured_client);
- void setup()
- {
- Serial.begin(115200);
- Blynk.begin(auth, ssid, pass);
- WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
- secured_client.setTrustAnchors(&cert); // Add root certificate for api.telegram.org
- 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);
- bot.sendMessage(CHAT_ID, "Bot started up", "");
- timer.setInterval(1000L, sendSensor);
- Blynk.logEvent("test1", "optional message");
- }
- void sendSensor()
- {
- DHT.read11(DHTPIN);
- float t = DHT.temperature;
- Blynk.virtualWrite(V4, t);
- Serial.println(t);
- if (t > 23) {
- String welcome = "temp = " + String(t) + "*C\n";
- bot.sendMessage(CHAT_ID, welcome);
- }
- }
- void loop()
- {
- Blynk.run();
- timer.run();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement