Advertisement
djkvidp

Arduino - Měření pecí

May 19th, 2019
468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <ESP8266WiFi.h> //Knihovna pro rizeni ESP:
  2. #include <ESP8266HTTPClient.h> //Knihovna pro klienta:
  3. #include <MAX6675_Thermocouple.h> //Knihovna pro rizeni senzoru:
  4.  
  5. //Definovani PINU pro pripojeni:
  6.  
  7. #define SCK_PIN 14    //(D5)
  8. #define CS_PIN  16     //(D0) // SENZOR 1
  9. #define CS2_PIN 15    //(D8) // SENZOR 2
  10. #define SO_PIN 12     //(D6)
  11.  
  12.  
  13. MAX6675_Thermocouple* thermocouple = NULL;
  14. MAX6675_Thermocouple* thermocouple2 = NULL;
  15.  
  16. const String ID_zarizeni = "ids2002"; //Definuj id zařízení:
  17.  
  18. //SSID a heslo pro Wi-Fi:
  19. const char* SSID = "*********";
  20. const char* heslo = "*******";
  21.  
  22. void setup() {
  23.   Serial.begin(115200);
  24.   thermocouple = new MAX6675_Thermocouple(SCK_PIN, CS_PIN, SO_PIN); // SENZOR 1
  25.   thermocouple2 = new MAX6675_Thermocouple(SCK_PIN, CS2_PIN, SO_PIN); // SENZOR 2  
  26.    
  27.   //Pripojeni k Wi-Fi:
  28.    
  29.     Serial.println();
  30.     Serial.println();
  31.     Serial.print("Pripojovani k ");
  32.     Serial.println(SSID);  
  33.     WiFi.begin(SSID, heslo);
  34.    
  35.     while (WiFi.status() != WL_CONNECTED){
  36.         delay(500);
  37.         Serial.print(".");
  38.         }
  39.     Serial.println("");
  40.     Serial.println("Pripojeno!");
  41.    
  42.     Serial.println(WiFi.localIP());
  43.  
  44. }
  45.  
  46. // Smicka ktera se opakuje
  47.  
  48. void loop() {
  49.   const double celsius = thermocouple->readCelsius();
  50.   const double celsius2 = thermocouple2->readCelsius();
  51.  
  52.   Serial.println("Teplota senzor 1: ");
  53.   Serial.println(String(celsius) + " C, ");
  54.  
  55.   Serial.println("Teplota senzor 2: ");
  56.   Serial.println(String(celsius2) + " C, ");
  57.  
  58.   if (WiFi.status() == WL_CONNECTED) { //Kontroluje pripojeni k wifi
  59.  
  60.     HTTPClient http;  //Deklaruje http klienta
  61.  
  62.     http.begin("http://***************/databaze.php?t1=" + String(celsius) + "&t2=" + String(celsius2) + "&z=" + ID_zarizeni);  //Určete cílové požadavky (teplota,vlhkost atd)
  63.     int httpCode = http.GET();   //Odesila pozadavky na adresu
  64.  
  65.     //Pouze pokud potřebujeme odpověď ze serveru, například JSON data
  66.     /*
  67.     if (httpCode > 0) { //Check the returning code
  68.  
  69.      // String payload = http.getString();   //Get the request response payload
  70.      // Serial.println(payload);                     //Print the response payload
  71.  
  72.     }
  73.     */
  74.  
  75.     http.end();   //uzavira pripojeni  
  76.   }
  77.  
  78.   delay(60000); //Prodleva pred opakovanim (1 minuta)
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement