/* * Simple HTTP get webclient test */ #include #include const char* ssid = "Your_Network_name"; const char* password = "Your_Network_Password"; const char* host = "www.your_domain_here.com"; String line; String trimmed; String red,blue; int count=0; void setup() { pinMode(14,OUTPUT); pinMode(16,OUTPUT); Serial.begin(115200); delay(100); // We start by connecting to a WiFi network Serial.println(); Serial.println(); Serial.print("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected"); Serial.println("IP address: "); Serial.println(WiFi.localIP()); } void loop() { delay(200); Serial.print("connecting to "); Serial.println(host); // Use WiFiClient class to create TCP connections WiFiClient client; const int httpPort = 80; if (!client.connect(host, httpPort)) { Serial.println("connection failed"); return; } // We now create a URI for the request String url = "/value.txt"; //writing to the webpage using form_data and php GET String message="lasttest"; String modify = "/index.htm?form_data=" + message + "&Submit=Submit"; Serial.print("Requesting URL: "); Serial.println(url); // This will send the request to the server client.print(String("GET ") + url + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Connection: close\r\n\r\n"); delay(500); // Read all the lines of the reply from server and print them to Serial while(client.available()){ line = client.readStringUntil('\r'); Serial.print(line); } Serial.println(); Serial.println("closing connection\n\n"); //line.trim(); //need to trim the whitespaces //---------Detect whether the text value is On or Off if (line.substring(1,3) == "On"){ Serial.print("\n\n Control Relay Turned on"); digitalWrite(16,HIGH); digitalWrite(14,LOW); } if (line.substring(1,4) =="Off"){ Serial.print("\n\n Control Relay Turned off"); digitalWrite(14,HIGH); digitalWrite(16,LOW); } Serial.print("length is: "); Serial.print(line.length()); Serial.print("\n"); Serial.print(line); }