Production-Ready IoT Smart Home System for ESP8266
- Overview
- Features
- Hardware Requirements
- Software Requirements
- Installation Guide
- First-Time Setup
- Web Interface Guide
- OTA Firmware Updates
- API Documentation
- Physical Controls
- Troubleshooting
- Advanced Configuration
- Security & Best Practices
NIELIT Smart Lab is a comprehensive IoT system built on ESP8266, designed for educational institutions and home automation. It provides:
- Dual relay control with web and physical interfaces
- Environmental monitoring via DHT11 sensor
- Wireless firmware updates (OTA)
- Factory reset with authentication
- Real-time system monitoring and logging
Key Improvements in v3.0.0:
- β Fixed OTA Update page loading bug
- β Fixed Factory Reset authentication
- β Enhanced error handling
- β Improved code documentation
| Feature | Description |
|---|---|
| Relay Control | 2 independent relays (web + physical buttons) |
| Environmental Sensing | DHT11 temperature & humidity monitoring |
| WiFi Manager | Captive portal for easy network setup |
| OTA Updates | Upload firmware via web browser |
| Factory Reset | Complete device reset with password |
| System Logs | Real-time event tracking (20 entries) |
- β‘ Rate Limiting: 20 toggles/minute per relay
- πΎ EEPROM Persistence: Saves relay states across reboots
- π HTTP Authentication: Protects admin functions
- π mDNS Support: Access via
http://nielit-ropar.local - π Watchdog Timer: Auto-recovery from crashes (8s timeout)
- π Memory Monitoring: Auto-restart below 8KB free heap
- π Audio Feedback: Buzzer confirms all actions
| Component | Specification | Quantity | Pin Connection |
|---|---|---|---|
| ESP8266 Board | NodeMCU v3 / Wemos D1 Mini | 1 | - |
| Relay Module | 2-Channel 5V (ACTIVE-HIGH) | 1 | D1, D2 |
| Temperature Sensor | DHT11 | 1 | D5 |
| Status LEDs | 5mm Red/Green | 2 | D7, D8 |
| Control Buttons | Tactile Push Button | 2 | RX, TX |
| Buzzer | 5V Active Buzzer | 1 | D3 |
| Resistors | 220Ξ© (for LEDs) | 2 | - |
| Power Supply | 5V 2A USB/DC Adapter | 1 | VIN/5V |
| Breadboard | Half-size or full-size | 1 | - |
| Jumper Wires | Male-to-Male/Female | 20+ | - |
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ESP8266 NodeMCU Pin Configuration β
βββββββββββββββ¬βββββββββββ¬βββββββββββ¬βββββββββββββββββββββ€
β Function β Board Pinβ GPIO Pin β Connection Details β
βββββββββββββββΌβββββββββββΌβββββββββββΌβββββββββββββββββββββ€
β Relay 1 β D1 β GPIO5 β β Relay IN1 β
β Relay 2 β D2 β GPIO4 β β Relay IN2 β
β LED 1 β D7 β GPIO13 β β 220Ξ© β LED β GND β
β LED 2 β D8 β GPIO15 β β 220Ξ© β LED β GND β
β Button 1 β RX β GPIO3 β β Button β GND β
β Button 2 β TX β GPIO1 β β Button β GND β
β Buzzer β D3 β GPIO0 β β Buzzer+ β GND β
β DHT11 Data β D5 β GPIO14 β β DHT11 Data Pin β
β DHT11 VCC β 3.3V β - β β DHT11 VCC β
β DHT11 GND β GND β - β β DHT11 GND β
β Power In β VIN/5V β - β β 5V 2A Supply β
β Ground β GND β - β β Common Ground β
βββββββββββββββ΄βββββββββββ΄βββββββββββ΄βββββββββββββββββββββ
ββββββββββββββββββββββββ
β ESP8266 NodeMCU β
β β
5V Power ββββββββ€ VIN 3V3 ββββββ DHT11 VCC
Ground ββββββββββ€ GND GND ββββββ Common GND
β β
Relay IN1 βββββββ€ D1 (GPIO5) D5 ββββββ DHT11 Data
Relay IN2 βββββββ€ D2 (GPIO4) D7 ββββ[220Ξ©]βββ LED1 βββ GND
β D8 ββββ[220Ξ©]βββ LED2 βββ GND
Button1 βββββββββ€ RX (GPIO3) D3 ββββββ Buzzer+ βββ GND
Button2 βββββββββ€ TX (GPIO1) β
ββββββββββββββββββββββββ
ββββββββββββββββββββββββββββββββββββ
β 2-Channel Relay Module β
ββββββββββββββββββββββββββββββββββββ€
β VCC βββ 5V Power Supply β
β GND βββ Common Ground β
β IN1 βββ D1 (GPIO5) β
β IN2 βββ D2 (GPIO4) β
β β
β Relay 1: COM1 βββ¬ββ NO1 β
β βββ NC1 β
β Relay 2: COM2 βββ¬ββ NO2 β
β βββ NC2 β
ββββββββββββββββββββββββββββββββββββ
- Relay Logic: ACTIVE-HIGH (HIGH = ON, LOW = OFF)
- Button Logic: ACTIVE-LOW with internal pullup (press = connect to GND)
- DHT11 Power: Use 3.3V for stability (5V can work but may cause errors)
- Common Ground: All components must share common ground with ESP8266
- Power Supply: 2A minimum to handle relay switching current
- Version Required: 1.8.19 or newer
- Download: arduino.cc/en/software
- Open Arduino IDE
- Go to File β Preferences
- In "Additional Board Manager URLs", add:
http://arduino.esp8266.com/stable/package_esp8266com_index.json - Click OK
- Go to Tools β Board β Boards Manager
- Search for
esp8266 - Install ESP8266 by ESP8266 Community (version 3.0.0+)
- Click Close
Open Sketch β Include Library β Manage Libraries and install:
| Library Name | Version | Author | Purpose |
|---|---|---|---|
| WiFiManager | 2.0.16+ | tzapu | WiFi configuration portal |
| ArduinoJson | 6.21.0+ | Benoit Blanchon | JSON parsing for API |
| DHT sensor library | 1.4.4+ | Adafruit | DHT11 temperature/humidity |
| Adafruit Unified Sensor | 1.1.9+ | Adafruit | Required by DHT library |
Built-in Libraries (No Installation Needed):
- ESP8266WiFi
- ESP8266WebServer
- ESP8266mDNS
- ESP8266HTTPUpdateServer
- EEPROM
Create a test sketch:
#include <ESP8266WiFi.h>
#include <WiFiManager.h>
#include <ArduinoJson.h>
#include <DHT.h>
void setup() {
Serial.begin(115200);
Serial.println("Libraries loaded successfully!");
}
void loop() {}Click Verify (β). If it compiles without errors, you're ready!
- Connect via USB to your computer
- Wait for drivers to install (Windows: Check Device Manager)
- Note the COM port (e.g., COM3, COM5)
- Windows: Device Manager β Ports (COM & LPT)
- Mac:
/dev/cu.usbserial-* - Linux:
/dev/ttyUSB*
- Open
NIELIT_SmartHome.ino - Go to Tools and configure:
| Setting | Value |
|---|---|
| Board | NodeMCU 1.0 (ESP-12E Module) |
| Upload Speed | 115200 |
| CPU Frequency | 80 MHz |
| Flash Size | 4MB (FS:2MB OTA:~1019KB) |
| Port | Your COM port (e.g., COM3) |
| Erase Flash | Only Sketch (or "All" for first upload) |
| Debug Level | None |
- Click Verify (β) button
- Wait for compilation (30-60 seconds)
- Check for errors in the output window
- Expected output:
Sketch uses 357,232 bytes (34%) of program storage space. Global variables use 31,416 bytes (38%) of dynamic memory.
- Ensure ESP8266 is connected via USB
- Click Upload (β) button
- Monitor progress in the output window:
Uploading... Writing at 0x00000000... (10%) Writing at 0x00004000... (20%) ... Writing at 0x00074000... (100%) Hard resetting via RTS pin... - Success message:
Done uploading.
Instead, verify upload by:
- Audio feedback:
- 3 beeps = Fresh boot (no saved state)
- 2 beeps = State restored from EEPROM
- LED indicators:
- LEDs should be OFF (or match last saved state)
- WiFi network:
- Look for
NIELIT-SmartLabWiFi network (AP mode)
- Look for
Why No Serial Monitor?
- GPIO3 (RX) and GPIO1 (TX) are used for physical buttons
- Serial communication would interfere with button detection
- All diagnostics available via web interface (
/logspage)
When powered on for the first time, the device enters Access Point (AP) Mode:
| Beep Pattern | Meaning |
|---|---|
| 3 beeps | Fresh boot (no EEPROM data) |
| 4 beeps | AP mode activated |
| 1 beep | WiFi connected successfully |
| 2 beeps | State restored from EEPROM |
Step 1: Power ON Device
βͺοΈ Connect 5V power supply
βͺοΈ Wait 3-5 seconds for boot
βͺοΈ Listen for 4 beeps (AP mode active)
Step 2: Connect to AP
π± On your phone/laptop:
ββ WiFi Settings
ββ Select: NIELIT-SmartLab
ββ Password: nielit2025
Step 3: Configure WiFi
π Captive portal opens automatically
(If not, browse to: http://192.168.4.1)
1. Click "Configure WiFi"
2. Select your home WiFi network
3. Enter WiFi password
4. Click "Save"
Step 4: Wait for Connection
β³ Device will:
1. Save credentials to memory
2. Reboot automatically
3. Connect to your WiFi
4. Beep once (success)
Step 5: Find Device IP
Since Serial Monitor is disabled, use:
Option A: Router Admin Panel
ββ DHCP Client List
ββ Look for "ESP_XXXXXX" or "NIELIT-SmartLab"
Option B: mDNS (if supported)
ββ Browse to: http://nielit-ropar.local
Option C: Network Scanner App
ββ Use: Fing (iOS/Android) or Advanced IP Scanner (Windows)
ββ Scan for device on port 80
| Problem | Solution |
|---|---|
| Can't see AP network | β’ Power cycle device β’ Check 2.4GHz WiFi enabled β’ Move closer to device |
| Captive portal doesn't open | β’ Manually go to 192.168.4.1β’ Disable mobile data β’ Try different browser |
| Can't connect to home WiFi | β’ Verify password (case-sensitive) β’ Check router is 2.4GHz β’ Ensure DHCP is enabled |
| No beep after save | β’ Wait 30 seconds β’ Check power supply (2A needed) β’ Try factory reset |
Primary Methods:
π http://DEVICE_IP_ADDRESS
Example: http://192.168.1.100
π http://nielit-ropar.local (mDNS)
Note: May not work on all networks
Default Credentials:
π€ Username: admin
π Password: rccrcc
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β NIELIT Ropar Smart Lab β
β Firmware v3.0.0 β’ β Online β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ£
β [RELAY CONTROL] β
β ββββββββββββββββββββββββββββββββββββββββββββββ β
β β Relay 1 [ON] [Turn OFF] β β
β β Relay 2 [OFF] [Turn ON] β β
β ββββββββββββββββββββββββββββββββββββββββββββββ β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ£
β [ENVIRONMENT SENSORS] β
β βββββββββββββββββββ¬ββββββββββββββββββ β
β β Temperature β Humidity β β
β β 28.5Β°C β 65.2% β β
β βββββββββββββββββββ΄ββββββββββββββββββ β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ£
β [SYSTEM INFO] β
β Uptime: 2h 15m β
β IP Address: 192.168.1.100 β
β Free Heap: 28.5 KB β
β Local URL: http://nielit-ropar.local/ β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ£
β [FACTORY RESET] β
β [ Factory Reset (Erase Wi-Fi & Settings) ] β
β β οΈ Requires password: admin / ****** β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ£
β Β© NIELIT Ropar 2025 β’ OTA Update β’ System Logs β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Relay Status Badge:
- π’ ON (Green) = Relay is active
- π΄ OFF (Red) = Relay is inactive
Control Buttons:
- Turn ON = Activates relay (green button)
- Turn OFF = Deactivates relay (red button)
Rate Limiting:
- Maximum: 20 toggles per minute per relay
- Counter resets every 60 seconds
- Exceeded limit shows error message
Audio Feedback:
- Single beep = Toggle successful
- No beep = Rate limit exceeded
Temperature Display:
- Range: -40Β°C to 80Β°C
- Updates every 5 seconds
- Shows
--if sensor error
Humidity Display:
- Range: 0% to 100%
- Updates every 5 seconds
- Shows
--if sensor error
Uptime:
- Format:
Xd Yh Zm(days, hours, minutes) - Example:
2d 5h 30m - Resets on device reboot
IP Address:
- Shows current local IP
- Click to copy (depends on browser)
Free Heap:
- Current available RAM
- Should stay above 8 KB
- Auto-restart if below 8 KB
Local URL:
- mDNS address (if supported)
- Alternative to IP address
Function:
- Clears all WiFi credentials
- Erases EEPROM data
- Resets to factory defaults
- Reboots into AP mode
Process:
- Click "Factory Reset" button
- Confirm warning dialog
- Enter username:
admin - Enter password:
rccrcc - Wait 5-10 seconds for reboot
Access: http://DEVICE_IP/logs
Features:
- Shows last 20 system events
- Auto-refreshes every 3 seconds
- Includes timestamps (in seconds since boot)
- No authentication required
Example Log Entries:
15s: System boot β NIELIT ROPAR v3.0.0
17s: EEPROM invalid or empty - using defaults
20s: DHT11 sensor initialized
25s: WiFi connected: 192.168.1.100
26s: mDNS started: nielit-ropar.local
27s: Web server started on port 80
28s: System ready β All services running
45s: Relay1 β ON
50s: Relay2 β ON
Using Arduino IDE:
- Open your modified
NIELIT_SmartHome.ino - Increment version if you made changes:
#define FIRMWARE_VERSION "3.0.1" // Change from 3.0.0
- Go to: Sketch β Export Compiled Binary
- Or press
Ctrl+Alt+S(Windows/Linux) - Or press
Cmd+Alt+S(Mac)
- Or press
- Wait for compilation (output shows "Done")
- Locate .BIN file:
- Windows:
Documents\Arduino\NIELIT_SmartHome\ - Mac:
~/Documents/Arduino/NIELIT_SmartHome/ - Linux:
~/Arduino/NIELIT_SmartHome/ - Filename:
NIELIT_SmartHome.ino.nodemcu.bin
- Windows:
Verify .BIN File:
β
File size: 350-450 KB
β
Extension: .bin
β
No spaces in filename (if renaming)
Access Update Page:
π http://DEVICE_IP/update
Example: http://192.168.1.100/update
π http://nielit-ropar.local/update
Update Process:
ββββββββββββββββββββββββββββββββββββββββββββ
β OTA Update β NIELIT ROPAR β
β β
β Current: v3.0.0 β
β β
β [Password: ******] β
β [Choose .bin File] β
β β
β β¬β¬β¬β¬β¬β¬β¬β¬β¬β¬ 0% β
β β
β [Update Firmware] (disabled) β
β β
β Β© NIELIT ROPAR 2025 β’ Back to Dashboard β
ββββββββββββββββββββββββββββββββββββββββββββ
Steps:
- Enter password:
rccrcc - Click "Choose .bin File"
- Select your .bin file
- Click "Update Firmware"
- Monitor progress bar
- Wait for success message
- Device reboots automatically (20-30 seconds)
- Verify new version on dashboard
Upload Progress:
β¬β¬β¬β¬β¬β¬β¬β¬β¬β¬ 0% β Starting upload...
β¬β¬β¬β¬β¬β¬β¬β¬β¬β¬ 25% β Uploading...
β¬β¬β¬β¬β¬β¬β¬β¬β¬β¬ 50% β Halfway there...
β¬β¬β¬β¬β¬β¬β¬β¬β¬β¬ 75% β Almost done...
β¬β¬β¬β¬β¬β¬β¬β¬β¬β¬ 100% β β
Success! Rebooting...
| Error | Cause | Solution |
|---|---|---|
| "Authentication failed" | Wrong password | Use rccrcc exactly |
| "Only .bin files allowed" | Wrong file type | Export compiled binary, not .ino |
| "Upload failed" | Network issue | Move closer to router, retry |
| "Not enough space" | Wrong flash settings | Recompile with 4MB OTA partition |
| Page doesn't load | Browser cache | Hard refresh (Ctrl+F5) |
| Device unresponsive | Bad firmware | Recover via USB upload |
If device becomes unresponsive:
- Connect via USB
- Open Arduino IDE
- Select correct COM port
- Upload working firmware (normal upload method)
- Wait for upload to complete
- Perform factory reset (web interface or via code)
Why OTA might fail:
- β Wrong board type selected during compilation
- β Flash size mismatch (must have OTA partition)
- β Corrupted .bin file
- β Power loss during upload
- β WiFi connection dropped mid-upload
All API endpoints return JSON responses and use RESTful conventions.
Base URL: http://DEVICE_IP/api/
Authentication: Required for /factory-reset only (HTTP Basic Auth)
Description: Retrieve current system status
Authentication: None
Response:
{
"version": "3.0.0",
"r1": true,
"r2": false,
"temp": 28.5,
"hum": 65.2,
"uptime": 125430,
"ip": "192.168.1.100",
"heap": 28672
}Response Fields:
| Field | Type | Description |
|---|---|---|
version |
string | Firmware version |
r1 |
boolean | Relay 1 state (true=ON) |
r2 |
boolean | Relay 2 state (true=ON) |
temp |
float | Temperature in Celsius |
hum |
float | Relative humidity (%) |
uptime |
integer | Milliseconds since boot |
ip |
string | Device IP address |
heap |
integer | Free heap in bytes |
Example cURL:
curl http://192.168.1.100/api/statusDescription: Retrieve system event logs
Authentication: None
Response:
{
"logs": [
"15s: System boot β NIELIT ROPAR v3.0.0",
"20s: WiFi connected: 192.168.1.100",
"45s: Relay1 β ON",
"50s: Relay2 β OFF",
""
]
}Response Fields:
logs: Array of 20 log entries (oldest first)- Empty strings indicate unused buffer slots
Example cURL:
curl http://192.168.1.100/api/logsDescription: Turn Relay 1 ON
Authentication: None
Response: 303 redirect to / (dashboard)
Rate Limit: 20 toggles/minute
Error Response (429):
Rate limit exceeded: Max 20 toggles/min
Example cURL:
curl http://192.168.1.100/api/relay1/onDescription: Turn Relay 1 OFF
Authentication: None
Response: 303 redirect to / (dashboard)
Example cURL:
curl http://192.168.1.100/api/relay1/offDescription: Turn Relay 2 ON
Authentication: None
Response: 303 redirect to / (dashboard)
Example cURL:
curl http://192.168.1.100/api/relay2/onDescription: Turn Relay 2 OFF
Authentication: None
Response: 303 redirect to / (dashboard)
Example cURL:
curl http://192.168.1.100/api/relay2/offDescription: Soft reset (clears EEPROM only, keeps WiFi)
Authentication: None
Response:
<h2>Resetting device... Β© NIELIT ROPAR</h2>Effect:
- Clears EEPROM data
- Keeps WiFi credentials
- Reboots device
Example cURL:
curl http://192.168.1.100/api/resetDescription: Complete factory reset (WiFi + EEPROM)
Authentication: HTTP Basic Auth (admin / rccrcc)
Response:
{
"status": "success",
"message": "Factory reset complete. Rebooting into AP mode..."
}Effect:
- Clears EEPROM data
- Erases WiFi credentials
- Reboots into AP mode
- Audio: 5 beeps before reboot
Example cURL:
curl -u admin:rccrcc http://192.168.1.100/api/factory-resetError Response (401):
Authentication required
import requests
BASE_URL = "http://192.168.1.100/api"
# Get status
response = requests.get(f"{BASE_URL}/status")
data = response.json()
print(f"Temperature: {data['temp']}Β°C")
print(f"Relay 1: {'ON' if data['r1'] else 'OFF'}")
# Toggle relay
requests.get(f"{BASE_URL}/relay1/on")
# Factory reset (requires auth)
requests.get(
f"{BASE_URL}/factory-reset",
auth=('admin', 'rccrcc')
)// Get status
fetch('http://192.168.1.100/api/status')
.then(r => r.json())
.then(d => {
console.log(`Temperature: ${d.temp}Β°C`);
console.log(`Relay 1: ${d.r1 ? 'ON' : 'OFF'}`);
});
// Toggle relay
fetch('http://192.168.1.100/api/relay1/on');
// Factory reset (with auth)
fetch('http://192.168.1.100/api/factory-reset', {
method: 'GET',
headers: {
'Authorization': 'Basic ' + btoa('admin:rccrcc')
}
});- HTTP Basic Authentication for OTA updates and factory reset
- Rate Limiting prevents relay abuse (20 toggles/min)
- Input Validation for all API endpoints
- WiFi Encryption with configurable AP password
Symptoms: Can't connect to home WiFi, keeps showing NIELIT-SmartLab network
- Solution 1: Reset WiFi credentials
- Access device via AP mode (
NIELIT-SmartLab/nielit2025) - Open
http://192.168.4.1 - Reconfigure WiFi with correct credentials
- Access device via AP mode (
- Solution 2: Factory reset
- Power off device
- Press and hold Button 1
- Power on while holding (release after 5 seconds)
- Device resets to AP mode
- Check: WiFi is enabled on your phone/laptop
- Check: You're within 10m of the device
- Check: 2.4GHz WiFi is supported (5GHz won't work)
- Try: Restart the device (power cycle)
- Manual access: Open browser and go to
http://192.168.4.1 - Disable mobile data: Turn off cellular data on phone
- Try different browser: Use Chrome/Firefox instead of in-app browsers
- Verify: SSID and password are correct (case-sensitive)
- Check: Router is 2.4GHz capable (ESP8266 doesn't support 5GHz)
- Check: Router allows new device connections (not MAC filtered)
- Try: Move device closer to router
- Reset: Hold power button for 10+ seconds to force AP mode
- Check Serial Monitor for IP address (115200 baud)
- Use mDNS:
http://nielit-ropar.local - Check router's DHCP client list
- Use IP scanner app (Fing, Advanced IP Scanner)
- Rate Limit: Wait 60 seconds if you hit 20 toggles/minute limit
- Power Check: Verify relay module has separate 5V supply
- Wiring Check:
- Relay 1 β D1 (GPIO5)
- Relay 2 β D2 (GPIO4)
- Common ground between ESP8266 and relay module
- Test: Use physical buttons to rule out software issues
- Logs: Check
/logspage for error messages
- Wiring Check:
- Button 1 β RX (GPIO3) β Ground
- Button 2 β TX (GPIO1) β Ground
- Note: Buttons are ACTIVE-LOW (press connects to GND)
- Test: Buttons should trigger audio feedback (beep)
- Warning: RX/TX buttons may interfere with Serial Monitor during boot
- Wiring Verification:
DHT11 VCC β 3.3V (NOT 5V for stability) DHT11 GND β GND DHT11 DATA β D5 (GPIO14) - Pull-up Resistor: Add 10kΞ© resistor between DATA and VCC if using raw DHT11
- Wait Time: Sensor needs 2 seconds after boot to stabilize
- Test: Replace with known-good DHT11 module
- Valid Range: Temperature: -40Β°C to 80Β°C, Humidity: 0-100%
- Check: LED polarity (long leg = anode = positive)
- Resistor: Use 220Ξ©-330Ξ© current-limiting resistor
- Pins: LED1 β D7 (GPIO13), LED2 β D8 (GPIO15)
- Note: LEDs mirror relay states (ON = HIGH = lit)
- Type: Use ACTIVE buzzer (built-in oscillator)
- Pin: Connect to D3 (GPIO0)
- Polarity: Red/+ to GPIO0, Black/- to GND
- Test: Should beep on boot and button presses
- Clear Cache: Force refresh (
Ctrl+F5orCmd+Shift+R) - Try: Use incognito/private browsing mode
- Direct URL:
http://YOUR_IP/update - Check: Firmware version in code is v3.0.0+ (older versions had bug)
- Credentials:
Username: admin Password: rccrcc - Case Sensitive: Enter exactly as shown
- Browser: Avoid auto-fill, type manually
- File Check: Ensure
.binfile is for ESP8266 (not ESP32) - Size Check: File should be 300-500 KB
- Flash Size: Compiled with correct settings (4MB with OTA partition)
- WiFi: Ensure stable connection during upload (stay within 5m of router)
- Recovery: If device becomes unresponsive:
- Power off
- Connect via USB
- Upload firmware via serial (not OTA)
- Flash Settings: Recompile with: 4MB (FS:2MB OTA:~1019KB)
- Clear EEPROM: Use factory reset before OTA update
- Last Resort: Re-upload via USB with "Erase Flash: All Flash Contents"
- Serial Monitor: Check for error messages
- Memory: Low heap warning? (check
/api/statusβ heap) - Power Supply: Insufficient current (need 2A minimum)
- Watchdog: Triggering due to blocked operations (check logs)
- Fix: Factory reset and re-upload firmware
- EEPROM Check: Look for "State saved to EEPROM" in logs
- Fix: Perform soft reset (
/api/reset) - Verify: Check
state.magicvalue in logs (should be 0xAA)
- Normal: Max 20 toggles per relay per minute
- Counter Reset: Automatically resets every 60 seconds
- Workaround: Wait 1 minute or perform soft reset
- Check: Review
/logsfor excessive toggle attempts
- JavaScript: Ensure JS is enabled in browser
- Console: Check browser console (F12) for errors
- Network: Verify
/api/statusendpoint returns valid JSON - Try: Hard refresh or clear browser cache
- Authentication: Must enter credentials in popup
- Username:
admin - Password:
rccrcc
- Username:
- Confirmation: Must click "OK" in confirmation dialog
- Browser: Some browsers block popups - check for blocked popup icon
- Manual Method: Use API endpoint with curl:
curl -u admin:rccrcc http://YOUR_IP/api/factory-reset
Access: Tools β Serial Monitor (115200 baud) Useful Commands: Look for:
- Boot messages with version number
- IP address assignment
- Error messages
- EEPROM state
- Relay toggle events
Access: http://YOUR_IP/logs
- Shows last 20 events
- Auto-refreshes every 3 seconds
- Includes timestamps
- Helps diagnose issues without USB connection
Access: http://YOUR_IP/api/status
Returns:
{
"version": "3.0.0",
"r1": true,
"r2": false,
"temp": 28.5,
"hum": 65.2,
"uptime": 125430,
"ip": "192.168.1.100",
"heap": 28672 β Monitor this for memory issues
}-
Via Web Interface:
- Go to dashboard
- Scroll to "Factory Reset" section
- Enter credentials (
admin/rccrcc) - Confirm reset
- Wait for reboot into AP mode
-
Via API (if web interface not working):
curl -u admin:rccrcc http://YOUR_IP/api/factory-reset
-
Hardware Method (if completely unresponsive):
- Power off device
- Connect to computer via USB
- In Arduino IDE: Tools β Erase Flash β All Flash Contents
- Re-upload firmware
- Reconfigure WiFi from scratch
- Connect device via USB
- Open Arduino IDE
- Upload working firmware via serial
- Check Serial Monitor for errors
- Perform factory reset if needed
You can modify these constants in the firmware before uploading:
// In NIELIT_SmartHome.ino
#define DEVICE_NAME "NIELIT-SmartLab" // AP name and mDNS hostname
#define AP_PASSWORD "nielit2025" // AP mode password
#define ADMIN_USER "admin" // Web interface username
#define ADMIN_PASS "rccrcc" // Web interface password
#define MAX_TOGGLES_PER_MIN 20 // Rate limit per relay
#define DHT_UPDATE_INTERVAL 5000 // Sensor read interval (ms)
#define MIN_FREE_HEAP 8192 // Auto-restart threshold (bytes)After making changes:
- Save the file
- Recompile and upload via USB or OTA
- Device will use new settings after reboot
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ESP8266 NodeMCU β
β β
β 3V3 ββββββββββββββ VCC (DHT11) β
β GND ββββββββββββββ GND (DHT11, Relay, LEDs, Buzzer) β
β β
β D1 ββββββββββββββ IN1 (Relay Channel 1) β
β D2 ββββββββββββββ IN2 (Relay Channel 2) β
β β
β D5 ββββββββββββββ DATA (DHT11) β
β β
β D7 βββββ[220Ξ©]βββ LED1 (Anode) β Cathode to GND β
β D8 βββββ[220Ξ©]βββ LED2 (Anode) β Cathode to GND β
β β
β D3 ββββββββββββββ BUZZER (+) β BUZZER (-) to GND β
β β
β RX βββββ[BTN1]βββ GND (Press to toggle Relay 1) β
β TX βββββ[BTN2]βββ GND (Press to toggle Relay 2) β
β β
β VIN ββββββββββββββ 5V Power Supply β
β GND ββββββββββββββ Power Supply GND β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β 2-Channel Relay Module β
β β
β VCC ββββββββββββββ 5V Power Supply β
β GND ββββββββββββββ Common GND with ESP8266 β
β IN1 ββββββββββββββ From D1 (GPIO5) β
β IN2 ββββββββββββββ From D2 (GPIO4) β
β β
β COM1 βββββββββββββ AC/DC Load Common β
β NO1 βββββββββββββ AC/DC Load (Normally Open) β
β NC1 β (unused - Normally Closed) β
β β
β COM2 βββββββββββββ AC/DC Load Common β
β NO2 βββββββββββββ AC/DC Load (Normally Open) β
β NC2 β (unused - Normally Closed) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β οΈ SAFETY WARNING:
- Never work on AC circuits while powered
- Use proper insulation and enclosures
- Follow local electrical codes
- Test with low voltage loads first (LED strips, DC fans)
| Function | ESP8266 Pin | GPIO | Notes |
|---|---|---|---|
| Relay 1 | D1 | GPIO5 | Output (ACTIVE-HIGH) |
| Relay 2 | D2 | GPIO4 | Output (ACTIVE-HIGH) |
| LED 1 | D7 | GPIO13 | Mirrors Relay 1 state |
| LED 2 | D8 | GPIO15 | Mirrors Relay 2 state |
| Button 1 | RX | GPIO3 | Input (ACTIVE-LOW) |
| Button 2 | TX | GPIO1 | Input (ACTIVE-LOW) |
| Buzzer | D3 | GPIO0 | Output (ACTIVE-HIGH) |
| DHT11 | D5 | GPIO14 | Data pin |
Before deploying in production:
-
Modify credentials in code:
#define ADMIN_USER "your_username" #define ADMIN_PASS "your_strong_password" #define AP_PASSWORD "your_ap_password"
-
Use strong passwords:
- Minimum 8 characters
- Mix of letters, numbers, symbols
- Avoid common words
- Use WPA2/WPA3 encryption on your WiFi router
- Change AP password from default
nielit2025 - Disable AP mode after initial setup (requires code modification)
- Use VPN if accessing from outside local network
- Firewall rules to restrict access to device IP
- Verify
.binfiles before OTA updates - Keep backups of working firmware versions
- Test updates on development device first
- Monitor logs for unauthorized access attempts
| Metric | Value |
|---|---|
| Boot Time | ~5-8 seconds (WiFi dependent) |
| Web Response Time | <100ms (local network) |
| Relay Switching Speed | <50ms |
| DHT Update Rate | Every 5 seconds |
| API Rate Limit | 20 toggles/min per relay |
| Max Concurrent Users | 4-5 (limited by ESP8266 RAM) |
| Memory Usage (Idle) | ~25-30 KB free heap |
| Power Consumption | ~80mA (idle), ~250mA (relays ON) |
| WiFi Range | ~30m (indoor, 2.4GHz) |
| OTA Update Time | 30-60 seconds |
- Smart Lighting: Control room lights remotely
- Fan Control: Automated temperature-based fan control
- Appliance Scheduling: Timer-based device control
- Environmental Monitoring: Track room temperature/humidity
- IoT Learning: Hands-on ESP8266 programming
- Web Development: REST API and frontend integration
- Electronics: Relay control and sensor interfacing
- Network Protocols: WiFi, HTTP, mDNS, OTA
- Equipment Control: Remote lab equipment switching
- Climate Monitoring: Temperature/humidity logging
- Access Control: Authenticated remote operation
- Energy Management: Monitor device states and uptime
- β Fixed OTA Update page loading issue (PROGMEM handling)
- β Fixed Factory Reset authentication and execution
- β Improved code documentation and readability
- β Enhanced error handling for web endpoints
- Added factory reset functionality
- Improved memory management
- Enhanced logging system
- Initial production release
- Core relay and sensor functionality
MIT License β Β© NIELIT ROPAR 2025
Developed by: Lovnish Verma
Contact: princelv84@gmail.com
Documentation: Wiki
For bug reports and feature requests, please open an issue on GitHub.
Built with:
- ESP8266 Arduino Core
- WiFiManager by tzapu
- ArduinoJson by Benoit Blanchon
- DHT Sensor Library by Adafruit
- NOCE MCU Blynk board
