#include #include "DHT.h" #define RX 10 #define TX 11 #define DHTPIN 8 #define DHTTYPE DHT11 // DHT 11 DHT dht(DHTPIN, DHTTYPE); String AP = "cencurovano"; // CHANGE ME String PASS = "cenzurovano"; // CHANGE ME String API = "cenzurovano"; // CHANGE ME String HOST = "api.thingspeak.com"; String PORT = "80"; String field = "field1"; int countTrueCommand; int countTimeCommand; boolean found = false; int valSensor = 1; SoftwareSerial esp8266(RX,TX); void setup() { Serial.begin(9600); esp8266.begin(115200); sendCommand("AT",5,"OK"); sendCommand("AT+CWMODE=1",5,"OK"); sendCommand("AT+CWJAP=\""+ AP +"\",\""+ PASS +"\"",20,"OK"); Serial.println("KY-015 test - temperature and humidity-test:"); } void loop() { //čidlo vlhkosti a teploty dht.begin(); // Two second break between measurements delay(2000); // Measurement of humidity float h = dht.readHumidity(); // Measurement of temperature float t = dht.readTemperature(); // The measurements will be tested of errors here // If an error is detected, an error message will be displayed if (isnan(h) || isnan(t)) { Serial.println("Error while reading the sensor"); return; } // Output at the serial console Serial.println("-----------------------------------------------------------"); Serial.print("Humidity: "); Serial.print(h); Serial.print(" %\t"); Serial.print("temperature: "); Serial.print(t); Serial.print(char(186)); //Output <°> symbol Serial.println("°C "); Serial.println("-----------------------------------------------------------"); Serial.println(" "); //konec čidla vlhkosti a teploty valSensor = getSensorData(); String getData = "GET /update?api_key="+ API +"&"+ field +"="+String(valSensor); // sendCommand("AT+CIPMUX=1",5,"OK"); sendCommand("AT+CIPSTART=0,\"TCP\",\""+ HOST +"\","+ PORT,15,"OK"); sendCommand("AT+CIPSEND=0," +String(getData.length()+4),4,">"); esp8266.println(getData);delay(1500);countTrueCommand++; sendCommand("AT+CIPCLOSE=0",5,"OK"); Serial.println("tudydadydá!"); Serial.println(t); } int getSensorData(){ return random(1000); // Replace with } void sendCommand(String command, int maxTime, char readReplay[]) { Serial.print(countTrueCommand); Serial.print(". at command => "); Serial.print(command); Serial.print(" "); while(countTimeCommand < (maxTime*1)) { esp8266.println(command);//at+cipsend if(esp8266.find(readReplay))//ok { found = true; break; } countTimeCommand++; } if(found == true) { Serial.println("OK!"); countTrueCommand++; countTimeCommand = 0; } if(found == false) { Serial.println("Fail!"); countTrueCommand = 0; countTimeCommand = 0; } found = false; }