Capsicum

🫑 A retrofitted wired audio doorbell with added WiFi connectivity 🔔

power 16340
wireless WiFi
mcu ESP32-C3
ongoing since Oct 2023

Access point

esp32c3 access point medium

Connect to the access point and view the hello world


Details

  1. Upload the firmware with make
  2. Remove the USB-C cable used for firmware upload
  3. Turn on the power switch to ensure battery is used
  4. Connect to WiFi access point batt with password 12345678

  5. Browser to http://192.168.4.1 on the browser
  6. View hello world

Serial console

Serial output from the firmware.

Code

Download code
// This code sets up an ESP32-C3 as an access point (AP) with a specified SSID and password.
// It creates a server that listens for incoming client connections on port 80.
// When a client connects, it sends a "Hello World!" message as the response.
// The code also includes a LED that turns on when a client is connected and turns off when the client disconnects.

// This code is based on the WiFiAccessPoint example from the Arduino ESP32 library:
// https://raw.githubusercontent.com/espressif/arduino-esp32/990e3d5b431b63b4adc364b045a79afdad645a3f/libraries/WiFi/examples/WiFiAccessPoint/WiFiAccessPoint.ino

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

#define LED 3

const char *ssid = "batt";
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

# Description: Makefile for the demo code
# Usage: make [lint] [compile] [upload] [clean]
BOARD := esp32:esp32:esp32c3:CDCOnBoot=cdc
PORT ?= /dev/cu.usbmodem1410*
BUILD = build

.PHONY: default lint compile upload clean

default: lint compile upload clean

lint:
	cpplint --extensions=ino --filter=-legal/copyright,-runtime/int,-readability/todo,-whitespace/line_length *.ino

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

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

clean:
	rm -rf build

References