#include SoftwareSerial ESP8266( 11, 10 ); // RX, TX #define SSID "FFF" #define PASS "KKKKKKK" #define IP "db.vexp.idv.tw" #define PORT "80" String GET = "GET /~tjm/esp8266/s.php?pwd="; String id="T0981"; long D=10000;//delay 10 sec String cmd; double T=23.3,H=67; void setup() { Serial.begin( 115200 ); ESP8266.begin( 115200 ); delay(2000); sendDebug("AT+RST"); while (!ESP8266.find("OK")) delay(200); Serial.println("Data ready to sent!"); connectWiFi(); } unsigned long lastTimeMillis = 0; void noprintResponse() { while (ESP8266.available()) { ESP8266.readStringUntil('\n'); } } void sendDebug(String wi) { Serial.print("SEND: "); Serial.println(wi); ESP8266.println(wi); } void loop() { if (millis() - lastTimeMillis > D) { lastTimeMillis = millis(); ESP8266.println("AT+CIPMUX=1"); delay(1000); noprintResponse(); cmd="AT+CIPSTART=4,\"TCP\",\""; cmd +=IP; cmd +="\","; cmd +=PORT; ESP8266.println(cmd); delay(1000); noprintResponse(); cmd = GET; cmd += "&tmp="; cmd += T; cmd += "&id="; cmd += id ; cmd += "\r\n"; ESP8266.println("AT+CIPSEND=4," + String(cmd.length() + 4)); delay(1000); ESP8266.println(cmd); delay(1000); ESP8266.println(""); } while (ESP8266.available()) { Serial.println(ESP8266.readStringUntil('\n')); } } boolean connectWiFi() { ESP8266.println("AT+CWMODE=1"); delay(2000); String cmd="AT+CWJAP=\""; cmd+=SSID; cmd+="\",\""; cmd+=PASS; cmd+="\""; sendDebug(cmd); int cnt=0; while (!ESP8266.find("OK") && !ESP8266.find("No") && cnt<20 ) { delay(200); cnt++; } if (cnt<20) Serial.println( "Connect OK" ); else Serial.println( "Time Out" ); return true; }