Advertisement
Guest User

Untitled

a guest
May 26th, 2021
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.30 KB | None | 0 0
  1. #include <ESP8266WiFi.h>
  2. #include "DHT.h"
  3. #include <Adafruit_BMP085.h>
  4. #include <Wire.h>
  5. #include <LiquidCrystal_I2C.h>
  6.  
  7. LiquidCrystal_I2C lcd(0x27, 20, 4);
  8. #define pinDHT D13
  9. #define typDHT22 DHT22 // DHT 22 (AM2302)
  10. DHT mojeDHT(pinDHT, typDHT22);
  11. const int myPeriodic = 300; // Time to sleep (in seconds):
  12. Adafruit_BMP085 bmp;
  13. // Nazev Wi-Fi site, do ktere se mam pripojit
  14. const char* ssid = "Kony";
  15. // Heslo Wi-Fi site, do ktere se mam pripojit
  16. const char* password = "sdfsfsdf";
  17. char server[] = "sdfsdfsdfsdf"; //URL adresa serveru
  18. WiFiClient client;
  19. unsigned long cas = 0;
  20. String cas_aktualni;
  21. String den;
  22. float tep;
  23. float vlh;
  24. float tlak_aktualni;
  25.  
  26. void setup() {
  27. lcd.begin();
  28. lcd.backlight();
  29. // komunikace přes sériovou linku rychlostí 9600 baud
  30. Serial.begin(9600);
  31. // zapnutí komunikace s teploměrem DHT
  32. mojeDHT.begin();
  33. if (!bmp.begin()) {
  34. Serial.println("Could not find BMP180 or BMP085 sensor at 0x77");
  35. while (1) {}
  36. }
  37. Serial.println();
  38. Serial.print("Pripojuji k ");
  39. Serial.println(ssid);
  40. WiFi.begin(ssid, password);
  41.  
  42. // Dokud nejsem pripojeny k Wi-Fi,zapisuj do seriove linky tecky progressbaru
  43. while (WiFi.status() != WL_CONNECTED) {
  44. delay(100);
  45. Serial.print(".");
  46. lcd.setCursor ( 0, 0 );
  47. lcd.print(".");
  48. }
  49.  
  50. // Jsem pripojeny k Wi-Fi a mohu pokracovat
  51. Serial.println();
  52. Serial.println("WiFi pripojena!");
  53. lcd.setCursor ( 0, 1 );
  54. lcd.print("Wifi Pripojena!");
  55.  
  56. // Napis IP adresu, kterou mikropocitac dostal
  57. Serial.print("Pouzij k pripojeni tuto adresu: ");
  58. Serial.print("http://");
  59. Serial.println(WiFi.localIP());
  60. lcd.setCursor ( 0, 2 );
  61. lcd.print(WiFi.localIP());
  62. delay(2000);
  63. lcd.clear();
  64. }
  65.  
  66. void teplota_vlhkost() {
  67. tep = mojeDHT.readTemperature();
  68. delay(2000);
  69. vlh = mojeDHT.readHumidity();
  70. // kontrola, jestli jsou načtené hodnoty čísla pomocí funkce isnan
  71. if (isnan(tep) || isnan(vlh)) {
  72. // při chybném čtení vypiš hlášku
  73. Serial.println("Chyba při čtení z DHT senzoru!");
  74. } else {
  75. // pokud jsou hodnoty v pořádku,
  76. // vypiš je po sériové lince
  77. Serial.print("Teplota: ");
  78. Serial.print(tep,1);
  79. Serial.println(" °C");
  80. Serial.print("Vlhkost: ");
  81. Serial.print(vlh,0);
  82. Serial.println(" %");
  83. lcd.setCursor ( 1, 1 );
  84. lcd.print("Teplota : ");
  85. lcd.setCursor ( 11, 1 );
  86. lcd.print(" ");
  87. lcd.setCursor ( 11, 1 );
  88. lcd.print(tep,1);
  89. lcd.print(" ");
  90. lcd.print((char)223);
  91. lcd.print("C");
  92. lcd.setCursor ( 1,2 );
  93. lcd.print("Vlhkost : ");
  94. lcd.setCursor ( 11,2 );
  95. lcd.print(vlh,0);
  96. lcd.print(F(" %"));
  97. }
  98. // pauza pro přehlednější výpis
  99. delay(2000);
  100. }
  101.  
  102. void tlak() {
  103. tlak_aktualni = (bmp.readPressure()/100)+38;
  104. Serial.print("Tlak : ");
  105. Serial.print(tlak_aktualni,0);
  106. Serial.println(" hPa");
  107. lcd.setCursor ( 2,3 );
  108. lcd.print("Tlak :");
  109. lcd.setCursor ( 11,3 );
  110. lcd.print(tlak_aktualni,0);
  111. lcd.print(F(" hPa"));
  112. }
  113.  
  114. void hodiny() {
  115. if (millis() - cas >= 6000 || cas == 0) {
  116. cas = millis();
  117. if (client.connect(server, 80)) { //starts client connection, checks for connection
  118. client.println("GET http://sfsdfsdf/cas.php");
  119. client.println("Host: sfsdfsdfsdf");
  120. client.println("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
  121. client.println("Connection: close");
  122. client.println();
  123. delay(1000);
  124. while (client.connected()) {
  125. String line = client.readStringUntil('\n');
  126. // Serial.println(line); //ak chceme vypísať HTTP header
  127. if (line == "\r") {
  128. break;
  129. }
  130. }
  131. String line = client.readStringUntil('\n');
  132. // Serial.println("Nacitany payload response: Cas - ");
  133. // Serial.println(line); //odpoveď webservera - naše dáta
  134. cas_aktualni = line;
  135. }
  136. else {
  137. Serial.println("Pripojenie na webserver sa nepodarilo");
  138. }
  139. client.stop();
  140. }
  141. Serial.print("Cas : ");
  142. Serial.println(cas_aktualni);
  143. lcd.setCursor ( 15,0 );
  144. lcd.print(cas_aktualni);
  145. }
  146.  
  147. void den_tydnu() {
  148. if (millis() - cas >= 6000 || cas == 0) {
  149. cas = millis();
  150. if (client.connect(server, 80)) { //starts client connection, checks for connection
  151. client.println("GET http://sdfsdfsdf/datum.php");
  152. client.println("Host: sdfsdfsdf");
  153. client.println("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
  154. client.println("Connection: close");
  155. client.println();
  156. delay(1000);
  157. while (client.connected()) {
  158. String line = client.readStringUntil('\n');
  159. // Serial.println(line); //ak chceme vypísať HTTP header
  160. if (line == "\r") {
  161. break;
  162. }
  163. }
  164. String line = client.readStringUntil('\n');
  165. // Serial.println("Nacitany payload response: Cas - ");
  166. // Serial.println(line); //odpoveď webservera - naše dáta
  167. den = line;
  168. }
  169. else {
  170. Serial.println("Pripojenie na webserver sa nepodarilo");
  171. }
  172. client.stop();
  173. }
  174. Serial.print("Den : ");
  175. Serial.println(den);
  176. lcd.setCursor ( 0,0 );
  177. lcd.print(" ");
  178. lcd.setCursor ( 0,0 );
  179. lcd.print(den);
  180. }
  181.  
  182. void cekej(int t) {
  183. unsigned long pm = millis();
  184. while (millis() - pm <= t)
  185. {
  186. hodiny();
  187. den_tydnu();
  188. teplota_vlhkost();
  189. tlak();
  190. Serial.println("_________________________");
  191. delay(10000);
  192. }
  193. }
  194.  
  195. void odesli() {
  196. if(client.connect(server, 80)){
  197. client.print("GET http://sdfsdfsdf/logger_venku.php?teplota=");
  198. client.print(tep,0);
  199. client.print("&vlhkost=");
  200. client.print(vlh,0);
  201. client.print("&tlak=");
  202. client.println(tlak_aktualni,0);
  203. client.println("Host: sdfsdfsdf");
  204. client.println("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
  205. client.println("Connection: close");
  206. client.println();
  207. client.stop();
  208. Serial.println("odeslano");
  209. Serial.println("_________________________");
  210. cekej(600000);
  211. }
  212. }
  213.  
  214. void loop() {
  215. teplota_vlhkost();
  216. tlak();
  217. hodiny();
  218. den_tydnu();
  219. Serial.println("_________________________");
  220. odesli();
  221. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement