Connecting ESP32 to WiFi in 4 Steps

As our dependence on the internet deepens, it seems that people have developed a reliance on WiFi. Regardless of where they are, they are constantly searching for available WiFi hotspots to stay connected online. While connecting to WiFi is a simple task for smartphones and tablets, configuring WiFi for your ESP32 to enable remote control or IoT development requires some time. Fortunately, the ESP32 offers a convenient solution to this problem: Web Hotspot Manual Provisioning. So let’s take a look at how to implement this operation!

Step 1: Preparation

Before getting started, make sure you have the following:

  • Arduino IDE installed with support for ESP32 development boards.
  • WebServer and WiFi libraries installed to enable serial communication between ESP32 and SNR9816TTS modules.

Step 2: Example Code

Here’s a simple example code demonstrating how to use ESP32 to create an AP hotspot and provide a network configuration page for entering WiFi information.

				
					#include <WiFi.h>
#include <WebServer.h>
const char *ssid = "ESP32-AP";
const char *password = "";  // Set to an empty string to indicate no password
WebServer server(2024);
void setup() {
  Serial.begin(115200);
  // Set ESP32 to AP mode
  WiFi.softAP(ssid, password);
  // Configure server handling functions
  server.on("/", HTTP_GET, handleRoot);
  server.on("/connect", HTTP_POST, handleConnect);
  // Start server
  server.begin();
  Serial.println("WiFi hotspot started");
}
void loop() {
  // Handle client requests
  server.handleClient();
}
void handleRoot() {
  // Return a simple HTML form for entering WiFi information
  server.send(200, "text/html", "<h1>ESP32 WiFi Provisioning</h1><p>Please enter your WiFi name and password</p><form action='/connect' method='post'><label for='ssid'>WiFi Name:</label><input type='text' id='ssid' name='ssid'><br><label for='password'>WiFi Password:</label><input type='password' id='password' name='password'><br><input type='submit' value='Connect'></form>");
}
void handleConnect() {
  // Handle connection request, attempt to connect to the specified WiFi network
  String ssid = server.arg("ssid");
  String password = server.arg("password");
  if (ssid != "" && password != "") {
    WiFi.begin(ssid.c_str(), password.c_str());
    int count = 0;
    while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.print(".");
      if (++count > 60) {
        Serial.println("WiFi connection failed");
        server.send(400, "text/html", "<h1>Connection failed</h1><p>Please check your WiFi information and try again.</p>");
        return;
      }
    }
    Serial.println("WiFi connected successfully");
    server.send(200, "text/html", "<h1>Connection successful</h1><p>Please disconnect from the network.</p>");
  } else {
    Serial.println("Incomplete WiFi information");
    server.send(400, "text/html", "<h1>Error</h1><p>Please enter WiFi name and password.</p>");
  }
}

				
			

Step 3: Upload Program

In the Arduino IDE, select the correct ESP32 development board model and port, then click the “Upload” button to burn the program into the ESP32.

Step 4: Perform Manual Provisioning

  1. Connect to the ESP32 hotspot: Open the WiFi settings on your smartphone or computer, find and connect to the hotspot named “ESP32-AP.”
  2. Access the provisioning page: Enter http://192.168.33.33:2024 in your browser to access the provisioning page provided by the ESP32.

Visit the network configuration page

  1. Enter WiFi information: On the page, enter the SSID and password for your home WiFi network, then click the “Connect” button.
  2. Confirm provisioning result: If provisioning is successful, the browser will display “Connection successful, please disconnect the network.” Then, disconnect from the ESP32 hotspot to allow the ESP32 to automatically connect to your home WiFi.

You Might Be Interested

A Step-by-Step Guide to Using LVGL with ESP32
A Step-by-Step Guide to Using LVGL with ESP32

This guide illustrates how to integrate LVGL with the ESP32, enabling the creation of engaging graphical user interfaces for embedded systems. By configuring libraries and writing code, developers can enhance user experiences on ESP32 devices with dynamic interfaces.

Using ESP32 with Arduino IDE to Control an LCD Display
Using ESP32 with Arduino IDE to Control an LCD Display

This article offers a comprehensive guide on utilizing ESP32 with Arduino IDE to control a 3.5-inch LCD display, navigating through development approaches, library installations, wiring configurations, and driver modifications.

esp32 based web server
Building ESP32 Web Server and Control LED in Arduino IDE

This project explores the creation of an ESP32-based web server that allows remote control of two LEDs via a web interface. Leveraging the ESP32’s Wi-Fi capabilities and web server functionality, users can toggle LEDs from any device with a web browser. It highlights the ESP32’s potential for IoT and home automation, showcasing its adaptability and convenience for controlling connected devices remotely. The project serves as a foundation for expanding web-enabled IoT applications.

How to Enable Multi-Core on ESP32 Microcontroller
How to Enable Multi-Core on ESP32 Microcontroller

This comprehensive guide elucidates the process of enabling multi-core functionality on the ESP32 microcontroller, leveraging its dual-core architecture for enhanced parallel processing capabilities. Through detailed steps and code examples, developers can effectively harness the power of both cores to optimize resource utilization and achieve versatile application scenarios.

ESP32 Sonar Servo Motor
ESP32 Sonar Servo Motor Object Detection Project

This project integrates sonar, servo motors, and the ESP32 microcontroller to create an object detection system with applications in robotics, security, and more. It uses sound waves for distance measurement and servo motors for precise control. Key code elements control the sonar sensor and servo motor. A Processing app enhances data visualization, making this project valuable for various applications.

esp32 connect to wifi
Connecting ESP32 to WiFi in 4 Steps

Unlock the potential of your ESP32 with these 4 simple steps to WiFi connectivity! Dive into the world of IoT and remote control effortlessly, as we guide you through setting up a Web Hotspot Manual Provisioning system. Say goodbye to complex configurations and hello to seamless connectivity.

arduino ble esp32
Creating Low-Power Bluetooth (BLE) with ESP32 Using Arduino IDE

In the world of IoT, the ESP32 microcontroller stands out as a versatile champion with its integrated Bluetooth Low Energy (BLE) technology. This article explores the technical intricacies and diverse applications of ESP32 BLE, shedding light on how it powers IoT solutions. From its efficient BLE integration to its robust community support, the ESP32 is a cost-effective and versatile choice for IoT development.

what is esp32
What is an ESP32

Dive into the world of microcontrollers with TechSparks’ comprehensive guide to the ESP32! Discover the power of this versatile chip, renowned for its integration, low power consumption, and robust security features, perfect for IoT enthusiasts and DIY projects. Explore its architecture, development boards, and key features, and unleash the full potential of your next project!

Scroll to Top