Advertisement
overvolt

Stazione Meteo Arduino V1.0

Apr 23rd, 2024
1,470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.63 KB | None | 0 0
  1.  
  2. // E-INK
  3. #include <GxEPD.h>
  4. #include <GxIO/GxIO_SPI/GxIO_SPI.h>
  5. #include <GxIO/GxIO.h>
  6. #include <GxGDEH0154D67/GxGDEH0154D67.h>
  7.  
  8. #include "bitmap.h"
  9.  
  10. #include <Fonts/FreeSansBold18pt7b.h>     //FONT SANS BOL 18P
  11. #include <Fonts/FreeSansBold24pt7b.h>     //FONT SANS BOL 24P
  12.  
  13. GxIO_Class io(SPI, 10, 9, 8);   // CREO SERIALE PER E-INK -- CS DC RST
  14. GxEPD_Class display(io, 8, 7);  // CREO DISPLAY PER E-INK -- Seriale RST BUSY
  15.  
  16.  
  17. // WIFI E TELEGRAM
  18. #include <WiFi.h>
  19. #include <WiFiClientSecure.h>
  20. #include <UniversalTelegramBot.h>
  21.  
  22. const char* ssid = "arduinooo";
  23. const char* password = "arduinami";
  24.  
  25. #define BOTToken "xxxxx"
  26. #define CHAT_ID "xxxxx"
  27.  
  28. WiFiClientSecure client;
  29. UniversalTelegramBot bot(BOTToken, client);
  30.  
  31.  
  32. // SENSORI
  33. #include "DHT.h"
  34. #include "MQ135.h"
  35.  
  36. MQ135 mq135_sensor(A1);
  37. DHT dht(2, DHT11);
  38.  
  39. float t, h, PPM;
  40.  
  41.  
  42.  
  43. void setup() {
  44.   Serial.begin(115200);
  45.   display.init();
  46.   display.setRotation(2);
  47.  
  48.   dht.begin();
  49.  
  50.   WiFi.mode(WIFI_STA);
  51.  
  52.   splash();
  53. }
  54.  
  55.  
  56. void loop() {
  57.   lettura_sensori();
  58.   stampa_valori();
  59.   messaggio();
  60.   delay(3600000);
  61. }
  62.  
  63.  
  64. void splash() {
  65.   display.eraseDisplay();                                       //SVUOTO DISPLAY
  66.   display.drawExampleBitmap(logo, 0, 0, 200, 200, GxEPD_BLACK); //SETTO IL LOGO
  67.   display.update();                                             //STAMPO
  68.   delay(3000);                                                  //ASPETTO 3 SEC
  69.  
  70.   display.drawExampleBitmap(gui, 0, 0, 200, 200, GxEPD_BLACK);
  71.   display.update();                                             //STAMPO
  72. }
  73.  
  74.  
  75. void lettura_sensori() {
  76.   t = dht.readTemperature();
  77.   h = dht.readHumidity();
  78.   PPM = mq135_sensor.getCorrectedPPM(t, h);
  79. }
  80.  
  81.  
  82. void stampa_valori() {
  83.   display.setRotation(3);
  84.   display.fillRect(65,0,135,200, GxEPD_WHITE);
  85.  
  86.   display.setFont(&FreeSansBold24pt7b);
  87.   display.setTextColor(GxEPD_BLACK);
  88.  
  89.   display.setCursor(65,50);
  90.   display.print(String(t,1));
  91.  
  92.   display.setCursor(65,115);
  93.   display.print(String(h,0) + "%");
  94.  
  95.   display.setCursor(65,180);
  96.   if (PPM > 100000) display.setFont(&FreeSansBold18pt7b);
  97.   display.print(String(PPM,0));
  98.  
  99.   display.update();
  100. }
  101.  
  102.  
  103. void messaggio() {
  104.   WiFi.begin(ssid, password);
  105.   client.setCACert(TELEGRAM_CERTIFICATE_ROOT);
  106.  
  107.   while (WiFi.status() != WL_CONNECTED) {
  108.     delay(500);
  109.     Serial.print(".");
  110.   }
  111.   Serial.println("");
  112.   Serial.println("WiFi connesso");
  113.  
  114.   bot.sendMessage(CHAT_ID, "\xf0\x9f\x8c\xa1 " + String(t,1) + "°C \n \xf0\x9f\x92\xa7 " + String(h,0) + "% \n \xf0\x9f\x92\xa8 " + String(PPM,0) + " PPM");  //invia il messaggio
  115.  
  116.   WiFi.disconnect(true);
  117.   WiFi.mode(WIFI_OFF);
  118. }
  119.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement