WiFi Basics - Connecting ESP32 to the Internet
Up to now your ESP32 has blinked LEDs and read sensors, but it lived on a little island - it could only talk to things wired directly to it. In this lesson we give it a superpower that almost no other beginner board has built in: WiFi. By the end you will connect your ESP32 to your home network and fetch real live data from the internet, all in a few lines of code.
What You Will Learn
- Why built-in WiFi makes the ESP32 special compared to other beginner boards.
- The two ways an ESP32 can use WiFi: Station mode and Access-Point mode.
- How to scan for nearby WiFi networks with
WiFi.scanNetworks(). - How to connect with
WiFi.begin(ssid, password), wait for the connection, and print your IP address. - What an IP address and a local network actually are, in plain everyday words.
- How to automatically reconnect when the WiFi drops.
- How to make your first real internet request (an HTTP GET) with
HTTPClientand read the reply. - Security basics and the most common beginner problems, and exactly how to fix them.
The Big Idea: Why WiFi Makes the ESP32 Special
Most beginner microcontroller boards, like the classic Arduino Uno, have no way to talk to the internet on their own. To get an Arduino Uno online you must buy an extra "shield" or module, wire it up, and install extra libraries. It is expensive and fiddly.
The ESP32 is different. Radio hardware for WiFi is baked right into the chip. That means the moment you power up an ESP32, it can already join a WiFi network and reach any server on the planet - no extra parts needed. This is exactly what turns a hobby project into an Internet of Things (IoT) device: a weather station that posts readings to a website, a plant monitor that texts you when the soil is dry, or a lamp you switch on from your phone.
One important limit to remember from the very start: the ESP32's WiFi radio only works on the 2.4 GHz band. Modern home routers often broadcast two networks, one at 2.4 GHz and one at 5 GHz. The ESP32 simply cannot see or join the 5 GHz one. We will come back to why this trips up so many beginners.