Espressif ESP8266 User Manual page 27

Hide thumbs Also See for ESP8266:
Table of Contents

Advertisement

30
31
Serial.print("connecting to ");
32
Serial.println(host);
33
34
// Use WiFiClient class to create TCP connections
35
WiFiClient client;
36
const int httpPort = 80;
37
if (!client.connect(host, httpPort)) {
38
Serial.println("connection failed");
39
return;
40
}
41
42
// We now create a URI for the request
43
String url = "/guide/";
44
45
Serial.print("Requesting URL: ");
46
Serial.println(url);
47
48
// This will send the request to the server
49
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
50
"Host: " + host + "\r\n" +
51
"Connection: close\r\n\r\n");
52
53
unsigned long timeout = millis();
54
while (client.available() == 0) {
55
if (millis() - timeout > 5000) {
56
Serial.println(">>> Client Timeout !");
57
client.stop();
58
return;
59
}
60
}
61
62
// Read all the lines of the reply from server and print them to Serial
63
while(client.available()){

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the ESP8266 and is the answer not in the manual?

Table of Contents

Save PDF