Espressif ESP8266 User Manual page 28

Hide thumbs Also See for ESP8266:
Table of Contents

Advertisement

64
String line = client.readStringUntil('\r');
65
Serial.print(line);
66
}
67
68
}
How does this work? First we define the SSID and password of the WiFi access point we want
to connect to. Please note that there are better ways to do that. The WiFiManager
(https://github.com/tzapu/WiFiManager)
it cannot connect to any SSID. You then use your smartphone to configure the WiFi credentials
and there is no need to hard code these into your firmware. But for the sake of simplicity let's
ignore this here.
On line 14 we start connecting to the defined access point and wait until the connection is
established. After all there is no point to send requests to a server if the network connection
is not confirmed yet.
Line 49 sends the request to the server. The command
strange to you. This is how your browser talks to the web server.
webserver,
/guide/
is the resource on the server we want to get and
that we are using. If you are interested how this works in detail have a look at this Wikipedia
article:
https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol.
On line 63 we print out the response line by line as long as there is text coming in. Sadly this
is quite complicated. Especially if we want to add encryption in the form of SSL to the
connection. This protects your data and makes sure that you are talking to the right server.
With the following command we can verify that the host matches the given SHA1 fingerprint.
1
if (client.verify(fingerprint, host)) {
2
Serial.println("certificate matches");
3
} else {
4
Serial.println("certificate doesn't match");
5
return;
6
}
How can you find this fingerprint? Your browser can help you with this. I will show it with
Chrome. First open the page you need the fingerprint for, in my case www.google.ch. Then
click on the little lock symbol and then on Details:
for instance starts the ESP8266 as an access point if
GET /guide/ HTTP/1.1\r\n
might look
GET
is the command for the
HTTP/1.1
is the protocol

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?

Questions and answers

Subscribe to Our Youtube Channel

Table of Contents

Save PDF