Capsicum

🫑 Retrofit a wired doorbell to add WiFi and make it connected 🔔

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
  4. Connect to access point batt with password 12345678
  5. Browser to http://192.168.4.1 on the browser
  6. View hello world

Code

Download code
// 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);
  pinMode(BATTERY_ENABLE_PIN, HIGH);

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

  Serial.println("Server started");
  Serial.print("Battery Analog level: ");
  Serial.println(measureBatteryVoltage());
}

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

  if (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);
  }
}

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 *.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