djkvidp

Untitled

Nov 18th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  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 = 613230;
  18. const char * myWriteAPIKey = "WJKU5V7M04ET9507";
  19.  
  20. const char* ssid = "***************";
  21. const char* password = "*****************";
  22.  
  23. WiFiClient client;
  24. WiFiServer server(80);
  25.  
  26. #define LED 0
  27.  
  28. void setup() {
  29. pinMode(0, OUTPUT); //-D7
  30. digitalWrite(0, HIGH);
  31.  
  32. Serial.begin(115200);
  33. delay(10);
  34. dht.begin(); //Nacteni senzoru
  35. // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
  36. display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 64x48)
  37. display.display();
  38.  
  39. // Pripojeni na wifi
  40. Serial.println();
  41. Serial.println();
  42. Serial.print("Pripojovani na ");
  43. Serial.println(ssid);
  44.  
  45. WiFi.begin(ssid, password);
  46.  
  47. while (WiFi.status() != WL_CONNECTED) {
  48. delay(500);
  49. Serial.print(".");
  50. }
  51. Serial.println("");
  52. Serial.println("WiFi pripojena");
  53.  
  54. // Start the server
  55. // server.begin();
  56. // Serial.println("Server started");
  57. // Vypsani ip
  58. Serial.println(WiFi.localIP());
  59.  
  60. ThingSpeak.begin(client);
  61.  
  62. }
  63.  
  64. void loop()
  65. {
  66. delay(2000);
  67. display.clearDisplay();
  68. display.setTextSize(1);
  69. display.setTextColor(WHITE);
  70. display.setCursor(0, 0);
  71. // Reading temperature or humidity takes about 250 milliseconds!
  72. // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  73. float h = dht.readHumidity();
  74. float t = dht.readTemperature();
  75. float f = dht.readTemperature(true);
  76. // Check if any reads failed and exit early (to try again).
  77. if (isnan(h) || isnan(t) || isnan(f))
  78. {
  79. Serial.println("Failed to read from DHT sensor!");
  80. return;
  81. }
  82. //temp in c
  83. display.println("Teplota");
  84. display.print(t);
  85. display.println(" c");
  86. display.println("----------");
  87. display.println("----------");
  88. display.println("Vlhkost");
  89. display.print(h);
  90. display.println(" %");
  91. display.display();
  92.  
  93. ThingSpeak.writeField(myChannelNumber, 1, h, myWriteAPIKey);
  94. delay(60000);
  95.  
  96.  
  97. ThingSpeak.writeField(myChannelNumber, 2, t, myWriteAPIKey);
  98. delay(60000);
  99.  
  100. }
Add Comment
Please, Sign In to add comment