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 <ESP8266WiFi.h> //Knihovna pro rizeni ESP:
- #include <ESP8266HTTPClient.h> //Knihovna pro klienta:
- #include <MAX6675_Thermocouple.h> //Knihovna pro rizeni senzoru:
- //Definovani PINu pro pripojeni Display:
- #define OLED_RESET 0 // GPIO0
- Adafruit_SSD1306 display(OLED_RESET);
- //Definovani PINu pro pripojeni mereni:
- #define SCK_PIN 14 //(D5)
- #define CS_PIN 4 //(D2)
- #define CS2_PIN 0 //(D3)
- #define SO_PIN 5 //(D1)
- MAX6675_Thermocouple* thermocouple = NULL;
- MAX6675_Thermocouple* thermocouple2 = NULL;
- const String ID_zarizeni = "ids2000"; //Definuj id zařízení:
- //SSID a heslo pro Wi-Fi:
- const char* SSID = "WWW.***************.CZ";
- const char* heslo = "*****************";
- void setup() {
- Serial.begin(115200);
- thermocouple = new MAX6675_Thermocouple(SCK_PIN, CS_PIN, SO_PIN);
- thermocouple2 = new MAX6675_Thermocouple(SCK_PIN, CS2_PIN, SO_PIN);
- // Display
- display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 64x48)
- display.display();
- //Pripojeni k Wi-Fi:
- Serial.println();
- Serial.println();
- Serial.print("Pripojovani k ");
- Serial.println(SSID);
- WiFi.begin(SSID, heslo);
- while (WiFi.status() != WL_CONNECTED){
- delay(500);
- Serial.print(".");
- }
- Serial.println("");
- Serial.println("Pripojeno!");
- Serial.println(WiFi.localIP());
- }
- // Smicka ktera se opakuje
- void loop() {
- const double celsius = thermocouple->readCelsius();
- const double celsius2 = thermocouple2->readCelsius();
- // Display
- 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 t1 = thermocouple->readCelsius();
- float t2 = thermocouple2->readCelsius();
- // Check if any reads failed and exit early (to try again).
- if (isnan(t1) || isnan(t2))
- {
- Serial.println("Nepodarilo se najit senzor");
- return;
- }
- //temp in c
- display.println("Teplota");
- display.print(t1);
- display.println(" c");
- display.println("----------");
- display.println("----------");
- display.println("Vlhkost");
- display.print(t2);
- display.println(" %");
- display.display();
- // Display konec
- Serial.println("Teplota senzor 1: ");
- Serial.println(String(celsius) + " C, ");
- Serial.println("Teplota senzor 2: ");
- Serial.println(String(celsius2) + " C, ");
- if (WiFi.status() == WL_CONNECTED) { //Kontroluje pripojeni k wifi
- HTTPClient http; //Deklaruje http klienta
- http.begin("http://192.168.0.103/polycom/databaze.php?t1=" + String(celsius) + "&t2=" + String(celsius2) + "&z=" + ID_zarizeni); //Specify request destination
- int httpCode = http.GET(); //Odesila pozadavky na adresu
- //Pouze pokud potřebujeme odpověď ze serveru, například JSON data
- /*
- if (httpCode > 0) { //Check the returning code
- // String payload = http.getString(); //Get the request response payload
- // Serial.println(payload); //Print the response payload
- }
- */
- http.end(); //uzavira pripojeni
- }
- delay(60000); //Prodleva pred opakovanim (1 minuta)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement