Advertisement
djkvidp

Untitled

Nov 1st, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <SPI.h>
  2. #include <Wire.h>
  3. #include <Adafruit_GFX.h>
  4. #include <Adafruit_SSD1306.h>
  5. #include <ThingSpeak.h> Knihovna thingu
  6. #include <DHT.h> //Knihovna dht
  7. #include <ESP8266WiFi.h> Knihovna ovladaciho prvku pro esp8266
  8.  
  9.  
  10. #define OLED_RESET 0  // GPIO0
  11. Adafruit_SSD1306 display(OLED_RESET);
  12.  
  13. #define DHTPIN D4
  14. #define DHTTYPE DHT22  
  15. DHT dht(DHTPIN, DHTTYPE);
  16.  
  17. unsigned long myChannelNumber = 00000;
  18. const char * myWriteAPIKey = "000000000";
  19.  
  20. const char* ssid = "WWW.NASVITTO.CZ";
  21. const char* password = "00000000000000000";
  22.  
  23. WiFiClient  client;
  24. WiFiServer server(80);
  25.  
  26. void setup() {
  27.   Serial.begin(115200);
  28.   delay(10);
  29.   dht.begin(); //Nacteni senzoru
  30.   // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
  31.   display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 64x48)
  32.   display.display();
  33.  
  34.   // Pripojeni na wifi
  35.   Serial.println();
  36.   Serial.println();
  37.   Serial.print("Pripojovani na ");
  38.   Serial.println(ssid);
  39.  
  40.   WiFi.begin(ssid, password);
  41.  
  42.   while (WiFi.status() != WL_CONNECTED) {
  43.     delay(500);
  44.     Serial.print(".");
  45.   }
  46.   Serial.println("");
  47.   Serial.println("WiFi pripojena");
  48.  
  49.   // Start the server
  50.   // server.begin();
  51.   // Serial.println("Server started");
  52.   // Vypsani ip
  53.   Serial.println(WiFi.localIP());
  54.  
  55.   ThingSpeak.begin(client);
  56.  
  57. }
  58.  
  59. void loop()
  60. {
  61.   delay(2000);
  62.   display.clearDisplay();
  63.   display.setTextSize(1);
  64.   display.setTextColor(WHITE);
  65.   display.setCursor(0,0);
  66.   // Reading temperature or humidity takes about 250 milliseconds!
  67.   // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  68.   float h = dht.readHumidity();
  69.   float t = dht.readTemperature();
  70.   float f = dht.readTemperature(true);
  71.   // Check if any reads failed and exit early (to try again).
  72.   if (isnan(h) || isnan(t) || isnan(f))
  73.   {
  74.     Serial.println("Failed to read from DHT sensor!");
  75.     return;
  76.   }
  77.   //temp in c
  78.   display.println("Teplota");
  79.   display.print(t);
  80.   display.println(" c");
  81.   display.println("----------");
  82.   display.println("----------");
  83.   display.println("Vlhkost");
  84.   display.print(h);
  85.   display.println(" %");
  86.   display.display();
  87.  
  88.   ThingSpeak.writeField(myChannelNumber, 1, h, myWriteAPIKey);
  89.   delay(10000);
  90.  
  91.  
  92.   ThingSpeak.writeField(myChannelNumber, 2, t, myWriteAPIKey);
  93.   delay(10000);
  94.  
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement