Source: https://mokxi.com/libraries/esp-wifi
Updated: 2026-11-02

Libraries / Network
Arduino library · Network

# ESP32 WiFi, HTTPClient and WebServer: the core libraries for networking

These three come with the ESP32 Arduino core, so there is nothing to install. WiFi.h joins a network in station mode and reports the address it got; HTTPClient.h makes HTTP requests and hands back the status code and body; WebServer.h listens on port 80 and calls your function for each path a browser asks for.

Open the example in the editor See the calls

Built in on Mokxi: #include <WiFi.h> and it builds, with nothing to install. Free, and no account needed.

## What WiFi, HTTPClient and WebServer (ESP32 core) does

Joining is asynchronous. WiFi.begin() starts the connection and returns at once, so a sketch waits in a loop until WiFi.status() reports WL_CONNECTED, usually printing dots, and only then makes a request or starts the server. WiFi.localIP() is the address to type into a browser.

A web server sketch has one rule for loop(): call server.handleClient() on every pass. Each handler you registered with server.on() runs from inside that call, reads arguments with server.arg() and answers with server.send(). The ESP8266 core has the same calls under ESP8266WiFi.h, ESP8266HTTPClient.h and ESP8266WebServer.h.

Library Manager name | WiFi, HTTPClient and WebServer (ESP32 core)

Author | Espressif

Include | #include <WiFi.h>
#include <HTTPClient.h>
#include <WebServer.h>
#include <WiFiClient.h>

Boards | ESP32-C3, ESP32-C6, Seeed XIAO ESP32-C3, ESP32-C3 SuperMini, Seeed XIAO ESP32-C6, ESP32 DevKit, ESP32-DevKitC V4, LOLIN32 Lite, Wemos D1 R32, Cheap Yellow Display, TTGO T-Display, ESP32-S3-DevKitC-1, Seeed XIAO ESP32-S3, Arduino Nano ESP32, ESP8266 NodeMCU, Raspberry Pi Pico W, Arduino Uno R4 WiFi

In the simulator | Runs, with a gap the note below names.

## Install it

It builds on ESP32-C3, ESP32-C6, Seeed XIAO ESP32-C3, ESP32-C3 SuperMini, Seeed XIAO ESP32-C6, ESP32 DevKit, ESP32-DevKitC V4, LOLIN32 Lite, Wemos D1 R32, Cheap Yellow Display, TTGO T-Display, ESP32-S3-DevKitC-1, Seeed XIAO ESP32-S3, Arduino Nano ESP32, ESP8266 NodeMCU, Raspberry Pi Pico W, Arduino Uno R4 WiFi.

In Mokxi it is built in: #include <WiFi.h> and the sketch compiles, with no download, no zip and no Library Manager.

On a real board it comes with the board package (Espressif), so the Arduino IDE has it as soon as the board is installed: there is nothing to add from the Library Manager.

ESP32-C3 · ESP32-C6 · Seeed XIAO ESP32-C3 · ESP32-C3 SuperMini · Seeed XIAO ESP32-C6 · ESP32 DevKit · ESP32-DevKitC V4 · LOLIN32 Lite · Wemos D1 R32 · Cheap Yellow Display · TTGO T-Display · ESP32-S3-DevKitC-1 · Seeed XIAO ESP32-S3 · Arduino Nano ESP32 · ESP8266 NodeMCU · Raspberry Pi Pico W · Arduino Uno R4 WiFi

## The calls you will use

In the order a sketch meets them.

### WiFi.begin("Mokxi-Lab", "breadboard")

Starts joining a network with its name and password. It returns before the board is connected.

### WiFi.status()

WL_CONNECTED once joined; WL_DISCONNECTED, WL_NO_SSID_AVAIL or WL_CONNECT_FAILED tell you what is wrong while it is not.

### WiFi.localIP()

The board’s IP address on the network, printable with Serial.println().

### http.begin(client, "http://weather.mokxi/")

Sets up a request to a URL through a WiFiClient. Nothing is sent until GET() or POST().

### http.GET()

Sends the request and returns the HTTP status (200 for OK), or a negative error code when the request did not get an answer.

### http.getString()

The response body as a String. Call http.end() afterward to free the connection.

### server.on("/", handleRoot)

Registers the function that answers a path. Lambdas work too: server.on("/on", [](){ ... });

### server.send(200, "text/html", page)

Answers the current request with a status, a content type and a body.

### server.arg("state")

The value of a query or form argument, such as ?state=on, as a String. server.hasArg() checks it is there.

### server.handleClient()

Accepts a waiting request and runs its handler. Call it on every pass of loop().

## Example: WiFi: a lamp on a web page

On the ESP32-C3-DevKitM-1. It runs in the browser exactly as printed.

sketch.ino · ESP32-C3-DevKitM-1

Open it in the editor, wired and ready to run · WiFi: a lamp on a web page: the project page

## Common errors and how to fix them

### The dots never stop: stuck waiting for WL_CONNECTED

Wrong network name or password (both are case sensitive), a 5 GHz-only network the ESP32 cannot see, or a router that is out of range. Print WiFi.status() in the loop to see which; WL_NO_SSID_AVAIL means the name was not found.

### http.GET() returns -1 (connection refused)

The host did not answer: a wrong address, no internet, or https:// given to a plain client. In Mokxi, only names under .mokxi answer unless real internet mode is switched on, and errorToString() says so.

### The web page never loads from the board’s address

Either server.begin() was not called after server.on(), or loop() does not call server.handleClient(), or it is blocked by a delay(). Keep loop() short so each request is answered at once.

### 'WiFi' was not declared in this scope on an Arduino Uno

The Uno has no WiFi. WiFi.h here is the ESP32 core’s; use an ESP32, ESP8266, Pico W or Uno R4 WiFi board, each of which has its own WiFi header.

## Projects that use WiFi, HTTPClient and WebServer (ESP32 core)

Built-in projects that include it. Each page has the full sketch and opens in the editor, already wired.

WiFi: join the network The connect loop every ESP32 tutorial opens with, on a simulated network: no 802.11, and the address a simulated DHCP hands out. ESP32 web server with two LEDs The Random Nerd Tutorials ESP32 web server: press Run, open the Web panel, and its ON and OFF buttons switch the LEDs on GPIO 26 and 27. Plant sensor for Home Assistant A capacitive soil sensor mapped between two calibration readings, a light level, and a thirsty LED with two thresholds so it does not flicker, on an ESP32-C3. Radar hallway sensor An RCWL-0516 radar holds a hallway "occupied" for ten seconds after the last movement and lights the lamp only when it is dark, with the honest limits of a Doppler sensor. ESP-NOW button and LED Two ESP32s and no wire between them: the button on one sends on or off over ESP-NOW, the other lights its LED and prints each message, and the sender hears the ACK. Garage door opener A relay that presses the opener’s wall button for half a second and two reed switches that say closed, opening, open, closing or stopped, from a button or the Web tab.

## Keep going

### Learn

- Connect a Board to WiFi and Serve a Page
- ESP32 HTTP GET Request: Fetch the Weather as JSON
- ESP32 Not Connecting to WiFi: Causes and Fixes

### More network libraries

- PubSubClient
- MQTT
- Blynk
- ThingSpeak
- WiFiManager

Every built-in library · Open the editor

## Try WiFi, HTTPClient and WebServer (ESP32 core) without installing anything

Open the example, change the sketch, and keep your version in a free account.

Start building free

Open the editor
