Espressif Systems ESP8266 Beginner's Manual page 10

Hide thumbs Also See for ESP8266:
Table of Contents

Advertisement

Wi-Fi
Using the ESP8266 as a simple microcontroller is great, but the reason why most people use it, is its Wi-Fi capabilities. In this chapter,
we'll dive into the wonderful world of network protocols, like Wi-Fi, TCP, UDP, HTTP, DNS ... All these acronyms might intimidate you,
but I'll try my best to explain them step-by-step and in an easy way.
Some paragraphs are in italic. These provide some extra information, but are not critical to understanding the ESP's Wi-Fi functions, so
don't get frustrated if there are things you don't understand.
It's really hard to give a clear explanation, without over-complicating things and while keeping it short enough as well. If you've got
any feedback or remarks, be sure to leave a comment to help improve this article. Thanks!
The TCP/IP stack
The system most people refer to as 'The Internet' isn't just one protocol: it's an entire stack of layers of protocols, often referred to as
the TCP/IP stack. We'll go over these different layers, because we need to understand how our ESP8266 communicates with other
devices on the network.
Layer
Protocols
Application
HTTP, FTP, mDNS, WebSocket, OSC ...
Transport
TCP, UDP
Internet
IP
Link
Ethernet, Wi-Fi ...
The Link layer
The link layer contains the physical link between two devices, an Ethernet cable, for example, or a Wi-Fi connection. This is the layer
that is closest to the hardware.
To connect an ESP8266 to the network, you have to create a Wi-Fi link. This can happen in two different ways:
1. The ESP8266 connects to a wireless access point (WAP or simply AP). The AP can be built-in to your modem or router, for
example.
In this configuration, the ESP acts like a wireless station.
2. The ESP8266 acts as an access point and wireless stations can connect to it. These stations could be your laptop, a
smartphone, or even another ESP in station mode.
Once the Wi-Fi link is established, the ESP8266 is part of a local area network (LAN). All devices on a LAN can communicate with
each other.
Most of the time, the AP is connected to a physical Ethernet network as well, this means that the ESP8266 can also communicate with
devices that are connected to the AP (modem/router) via a wired Ethernet connection (desktop computers, gaming consoles and set-
top boxes, for instance).
If the ESP8266 is in access point mode, it can communicate with any station that is connected to it, and two stations (e.g. a laptop and
a smartphone) can also communicate with each other.
The ESP can be used in AP-only, station-only, or AP+station mode.
TL;DR
The link layer is the physical link between devices: in the case of the ESP8266, this is a WiFi connection. The ESP can act as a station
and connect to an access point, or act as an access point and let other devices connect to it.
The Internet or Network layer
Although the devices are now physically connected (either through actual wires (Ethernet) or through radio waves (Wi-Fi)), they can't
actually talk to each other yet, because they have no way of knowing where to send the message to.
That's where the Internet Protocol (IP) comes in. Every device on the network has a personal IP address. The DHCP server (Dynamic
Host Configuration Protocol Server) makes sure that these addresses are unique.
This means that you can now send a message to a specific address.
There are two versions of the Internet Protocol: IPv4 and IPv6. IPv6 is an improved version of IPv4 and has much more addresses than
IPv4 (because there are much more devices than available IPv4 addresses). In this article, we'll only talk about IPv4 addresses, since
most LANs still use them.
The IP address consists of 4 numbers, for example 192.168.1.5 is a valid IPv4 address. It actually consists of two parts: the first part is
192.168.1, this is the address of the local network. The last digit, 5 in this case, is specific to the device.
By using IP addresses, we can find the ESP8266 on the network, and send messages to it. The ESP can also find our computer or our
phone, if it knows their respective IP addresses.
Sub-net mask (optional)
This subdivision of the IP address is determined by the sub-net mask, often written as 255.255.255.0. You can see that it consists of
four numbers, just like the IP address. If a part of the sub-net mask is 255, it means that the corresponding part of the IP address is
part of the network address, if it's 0, the corresponding IP part is part of the address of the specific address. A different notation to "IP:
192.168.1.5, sub-net mask: 255.255.255.0" would be "192.168.1.5/24", because the binary representation of the sub-net mask is
11111111.11111111.11111111.00000000, and it has 24 ones.
If you want to know more about sub-nets, I'd recommend you to read the Wikipedia article.
(A quick tip to help you remember: it's called the sub-net mask, because if you perform a bitwise AND operation on the IP address and
the sub-net mask (i.e. use the sub-net mask as a mask for the IP address), you get the address of the sub-net.)

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