01 Overview
Runs an HTTP server on an ESP32 that is already connected to Wi-Fi. The device's IP address can be opened in a browser to access a configuration page. Suitable for LAN-based device debugging, parameter changes, and status monitoring.
Use when: engineer debug, local switch control, provisioning portal (SoftAP mode), production line batch configuration.
Skip when: public internet exposure without authentication and TLS, high concurrency, or HTTPS requirement.
Essence: This is a lightweight embedded web server based on the esp_http_server component, consuming minimal resources, ideal for resource-constrained MCUs.
Difference from cloud: It does not rely on external servers; all logic is local, providing fast response but not accessible from the internet without port forwarding or tunneling.
03 Software flow
1. Initialize Wi-Fi: Connect to a router (Station) or create an access point (SoftAP), and wait for an IP address.
2. Start HTTP server: Call esp_http_server_start() to create a server instance, configuring the port (default 80) and maximum number of connections.
3. Register URI handlers: Use httpd_register_uri_handler() to register callbacks for HTTP methods (GET/POST), e.g., root path '/' returns an HTML page.
4. Handle requests: In the callback, parse URL parameters or request body, perform actions (e.g., read/modify parameters), and return an HTTP response (text, JSON, or redirect).
5. Persist parameters: Write modified parameters to NVS (non-volatile storage) to ensure they survive a reboot.
6. Error handling: Check for server start failures, memory exhaustion, etc., and retry or log errors appropriately.
7. Security enhancements (for production): Add basic authentication, CSRF protection, input validation, etc., to avoid vulnerabilities.