Advertisement
safwan092

Untitled

Oct 9th, 2021
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. #include <WiFiClientSecure.h>
  2. #include <UniversalTelegramBot.h>
  3. #include <ArduinoJson.h>
  4.  
  5. #define BLYNK_TEMPLATE_ID "TMPL7C0ij_NC"
  6. #define BLYNK_DEVICE_NAME "مشروع الربطة الطبية"
  7. #define BLYNK_AUTH_TOKEN "g8sqyiqKXWL2duca0TiCnxH3JIUxDGXw";
  8.  
  9. #define BLYNK_PRINT Serial
  10. #include <ESP8266WiFi.h>
  11. #include <BlynkSimpleEsp8266.h>
  12. #include "dht.h"
  13. dht DHT;
  14. #define DHTPIN 4
  15.  
  16. char ssid[] = "network";
  17. char pass[] = "123456789";
  18.  
  19.  
  20. BlynkTimer timer;
  21.  
  22. char auth[] = BLYNK_AUTH_TOKEN;
  23.  
  24. // Wifi network station credentials
  25. #define WIFI_SSID "network"
  26. #define WIFI_PASSWORD "123456789"
  27. // Telegram BOT Token (Get from Botfather)
  28. #define BOT_TOKEN "2063122091:AAG3cC5dGoEsZm0rp0KO54ICHsEMT8nIugE"
  29.  
  30. // Use @myidbot (IDBot) to find out the chat ID of an individual or a group
  31. // Also note that you need to click "start" on a bot before it can
  32. // message you
  33. #define CHAT_ID "473975732"
  34.  
  35. X509List cert(TELEGRAM_CERTIFICATE_ROOT);
  36. WiFiClientSecure secured_client;
  37. UniversalTelegramBot bot(BOT_TOKEN, secured_client);
  38.  
  39.  
  40. void setup()
  41. {
  42. Serial.begin(115200);
  43. Blynk.begin(auth, ssid, pass);
  44. WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  45. secured_client.setTrustAnchors(&cert); // Add root certificate for api.telegram.org
  46. configTime(0, 0, "pool.ntp.org"); // get UTC time via NTP
  47. time_t now = time(nullptr);
  48. while (now < 24 * 3600)
  49. {
  50. Serial.print(".");
  51. delay(100);
  52. now = time(nullptr);
  53. }
  54. Serial.println(now);
  55.  
  56. bot.sendMessage(CHAT_ID, "Bot started up", "");
  57.  
  58. timer.setInterval(1000L, sendSensor);
  59. Blynk.logEvent("test1", "optional message");
  60. }
  61.  
  62. void sendSensor()
  63. {
  64. DHT.read11(DHTPIN);
  65. float t = DHT.temperature;
  66. Blynk.virtualWrite(V4, t);
  67. Serial.println(t);
  68. if (t > 23) {
  69. String welcome = "temp = " + String(t) + "*C\n";
  70. bot.sendMessage(CHAT_ID, welcome);
  71. }
  72. }
  73. void loop()
  74. {
  75. Blynk.run();
  76. timer.run();
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement