Access Point with Arduino on ESP32-C3

Updated on 21 June 2024
dev board ESP32-C3-DevKitM-1
chip ESP32-C3-MINI-1-N4
features access point wifi webpage esp32c3

Before starting

Dependancies

Ensure the following dependancies are downloaded and available:

Pre-requisites

Try these simpler or similar examples:

Buy the components

Code

Download code access-point-arduino-esp32c3.ino
// https://raw.githubusercontent.com/espressif/arduino-esp32/990e3d5b431b63b4adc364b045a79afdad645a3f/libraries/WiFi/examples/WiFiAccessPoint/WiFiAccessPoint.ino

// The code below is an example of how to create an access point using the ESP32-C3. The code creates an access point with the SSID "hello" and password "12345678". The code then starts a server on port 80. When a client connects to the server, the server sends the message "Hello World!" to the client.

#include <WiFi.h>
#include <WiFiClient.h>
#include <WiFiAP.h>

#define LED 3

const char *ssid = "hello";
const char *password = "12345678";
WiFiServer server(80);

void setup() {
  Serial.begin(115200);
  Serial.println();
  Serial.println("Configuring access point...");

  pinMode(LED, OUTPUT);

  if (!WiFi.softAP(ssid, password)) {
    Serial.println("Soft AP creation failed.");
    while (1) {}
  }
  IPAddress myIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(myIP);
  server.begin();

  Serial.println("Server started");
}

void handleClient(WiFiClient client) {
  Serial.println("New Client.");
  String currentLine = "";
  while (client.connected()) {
    if (client.available()) {
      digitalWrite(LED, HIGH);

      client.println("HTTP/1.1 200 OK");
      client.println("Content-type:text/html");
      client.println();

      client.print("Hello World!");

      client.println();
      break;
    }
  }
  client.stop();
  Serial.println("Client Disconnected.");
  digitalWrite(LED, LOW);
}

void loop() {
  WiFiClient client = server.accept();

  if (client) {
    handleClient(client);
  }
}

Makefile

BOARD?=esp32:esp32:esp32c3
PORT?=/dev/cu.SLAB_USBtoUART*
BUILD=build

.PHONY: default lint all flash clean

default: lint all flash clean

lint:
	cpplint --extensions=ino --filter=-legal/copyright *.ino

all:
	arduino-cli compile --fqbn $(BOARD) --output-dir $(BUILD) ./

flash:
	arduino-cli upload --fqbn $(BOARD) --port $(PORT) --input-dir $(BUILD)

clean:
	rm -r build

Prototype

A photo of the actual setup.

Access Point with Arduino on ESP32-C3 prototype

Serial console

Serial output from the firmware.

Access Point with Arduino on ESP32-C3 serial console

Description

The code below is an example of how to create an access point using the ESP32-C3. The code creates an access point with the SSID hello and password 12345678. The code then starts a server on port 80. When a client connects to the server, the server sends the message “Hello World!” to the client.

  1. Plug in to the computer with USB cable
  2. Upload the firmware with make or Arduino IDE
  3. Unplug and then plug in the dev board to a seperate USB cable power
  4. Connect to WiFi access point hello with password 12345678
  5. Browser to http://192.168.4.1 on the browser
  6. View hello world on the webpage

References