Create a ESP32 Web Server using Arduino IDE


In this example, we will see how to create a simple web server using ESP32. We will see how to control LED wirelessly using a mobile or laptop.

ESP32 has 10 capacitive-sensing GPIOs, which detect variations induced by touching or approaching the GPIOs with a finger or other objects. The low-noise nature of the design and the high sensitivity of the circuit allows relatively small pads to be used.

control options on smart-phone screen

In station mode, the ESP32 creates its own Wi-Fi network. However, the ESP32 does not have an interface to the wired network.

In Access point mode, the ESP32 connects to the Wi-Fi network, and the IP address is assigned to ESP32 from the router.


#include 

// Network credentials
const char* ssid = "WiFi SSID"; // Set your network name
const char* password = "Wifi Password";       // Set your password (min 8 characters)

// Create a Web Server on port 80
WiFiServer server(80);

const int ledPin = 2;

void setup() {
  Serial.begin(115200);
  pinMode(ledPin, OUTPUT);
  
  // Configure ESP32 as an Access Point
  WiFi.softAP(ssid, password);
  Serial.println("Access Point Started");
  Serial.print("IP Address: ");
  Serial.println(WiFi.softAPIP());

  // Start the server
  server.begin();
}

void loop() {
  WiFiClient client = server.available(); // Check for incoming clients

  if (client) {
    Serial.println("New Client Connected!");
    String currentLine = "";

    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        if (c == '\n') {
          if (currentLine.length() == 0) {
            // Send HTML response
            client.println("HTTP/1.1 200 OK");
            client.println("Content-type:text/html");
            client.println();
            client.println("ESP32 AP");
            client.println("

Welcome to ESP32 Access Point!

"); client.println("

You are connected to ESP32.

"); client.println(""); client.println(); break; } else { currentLine = ""; } } else if (c != '\r') { currentLine += c; } } } client.stop(); Serial.println("Client Disconnected."); } }

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *