Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <Wire.h>
- #include <Adafruit_GFX.h>
- #include <Adafruit_SSD1306.h>
- #include <ThingSpeak.h> Knihovna thingu
- #include <DHT.h> //Knihovna dht
- #include <ESP8266WiFi.h> Knihovna ovladaciho prvku pro esp8266
- #define OLED_RESET 0 // GPIO0
- Adafruit_SSD1306 display(OLED_RESET);
- #define DHTPIN D4
- #define DHTTYPE DHT22
- DHT dht(DHTPIN, DHTTYPE);
- unsigned long myChannelNumber = 00000;
- const char * myWriteAPIKey = "000000000";
- const char* ssid = "WWW.NASVITTO.CZ";
- const char* password = "00000000000000000";
- WiFiClient client;
- WiFiServer server(80);
- void setup() {
- Serial.begin(115200);
- delay(10);
- dht.begin(); //Nacteni senzoru
- // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
- display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 64x48)
- display.display();
- // Pripojeni na wifi
- Serial.println();
- Serial.println();
- Serial.print("Pripojovani na ");
- Serial.println(ssid);
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- Serial.print(".");
- }
- Serial.println("");
- Serial.println("WiFi pripojena");
- // Start the server
- // server.begin();
- // Serial.println("Server started");
- // Vypsani ip
- Serial.println(WiFi.localIP());
- ThingSpeak.begin(client);
- }
- void loop()
- {
- delay(2000);
- display.clearDisplay();
- display.setTextSize(1);
- display.setTextColor(WHITE);
- display.setCursor(0,0);
- // Reading temperature or humidity takes about 250 milliseconds!
- // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
- float h = dht.readHumidity();
- float t = dht.readTemperature();
- float f = dht.readTemperature(true);
- // Check if any reads failed and exit early (to try again).
- if (isnan(h) || isnan(t) || isnan(f))
- {
- Serial.println("Failed to read from DHT sensor!");
- return;
- }
- //temp in c
- display.println("Teplota");
- display.print(t);
- display.println(" c");
- display.println("----------");
- display.println("----------");
- display.println("Vlhkost");
- display.print(h);
- display.println(" %");
- display.display();
- ThingSpeak.writeField(myChannelNumber, 1, h, myWriteAPIKey);
- delay(10000);
- ThingSpeak.writeField(myChannelNumber, 2, t, myWriteAPIKey);
- delay(10000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement