Sub topic 2
Network Basics an Arduino Wi-Fi Board Relies On
Assume you know basic Arduino sketches, can upload code, and understand that an IP address identifies a device. You should also know your network's SSID, router, and port terms. This chapter builds the working model behind a Wi-Fi connection so that later HTTP and MQTT sketches make sense.
The path from Arduino to a server
When a Wi-Fi Arduino sends data to an internet server, several systems cooperate:
The board first joins the local wireless network. The router then gives it network settings. After that, the board can find a server and open a connection to it.
IP addresses and DHCP
An IP address identifies a device on an IP network. A local address might look like 192.168.1.42. It is usually assigned by DHCP, which means Dynamic Host Configuration Protocol. DHCP automatically gives the board:
- An IP address for the board
- A subnet mask that defines its local network
- A default gateway, usually the router
- One or more DNS server addresses
The board needs a unique local IP address. If two devices use the same address, packets can go to the wrong device or fail altogether.
A subnet mask helps the board decide whether another address is local. For example, with the common mask 255.255.255.0, devices beginning with 192.168.1 are usually on the same local network. The board can send directly to them. For a remote address, it sends packets to the default gateway.
DNS, TCP, and ports
People use names such as example.com, but network packets need an IP address. DNS, or Domain Name System, translates a hostname into an IP address. A DNS failure can prevent a connection even when Wi-Fi is working.
TCP, or Transmission Control Protocol, creates a reliable connection between two endpoints. It numbers data, detects missing parts, and retransmits them. Arduino client classes such as WiFiClient commonly use TCP.
A port identifies a service on a device. The same server can provide several services at different ports:
| Service | Common port | Typical Arduino class |
|---|---|---|
| HTTP | 80 | `WiFiClient` |
| HTTPS | 443 | `WiFiSSLClient` |
| MQTT without TLS | 1883 | `WiFiClient` |
| MQTT with TLS | 8883 | A TLS-capable client |
A port is not a security boundary by itself. It is an address for a program that is listening for connections.
A request's route
Suppose the board connects to example.com on port 80.
- DNS resolves
example.comto a server IP address. - The board creates a TCP connection to that IP and port 80.
- The router forwards the packets beyond the local network.
- The server accepts the connection.
- The board sends an application message, such as an HTTP request.
- The server sends a response over the same TCP connection.
HTTP is an application protocol. TCP carries its bytes, but TCP does not understand HTTP headers, URLs, or status codes. This separation matters when troubleshooting. A successful TCP connection does not guarantee a valid HTTP request.
Common mistakes
- Wrong network band: Many Wi-Fi boards support 2.4 GHz networks but not 5 GHz networks.
- Confusing SSID and password: The SSID is the network name. The password authenticates the device.
- Using
localhost: On the Arduino,localhostmeans the Arduino itself, not your computer. - Using a private address from the internet: An address such as
192.168.1.20normally works only inside that local network. - Blocking captive portals: Hotel and public networks may require a web login that a simple Arduino sketch cannot complete.
- Assuming every port is open: Firewalls and routers may block incoming or outgoing traffic.
Exercise
The board has IP address 192.168.1.50 and can contact 192.168.1.1, but DNS lookups fail. Which network function should you investigate first?
Show answer
Investigate the configured DNS server or the router's DNS service. The local Wi-Fi link and gateway are working, but hostname resolution is not.