A comprehensive ESP32 project template with WiFi configuration, web server, OTA updates, HTTP client, and serial logging. Built with Arduino framework and PlatformIO for easy development and deployment.
- β WiFi Management: Auto-reconnect, configurable credentials via web interface
- β Web Server: Async web server with responsive HTML UI
- β OTA Updates: Over-the-air firmware updates for remote devices
- β HTTP Client: Send data to external APIs/servers
- β Serial Logging: Comprehensive logging with multiple log levels
- β SPIFFS: File system for storing configuration and web files
- β Clean Architecture: Well-organized code structure with separation of concerns
- β PlatformIO Support: Complete development environment setup
template-esp32-project/
βββ src/ # Source files
β βββ main.cpp # Main application entry point
β βββ wifi_manager.cpp # WiFi connection and management
β βββ web_server.cpp # Web server implementation
β βββ ota_manager.cpp # OTA update handling
β βββ http_client.cpp # HTTP client for API calls
β βββ logger.cpp # Serial logging implementation
βββ include/ # Header files
β βββ config.h # Configuration constants
β βββ wifi_manager.h # WiFi manager interface
β βββ web_server.h # Web server interface
β βββ ota_manager.h # OTA manager interface
β βββ http_client.h # HTTP client interface
β βββ logger.h # Logger interface
β βββ credentials.h.example # Example credentials file
βββ data/ # Web files (uploaded to SPIFFS)
β βββ index.html # Web configuration interface
βββ docs/ # Documentation
β βββ SETUP.md # Setup and installation guide
β βββ OTA_UPDATES.md # OTA update instructions
β βββ API.md # HTTP API documentation
βββ platformio.ini # PlatformIO configuration
βββ .gitignore # Git ignore file
βββ README.md # This file
- VS Code with PlatformIO IDE extension
- ESP32 development board
- USB cable
-
Clone the repository:
git clone https://github.com/pnstack/template-esp32-project.git cd template-esp32-project -
Open in VS Code:
code . -
Upload filesystem image (contains web interface):
pio run --target uploadfs
Or in VS Code: PlatformIO β Upload Filesystem Image
-
Build and upload firmware:
pio run --target upload
Or in VS Code: PlatformIO β Upload
-
Open serial monitor:
pio device monitor
Or in VS Code: PlatformIO β Monitor
- After uploading, the ESP32 will start and display its status in the serial monitor
- If no WiFi is configured, you can:
- Option A: Connect to ESP32's default IP (usually
192.168.4.1) if it creates an AP - Option B: Connect it to your network and find its IP in the serial monitor
- Option A: Connect to ESP32's default IP (usually
- Open a web browser and navigate to the ESP32's IP address
- Enter your WiFi credentials in the web interface
- Click "Save Configuration"
- The device will reconnect to your WiFi network
- Quick Start Guide: Get running in 5 minutes! β‘
- Setup Guide: Detailed installation and setup instructions
- Project Checklist: Track your setup progress
- Architecture: System design and component interactions
- Folder Structure: Project organization and file layout
- API Documentation: HTTP API endpoints and usage examples
- OTA Updates: Over-the-air firmware update guide
- Examples: Code examples for common use cases
- Contributing: How to contribute to this project
- Access the device at
http://<device-ip>/ - View current status (WiFi connection, IP address, uptime, etc.)
- Update WiFi credentials
- Monitor device status in real-time
#include "http_client.h"
HTTPClientManager httpClient;
void sendSensorData() {
float temperature = 25.5;
float humidity = 60.0;
const char* endpoint = "http://your-server.com/api/data";
bool success = httpClient.sendSensorData(endpoint, temperature, humidity);
if (success) {
Logger::info("Data sent successfully");
}
}# Configure upload port in platformio.ini
upload_protocol = espota
upload_port = 192.168.1.100
# Upload via OTA
pio run --target uploadcurl http://192.168.1.100/api/statusResponse:
{
"device_name": "ESP32-Device",
"uptime": 123456,
"wifi_connected": true,
"ssid": "MyWiFiNetwork",
"ip_address": "192.168.1.100",
"signal_strength": -45
}Edit include/config.h:
#define WIFI_RECONNECT_INTERVAL 5000 // ms between reconnect attempts
#define WIFI_MAX_RETRY 20 // max reconnection attempts#define WEBSERVER_PORT 80#define OTA_HOSTNAME "esp32-device"
#define OTA_PASSWORD "admin"#define SERIAL_BAUD_RATE 115200
// In your code:
Logger::setLogLevel(LOG_DEBUG); // LOG_ERROR, LOG_WARN, LOG_INFO, LOG_DEBUG# Build project
pio run
# Upload firmware via USB
pio run --target upload
# Upload filesystem (web files)
pio run --target uploadfs
# Open serial monitor
pio device monitor
# Clean build files
pio run --target clean
# Update libraries
pio lib update- Create new
.cppand.hfiles insrc/andinclude/ - Add your functionality following the existing code structure
- Use the Logger for debugging:
Logger::info("Your message") - Test thoroughly via serial monitor
- Edit
data/index.html - Upload filesystem:
pio run --target uploadfs - Refresh your browser
The following libraries are automatically installed by PlatformIO:
- ESP32 Arduino Framework: Core ESP32 support
- ESP AsyncWebServer: Asynchronous web server
- AsyncTCP: Async TCP library for ESP32
- ArduinoJson: JSON parsing and generation
# Linux: Add user to dialout group
sudo usermod -a -G dialout $USER
# Log out and log back in- Hold the BOOT button during upload
- Try a different USB cable
- Reduce upload speed in
platformio.ini
- Verify credentials are correct
- Ensure network is 2.4GHz (ESP32 doesn't support 5GHz)
- Check router settings (MAC filtering, etc.)
- View detailed logs in serial monitor
- Upload filesystem first:
pio run --target uploadfs - Verify
data/index.htmlexists - Check SPIFFS mount status in serial monitor
- Change default OTA password before deployment
- Never commit credentials to version control (use
credentials.h, which is in.gitignore) - Use strong WiFi passwords
- Consider adding API authentication for production
- Keep firmware updated to patch security vulnerabilities
This project is provided as a template. Feel free to use, modify, and distribute as needed.
Contributions are welcome! Please feel free to submit issues and pull requests.
For questions and support:
- Check the documentation
- Review serial monitor logs for errors
- Create an issue on GitHub
Built with:
Made with β€οΈ for the ESP32 community