Welcome to YaranaIoT Guru’s advanced ESP32 tutorial! In this project, we’ll teach you how to change Wi-Fi credentials on ESP32 without re-uploading code.
Many IoT projects require Wi-Fi credentials to be updated frequently. Traditionally, you need to modify the code and re-upload it, which is inconvenient for deployed devices. In this guide, we’ll implement a web dashboard and captive portal setup, allowing users to:
- Change Wi-Fi SSID & password directly from a browser
- Avoid knowing the ESP32 IP address
- Automatically connect to the new network
This method is perfect for home automation, IoT devices, and portable ESP32 projects.
🔹 Why This Approach is Useful
- Eliminates the need to reprogram devices every time Wi-Fi changes
- Supports dynamic networks in homes, offices, and labs
- Provides a professional user interface for Wi-Fi configuration
- Works with multiple IoT devices in distributed setups
🔹 Project Goals
- Configure ESP32 as Access Point (AP) if it cannot connect to Wi-Fi
- Host a captive portal web page for Wi-Fi credentials
- Store credentials in non-volatile memory (EEPROM / Preferences)
- Connect to the new Wi-Fi automatically
- Provide optional dashboard for multiple device control
🔹 Applications
- IoT devices that need frequent Wi-Fi updates
- Home automation appliances with dynamic network environments
- Smart sensors, smart plugs, or security devices
- Classroom or office IoT deployments
🔹 Required Components
| Component | Quantity | Description |
|---|---|---|
| ESP32 Dev Board | 1 | Microcontroller with Wi-Fi |
| USB Cable | 1 | Power and programming |
| Breadboard & Jumper Wires | Optional | For LEDs or relays if included |
| PC or Mobile Device | 1 | Access portal via browser |
| Arduino IDE | 1 | Development environment |
🔹 Step 1: Circuit Overview
This project is primarily software-driven. Optional LEDs or relays can be connected for demonstration:
- LED → GPIO2
- Relay → GPIO5
- Connect 220Ω resistor with LED to GND
The focus is on Wi-Fi configuration, so hardware requirements are minimal.
🔹 How This Works (High-Level)
- ESP32 starts and attempts to connect to saved Wi-Fi credentials
- If unsuccessful, it starts an Access Point (AP)
- User connects to the AP via phone or PC → automatic captive portal opens
- User enters new Wi-Fi credentials → ESP32 saves them in non-volatile memory
- ESP32 connects to the new network without needing IP or code re-upload
🔹 Step 1: Required Libraries
To implement this project, you need the following Arduino libraries:
- WiFi.h → for Wi-Fi connectivity
- ESPAsyncWebServer.h → to host the web server
- AsyncTCP.h → dependency for ESPAsyncWebServer
- Preferences.h → for storing Wi-Fi credentials in non-volatile memory
Installation:
- Go to Sketch → Include Library → Manage Libraries
- Search for ESPAsyncWebServer and install
- Search for AsyncTCP and install
🔹 Step 2: Setup Preferences Storage
ESP32’s Preferences library allows storing Wi-Fi credentials permanently:
#include <Preferences.h>
Preferences preferences;
void setup() {
preferences.begin("wifiCreds", false); // Namespace
String ssid = preferences.getString("ssid", "");
String password = preferences.getString("pass", "");
}
- If credentials exist → ESP32 tries to connect
- If not → ESP32 starts Access Point mode
🔹 Step 3: Configuring the Captive Portal
Core logic:
- Start AP mode if Wi-Fi connection fails
- ESP32 hosts a web page for SSID and password
- User submits credentials → ESP32 saves in Preferences and restarts
Code Example:
#include <WiFi.h>
#include <ESPAsyncWebServer.h>
#include <Preferences.h>
Preferences preferences;
AsyncWebServer server(80);
String ssid = "";
String password = "";
void setup() {
Serial.begin(115200);
preferences.begin("wifiCreds", false);
ssid = preferences.getString("ssid", "");
password = preferences.getString("pass", "");
WiFi.mode(WIFI_STA);
if (ssid != "" && password != "" && WiFi.begin(ssid.c_str(), password.c_str()) == WL_CONNECTED) {
Serial.println("Connected to saved WiFi!");
} else {
startAPMode();
}
}
void startAPMode() {
WiFi.mode(WIFI_AP);
WiFi.softAP("ESP32_Config_Portal");
Serial.println("Access Point Started: ESP32_Config_Portal");
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
request->send(200, "text/html",
"<form action=\"/save\" method=\"POST\">"
"SSID:<input type='text' name='ssid'><br>"
"Password:<input type='password' name='pass'><br>"
"<input type='submit' value='Save'>"
"</form>");
});
server.on("/save", HTTP_POST, [](AsyncWebServerRequest *request){
ssid = request->getParam("ssid", true)->value();
password = request->getParam("pass", true)->value();
preferences.putString("ssid", ssid);
preferences.putString("pass", password);
request->send(200, "text/html", "<h2>WiFi Saved! Restarting...</h2>");
delay(2000);
ESP.restart();
});
server.begin();
}
✅ Now, when the ESP32 cannot connect to saved Wi-Fi:
- It creates ESP32_Config_Portal AP
- User connects → captive portal opens automatically
- Enter new credentials → ESP32 saves and connects
🔹 Step 4: Testing the Captive Portal
- Upload the code to ESP32
- Disconnect ESP32 from Wi-Fi or use new credentials
- Check available Wi-Fi networks → connect to ESP32_Config_Portal
- Browser automatically opens → enter SSID & password
- ESP32 stores them and connects to the new network
🔹 Step 5: Optional Enhancements
- Add LED indicator: blink while in AP mode
- Add multiple device support with unique AP names
- Validate SSID & password input for better UX
🔹 1. Dynamic Web Dashboard
Instead of a simple HTML form, we can create a full-featured dashboard:
- Displays current Wi-Fi status
- Allows changing SSID and password
- Shows LED status or sensor readings (optional)
HTML Example for ESP32 Web Server:
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
String html = "<html><head><title>ESP32 WiFi Manager</title></head><body>";
html += "<h1>ESP32 WiFi Configuration</h1>";
html += "<p>Current SSID: " + WiFi.SSID() + "</p>";
html += "<form action='/save' method='POST'>";
html += "SSID:<input type='text' name='ssid'><br>";
html += "Password:<input type='password' name='pass'><br>";
html += "<input type='submit' value='Save'>";
html += "</form></body></html>";
request->send(200, "text/html", html);
});
✅ Users now see current Wi-Fi SSID and can update credentials seamlessly.
🔹 2. Managing Multiple Devices
If you have multiple ESP32 devices, each can:
- Start its own AP with unique name, e.g.,
ESP32_Device1,ESP32_Device2 - Host the same dashboard interface for credentials
- Users can connect and configure each device individually
Code for Unique AP Names:
String apName = "ESP32_Device_" + String((uint32_t)ESP.getEfuseMac(), HEX);
WiFi.softAP(apName.c_str());
Serial.println("AP Started: " + apName);
🔹 3. Switching Wi-Fi Without IP
Traditional web servers require knowing ESP32’s IP. With captive portal, it’s automatic:
- Device broadcasts AP if it cannot connect to Wi-Fi
- User connects → browser automatically opens the portal
- No need to enter IP addresses
- Credentials are saved → ESP32 reconnects automatically
This is ideal for IoT devices deployed in remote locations.
🔹 4. Adding Optional Features
- LED / Relay Control on Dashboard
- Extend dashboard to toggle GPIO pins:
<p><a href='/LED1=ON'><button>LED ON</button></a> <a href='/LED1=OFF'><button>LED OFF</button></a></p> - ESP32 updates device status in real-time
- Extend dashboard to toggle GPIO pins:
- Sensor Readings
- Add temperature, humidity, or motion sensor data to the dashboard
- Users can monitor environment and update settings in real-time
- Network Diagnostics
- Display signal strength (RSSI)
- Show connection status, uptime, and last updated time
🔹 5. Testing & Troubleshooting
- Disconnect ESP32 from your Wi-Fi to trigger AP mode
- Connect multiple devices and ensure unique AP names
- Test dashboard on mobile and desktop browsers
- Verify saved credentials are applied after ESP32 restarts
🔹 1. Cloud Integration
Integrating your ESP32 with a cloud platform like Firebase, Blynk, or Ubidots allows:
- Remote monitoring of connected Wi-Fi networks
- Ability to push updates or change configurations remotely
- Collect device logs for maintenance and analytics
Example: Firebase Integration
#include <HTTPClient.h>
#include <WiFi.h>
void sendWiFiStatusToCloud(String ssid) {
if(WiFi.status() == WL_CONNECTED){
HTTPClient http;
String url = "https://your-project.firebaseio.com/device_status.json";
String payload = "{\"SSID\":\"" + ssid + "\"}";
http.begin(url);
http.addHeader("Content-Type", "application/json");
http.POST(payload);
http.end();
}
}
✅ Every time ESP32 connects to Wi-Fi, the SSID is sent to Firebase, allowing cloud tracking.
🔹 2. Over-The-Air (OTA) Updates
OTA allows you to update firmware remotely without USB:
- Include the
ArduinoOTAlibrary:
#include <ArduinoOTA.h>
- Add OTA setup in
setup():
ArduinoOTA.begin();
- In
loop(), call:
ArduinoOTA.handle();
- Upload new firmware via Arduino IDE over Wi-Fi
- Eliminates the need to physically access the device
🔹 3. Security Measures
- Password Protection on Web Portal
if(request->getParam("password")->value() != "YourSecret") {
request->send(403, "text/plain", "Forbidden");
return;
}
- Use HTTPS / SSL Certificates for cloud communication
- Wi-Fi Credentials Encryption
- Store encrypted SSID & password in Preferences
- Prevents unauthorized access if EEPROM is read
🔹 4. Optional Advanced Features
- Device Grouping
- Assign multiple ESP32 devices to groups for bulk configuration
- Sensor Data Dashboard
- Display temperature, humidity, motion, or LED status
- Custom Captive Portal Themes
- Brand with your own logos and styling
🔹 5. Future Upgrades
- Integrate voice assistants (Alexa, Google Assistant) to switch networks via commands
- Add MQTT protocol for real-time cloud IoT communication
- Implement automatic Wi-Fi failover for multiple networks
- Extend dashboard to control multiple devices, LEDs, or relays
🔹 6. Final Testing & Deployment
- Disconnect ESP32 → triggers captive portal
- Connect via mobile → enter new credentials
- Verify automatic Wi-Fi reconnection
- Test dashboard, cloud sync, OTA update, and security measures
- Ensure all devices maintain connectivity and report real-time status
🔹 Conclusion
With this guide, you have learned how to:
- Build an ESP32 captive portal to update Wi-Fi dynamically
- Store credentials in non-volatile memory
- Create a web dashboard for device management
- Integrate cloud tracking and OTA updates
- Implement security and advanced IoT features
“This project transforms your ESP32 into a self-configuring, secure, and cloud-ready IoT device — no IP, no re-upload, just seamless Wi-Fi management.”
— YaranaIoT Guru
📞 Contact YaranaIoT Guru Empowering IoT Innovation | ESP32 | Home Automation | Smart Solutions | 50K+ Community
We’d love to hear from you! Whether it’s IoT project queries, collaborations, tech support, custom PCB design, bulk orders, corporate training, college workshops, or freelance development — we’re just one message away.
✉️ Email (Official)
For detailed inquiries, project support, business collaboration, sponsorships, or documentation: 📩 contact@yaranaiotguru.in 📧 Alternate: support@yaranaiotguru.in ⏳ Response: Within 24 hours (Mon–Sat) 💡 Best for attachments (code, schematics, logs, etc.)
📱 Phone / WhatsApp (24×7 Support)
Instant live help, troubleshooting, project consultation, or order updates: 📞 +91 70527 22734 💬 WhatsApp: Chat Now ⏰ Call Hours: Mon–Sat, 10 AM – 7 PM IST 🚀 Emergency? WhatsApp anytime — reply within 1 hour
🌐 Official Website
Tutorials, code, PDFs, schematics, blogs, free tools & online store: 🔗 www.yaranaiotguru.in 🛒 Shop: yaranaiotguru.in/shop (ESP32 DevKits, Sensors, Relays, Custom PCBs, Project Kits)
▶️ YouTube Channel
Step-by-step IoT builds, live coding, ESP32, Blynk, Node-RED, MQTT, Home Assistant & more: 🔗 Yarana IoT Guru 📺 1,200+ Videos | 52K+ Subs | 5.5M+ Views | 4.8★ Rating 🎥 New Video Every Week — 🔔 Subscribe & Turn On Notifications
🛠 GitHub (100% Open Source)
All codes, Arduino sketches, PlatformIO projects, Node-RED flows, MQTT configs & docs: 🔗 github.com/YaranaIotGuru ⭐ 50+ Repos | 10K+ Stars & Forks
🔥 Top Projects:
- ESP32 WebSocket Real-Time Dashboard
- Smart Home with Blynk & Alexa
- IoT Irrigation System with Soil Moisture
- MQTT + Node-RED + MySQL Logging
- OLED Weather Station with API
Daily reels, quick tips, live builds, student showcases & giveaways: 🔗 @YaranaIoTGuru 📱 10K+ Followers | Reels | Stories | Live Sessions
💼 LinkedIn (Professional Network)
B2B, IoT consulting, training, hiring & partnerships: 🔗 Yarana IoT Guru
🤝 Services Offered:
- Custom IoT Product Development
- Embedded Systems Training
- College Workshops & FDPs
- PCB Design & Prototyping
🐦 Twitter / X
Real-time updates, polls, project launches & community Q&A: 🔗 @YaranaIoTGuru 📢 Follow for instant alerts
🛠 Hackster.io (Project Showcases)
In-depth write-ups, circuits, BOM, code & ratings: 🔗 hackster.io/yaranaiotguru 🏆 50+ Projects | 100K+ Views | Top 5% Creator
📝 Instructables (DIY Guides)
Beginner-friendly step-by-step guides with templates & troubleshooting: 🔗 instructables.com/member/YaranaIoTGuru
🛠 Featured Guides:
- Automatic Plant Watering System
- Voice-Controlled Home Appliances
- WiFi-enabled Temperature Monitor
📚 Medium Blog
Deep-dive articles, trends, tutorials & career tips in embedded systems: 🔗 medium.com/@yaranaiotguru ✍️ 50+ Articles | 15K+ Readers
🛒 Online Store & Kits
Ready-to-use IoT kits, custom PCBs, sensors & merch: 🔗 yaranaiotguru.in/shop 📦 Free Shipping in India above ₹999 💳 Payment: UPI, Card, Wallet, COD
🌟 Community Platforms
| Platform | Link | Purpose |
|---|---|---|
| Telegram Channel | t.me/YaranaIoTGuru | Project files, PDFs, updates |
| Telegram Group | t.me/YaranaIoTCommunity | Peer support, doubts |
| Discord Server | discord.gg/yarana-iot | Live voice help, coding rooms |
| WhatsApp Community | Join Here | Announcements & polls |
🏢 Office & Studio Address
Yarana Studio & Software (Yarana IoT Guru HQ) 📍 Near Rookh Baba Mandir, Umariya Badal Urf Gainda, Allahabad (Prayagraj), Uttar Pradesh – 212507, India ⭐ Google Rating: 5.0 ★ (100+ Reviews)
🕒 Opening Hours: Mon–Sat: 10:00 AM – 5:00 PM Sunday: Closed
🌐 Associated Website: yaranawebtech.in 🗺️ View on Google Maps: Search “Yarana Studio & Software” 📌 Walk-ins welcome | Appointment recommended for project discussions