Advertisement
Guest User

Meteostanice

a guest
May 24th, 2018
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.20 KB | None | 0 0
  1. #include <BH1750.h>
  2. #include <BME280.h>
  3. #include <CCS811.h>
  4. #include <ESP8266WiFi.h>
  5. #include <HTTPSRedirect.h>
  6. #include <Wire.h>
  7.  
  8. IPAddress ip(192, 168, 1, 101);
  9. IPAddress gateway(192, 168, 1, 1);
  10. IPAddress subnet(255, 255, 255, 0);
  11.  
  12. const char* Nazev_WiFi = "přísně tajné";
  13. const char* Heslo_WiFi = "přísně tajné";
  14.  
  15. const char* Google_Script_ID = "přísně tajné";
  16. const char* Google_Script_host = "script.google.com";
  17. const char* Google_Script_host_presmerovani = "script.googleusercontent.com";
  18.  
  19. const int HTTPS_port = 443;
  20. HTTPSRedirect client(HTTPS_port);
  21.  
  22. String Google_Script_URL = String("/macros/s/") + Google_Script_ID + "/exec?";
  23.  
  24. BME280 teplomer;
  25.  
  26. #define ADDR 0x5A
  27. #define WAKE_PIN 4
  28. CCS811 CO2senzor;
  29.  
  30. BH1750 luxmetr;
  31.  
  32. void setup(){
  33.   Serial.begin(115200);
  34.   delay(10);
  35.   teplomer.begin();
  36.   CO2senzor.begin(ADDR, WAKE_PIN);
  37.   luxmetr.begin();
  38.  
  39.   WiFi.config(ip, gateway, subnet);
  40.   WiFi.begin(Nazev_WiFi, Heslo_WiFi);
  41.   while(WiFi.status() != WL_CONNECTED){
  42.     delay(500);
  43.     Serial.print("▒");
  44.   }
  45. }
  46.  
  47. void OdeslatData(float teplota, float vlhkost, float tlak, float CO2, float svetlo){
  48.   if(!client.connected()){
  49.     client.connect(Google_Script_host, HTTPS_port);
  50.   }
  51.   String Google_Script_URL_finalni = Google_Script_URL + "teplota=" + teplota + "&vlhkost=" + vlhkost + "&tlak=" + tlak + "&CO2=" + CO2 + "&svetlo=" + svetlo;
  52.   client.printRedir(Google_Script_URL_finalni, Google_Script_host, Google_Script_host_presmerovani);
  53. }
  54.  
  55. void loop(){
  56.   CO2senzor.getData();
  57.   float teplota = teplomer.readTemp();
  58.   float vlhkost = teplomer.readHumidity();
  59.   float tlak_pa = teplomer.readPressure();
  60.   float tlak_hpa;
  61.   float CO2 = CO2senzor.readCO2();
  62.   uint16_t svetlo = luxmetr.readLightLevel();
  63.  
  64.   Serial.println();
  65.   Serial.println("Teplota vzduchu: "+String(teplota)+" st. C");
  66.   Serial.println("Relativní vlhkost vzduchu: "+String(vlhkost)+" %");
  67.   tlak_hpa = tlak_pa/100;
  68.   Serial.println("Atmosférický tlak: "+String(tlak_hpa)+" hPa");
  69.   Serial.println("CO2: "+String(CO2)+" ppm");
  70.   Serial.println("Intenzita světla: "+String(svetlo)+" lx");
  71.   Serial.println();
  72.  
  73.   OdeslatData(teplota, vlhkost, tlak_hpa, CO2, svetlo);
  74.  
  75.   delay(10000);
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement