#include #include #include #include "Adafruit_SHT4x.h" Adafruit_SHT4x sht4 = Adafruit_SHT4x(); String URL = "http://www.xxxxxxxxxx.cz/xxxxxxxxxx.php"; const char* ssid = "xxxxxxxx"; const char* password = "xxxxxxxxx"; //float temp = 0; //float humidity = 0; //char x [10]; //char y [10]; void setup() { Serial.begin(115200); Wire.begin(19,18); // I2C sbernicce pro cidlo teploty a vlhkosti /* NASTAVENI CIDLA TEPLOTY A VLHKOSTI */ sht4.begin(); // inicializace sht4.setPrecision(SHT4X_HIGH_PRECISION); // vysoka presnost mreni sht4.setHeater(SHT4X_NO_HEATER); // bez interniho ohrivace /*--------------------------------------*/ connectWiFi(); } void loop() { if(WiFi.status() != WL_CONNECTED) { connectWiFi(); } /* CIDLO TEPLOTY A VLHKOSTI */ sensors_event_t humidity, temp; sht4.getEvent(&humidity, &temp); // cekani na aktualni data Serial.print("Teplota: "); Serial.print(temp.temperature); Serial.println(" stC"); Serial.print("Vlhkost: "); Serial.print(humidity.relative_humidity); Serial.println("% rH"); /*--------------------------*/ //dtostrf(temp.temperature, 6, 4, x); //dtostrf(humidity.relative_humidity, 6, 4, y); //String postData = "temperature=" + String(x) + "&humidity=" + String(y); String postData = "temperature=" + String(temp.temperature) + "&humidity=" + String(humidity.relative_humidity); HTTPClient http; http.begin(URL); http.addHeader("Content-Type", "application/x-www-form-urlencoded"); int httpCode = http.POST(postData); String payload = http.getString(); Serial.print("URL : "); Serial.println(URL); Serial.print("Data: "); Serial.println(postData); Serial.print("httpCode: "); Serial.println(httpCode); Serial.print("payload : "); Serial.println(payload); Serial.println("--------------------------------------------------"); delay(120000); } void connectWiFi() { WiFi.mode(WIFI_OFF); delay(1000); //This line hides the viewing of ESP as wifi hotspot WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); Serial.println("Connecting to WiFi"); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.print("connected to : "); Serial.println(ssid); Serial.print("IP address: "); Serial.println(WiFi.localIP()); }