// Iot.electronixforu.com // username xxxx, password xxxx // Hardware: ESP8266 generic,DHT11 //date august 30, 2018 //pASSHROUGH mODE FASTER MODE //tested on august 31, 2018, time 2:53AM //auto connect after internet interruption #include // Including library for dht #include String apikey = "6a22f591bd197"; // Enter your API key from iot.electronixforu.com const char *ssid = "ultra HD"; // replace with your wifi ssid and wpa2 key const char *pass = "12345678"; const char* server = "iot.electronixforu.com"; String web = "iot.electronixforu.com"; #define DHTPIN 0 //pin where the dht11 is connected DHT dht(DHTPIN, DHT11); WiFiClient client; void setup() { Serial.begin(115200); delay(10); dht.begin(); Serial.println("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, pass); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected"); init_esp(); } //*************************main Loop void loop() { float h = dht.readHumidity(); float t = dht.readTemperature(); //float h = 33.4; //float t = 12.5; if (isnan(h) || isnan(t)) { Serial.println("Failed to read from DHT sensor!"); return; } if (client.connect(server,80)) { String getStrf = "GET /post.php?api_key="; getStrf += apikey; getStrf +="&field1="; getStrf += String(t); getStrf += "&field2="; getStrf += String(h); getStrf +="&field3="; getStrf += String(t); getStrf += "&field4="; getStrf += String(h); getStrf += " HTTP/1.1"; getStrf += String("\r\n"); getStrf += "Host: "; getStrf += web; getStrf += String("\r\n\r\n"); client.print(getStrf); Serial.print("Temperature: "); Serial.print(t); Serial.print(" degrees Celcius, Humidity: "); Serial.print(h); Serial.println("%. Send to iot_web."); } client.stop(); Serial.println("Waiting..."); delay(1000); } //****************initialize ESP8266 with Passthrough mode for iot.electronixforu.com************** void init_esp() { Serial.println("initializing"); client.print ("AT+CIPMUX=0"); // set esp8266 as client delay(1000); //ser.println ("AT+CWJAP=\""+ssid+"\",\""+password+"\""); // set your home router SSID and password client.print ("AT+CIPSTART=\"TCP\",\"iot.electronixforu.com\",80\r\n"); // delay(4000); client.print ("AT+CIPMODE=1"); // set passthrough mode delay(1000); client.print ("AT+CIPSEND"); // send data without length delay(1000); }