Advertisement
djkvidp

Untitled

Nov 18th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.44 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <Wire.h>
  3. #include <Adafruit_GFX.h>
  4. #include <Adafruit_SSD1306.h>
  5. #include <ESP8266WiFi.h> //Knihovna pro rizeni ESP:
  6. #include <ESP8266HTTPClient.h> //Knihovna pro klienta:
  7. #include <MAX6675_Thermocouple.h> //Knihovna pro rizeni senzoru:
  8.  
  9. //Definovani PINu pro pripojeni Display:
  10. #define OLED_RESET 0 // GPIO0
  11. Adafruit_SSD1306 display(OLED_RESET);
  12.  
  13. //Definovani PINu pro pripojeni mereni:
  14. #define SCK_PIN 14 //(D5)
  15. #define CS_PIN 4 //(D2)
  16. #define CS2_PIN 0 //(D3)
  17. #define SO_PIN 5 //(D1)
  18.  
  19.  
  20. MAX6675_Thermocouple* thermocouple = NULL;
  21. MAX6675_Thermocouple* thermocouple2 = NULL;
  22.  
  23. const String ID_zarizeni = "ids2000"; //Definuj id zařízení:
  24.  
  25. //SSID a heslo pro Wi-Fi:
  26. const char* SSID = "WWW.***************.CZ";
  27. const char* heslo = "*****************";
  28.  
  29. void setup() {
  30.  
  31. Serial.begin(115200);
  32. thermocouple = new MAX6675_Thermocouple(SCK_PIN, CS_PIN, SO_PIN);
  33. thermocouple2 = new MAX6675_Thermocouple(SCK_PIN, CS2_PIN, SO_PIN);
  34.  
  35. // Display
  36. display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 64x48)
  37. display.display();
  38.  
  39. //Pripojeni k Wi-Fi:
  40.  
  41. Serial.println();
  42. Serial.println();
  43. Serial.print("Pripojovani k ");
  44. Serial.println(SSID);
  45. WiFi.begin(SSID, heslo);
  46.  
  47. while (WiFi.status() != WL_CONNECTED){
  48. delay(500);
  49. Serial.print(".");
  50. }
  51. Serial.println("");
  52. Serial.println("Pripojeno!");
  53.  
  54. Serial.println(WiFi.localIP());
  55.  
  56. }
  57.  
  58. // Smicka ktera se opakuje
  59.  
  60. void loop() {
  61.  
  62.  
  63.  
  64. const double celsius = thermocouple->readCelsius();
  65. const double celsius2 = thermocouple2->readCelsius();
  66.  
  67. // Display
  68.  
  69. display.clearDisplay();
  70. display.setTextSize(1);
  71. display.setTextColor(WHITE);
  72. display.setCursor(0, 0);
  73.  
  74. // Reading temperature or humidity takes about 250 milliseconds!
  75. // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  76. float t1 = thermocouple->readCelsius();
  77. float t2 = thermocouple2->readCelsius();
  78.  
  79. // Check if any reads failed and exit early (to try again).
  80. if (isnan(t1) || isnan(t2))
  81. {
  82. Serial.println("Nepodarilo se najit senzor");
  83. return;
  84. }
  85. //temp in c
  86. display.println("Teplota");
  87. display.print(t1);
  88. display.println(" c");
  89. display.println("----------");
  90. display.println("----------");
  91. display.println("Vlhkost");
  92. display.print(t2);
  93. display.println(" %");
  94. display.display();
  95.  
  96.  
  97. // Display konec
  98.  
  99.  
  100. Serial.println("Teplota senzor 1: ");
  101. Serial.println(String(celsius) + " C, ");
  102.  
  103. Serial.println("Teplota senzor 2: ");
  104. Serial.println(String(celsius2) + " C, ");
  105.  
  106. if (WiFi.status() == WL_CONNECTED) { //Kontroluje pripojeni k wifi
  107.  
  108. HTTPClient http; //Deklaruje http klienta
  109.  
  110. http.begin("http://192.168.0.103/polycom/databaze.php?t1=" + String(celsius) + "&t2=" + String(celsius2) + "&z=" + ID_zarizeni); //Specify request destination
  111. int httpCode = http.GET(); //Odesila pozadavky na adresu
  112.  
  113. //Pouze pokud potřebujeme odpověď ze serveru, například JSON data
  114. /*
  115. if (httpCode > 0) { //Check the returning code
  116.  
  117. // String payload = http.getString(); //Get the request response payload
  118. // Serial.println(payload); //Print the response payload
  119.  
  120. }
  121. */
  122.  
  123. http.end(); //uzavira pripojeni
  124. }
  125.  
  126. delay(60000); //Prodleva pred opakovanim (1 minuta)
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement