Skip to content

Mayborg121/smartHome

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

24 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ”’ ESP32 Smart Home Automation Project

๐Ÿ“œ Project Overview

This project is a secure, Wi-Fi-enabled Smart Home Automation System built using the ESP32 microcontroller. It allows real-time control and monitoring of devices (Relays, NeoPixel RGB LEDs, Stepper Motor, DHT22 sensor) through a dynamic WebSocket interface served from the ESP32โ€™s file system (LittleFS).

Only authenticated users can access the control panel using a challenge-response password hashing mechanism without storing the password in the ESP32 memory โ€” ensuring secure, stateless authentication.


๐Ÿ“Œ Features

  • ๐Ÿ” Secure Challenge-Response WebSocket Authentication
  • ๐ŸŒ Dynamic web interface with WebSocket-based real-time updates
  • ๐Ÿ”Œ 4x Relays: Toggle control via web and physical buttons
  • ๐ŸŒก๏ธ DHT22: Real-time temperature and humidity monitoring
  • ๐ŸŽจ NeoPixel RGB LED: Color control from UI
  • ๐Ÿค€ Stepper Motor: Angular control via slider with auto-reset on boot
  • ๐Ÿ“ฒ Works over local Wi-Fi or fallback hotspot
  • ๐Ÿ’พ Uses LittleFS for HTML, CSS, JS
  • ๐ŸŽฏ UUID-based device recognition (up to 5 remembered clients)
  • ๐Ÿ“‰ System info console and log display

๐Ÿ“‚ Folder Structure

SmartHome-ESP32/
โ”‚
โ”œโ”€โ”€ data/                      # Web UI files for LittleFS
โ”‚   โ”œโ”€โ”€ index.html             # Login page
โ”‚   โ”œโ”€โ”€ control.html           # Smart control panel (after auth)
โ”‚   โ”œโ”€โ”€ style.css              # Web styling
โ”‚   โ””โ”€โ”€ script.js              # WebSocket + UI logic
โ”‚
โ”œโ”€โ”€ src/
โ”‚   โ””โ”€โ”€ main.cpp               # Core firmware code
โ”‚
โ”œโ”€โ”€ platformio.ini             # PlatformIO config
โ”œโ”€โ”€ README.md                  # Project documentation (this file)
โ””โ”€โ”€ credentials_template.h     # Wi-Fi credentials (excluded from repo)

๐Ÿง  Authentication Logic (Password Verification)

We use challenge-response SHA-256 hashing. Password is never stored or transmitted directly. Here's a highlight from main.cpp:

#include <SHA256.h>
#include <Preferences.h>

Preferences preferences;
SHA256 sha256;

// Example password hash (not plain password)
const char* correctHash = "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd..."; // sha256("password")

bool verifyPassword(String userResponse, String challenge) {
    String combined = challenge + "password";  // 'password' is never stored; just shown here for understanding
    sha256.reset();
    sha256.update(combined.c_str(), combined.length());
    uint8_t* result = sha256.result();

    String calculatedHash = "";
    for (int i = 0; i < 32; i++) {
        char hex[3];
        sprintf(hex, "%02x", result[i]);
        calculatedHash += hex;
    }

    return userResponse.equals(calculatedHash);
}
  • Server sends a challenge string to the browser.
  • Browser JavaScript hashes challenge + password and sends it back.
  • ESP32 verifies by recomputing SHA-256 on same.

๐Ÿ”ง Hardware Setup

  • โœ… ESP32 Devkit V1
  • โœ… 4x Relays on GPIO 16โ€“19
  • โœ… 4x Buttons on GPIO 21โ€“25 (optional debounce)
  • โœ… DHT22 Sensor on GPIO 4
  • โœ… NeoPixel RGB LED on GPIO 5 (WS2812)
  • โœ… Stepper Motor (28BYJ-48 + ULN2003) on GPIOs 26โ€“29
  • โœ… Power supply: 5V regulated for relays/motor

๐ŸŒ Web Interface Walkthrough

See screenshots below for better understanding WEB APP ๐Ÿ‘ˆ Click Here

Smart Home Web UI

1. Login Page (``)

Login Page ๐Ÿ‘ˆ Click Here

  • User connects to ESP hotspot SmartHome-ESP32 (PW: 00000000) or home Wi-Fi.
  • A random challenge string is shown.
  • User enters password โ†’ client hashes password + challenge โ†’ sends hash.

2. Main Control Panel (``)

Controls Page ๐Ÿ‘ˆ Click Here Top Console:

  • Device info: RAM, CPU freq, uptime, IP
  • WebSocket client ID
  • Scrollable serial monitor logs

Relay Control:

  • Toggle buttons for 4 relays
    Example log:
    { "Type": "Control", "Key": "Light-1", "Value": "on" }

DHT22 Sensor Display:

  • Live temperature and humidity updates every 2s
    *Example: *Temp: 29.4ยฐC | Humidity: 62%

NeoPixel Control:

  • HTML color picker to choose RGB values
    Logs as:
    { "Type": "Control", "Key": "Ambience", "Value": "#ff8800" }

Stepper Motor Slider:

  • Angular control via slider (0ยฐโ€“180ยฐ)
  • Resets to 0ยฐ on boot

๐Ÿ” UUID-Based Authorization

  • On successful login, ESP stores { username : UUID } in NVS Preferences
  • Maintains last 5 UUIDs
  • If a known UUID connects, skips login and serves control.html directly

Code snippet:

preferences.begin("uuid-auth", false);
preferences.putString("user1", "UUID-1234");
String uuid = preferences.getString("user1");
preferences.end();

๐Ÿงช Testing Instructions

First Time Setup

  1. Power on ESP32, connect to hotspot SmartHome-ESP32 (PW: 00000000)
  2. Open 192.168.4.1
  3. Enter password (e.g. password123)
  4. Control panel opens after successful hash match

Switching to Home Wi-Fi

  1. From UI, go to "Update Credentials"
  2. Enter your home Wi-Fi SSID and password
  3. Restart ESP32 โ€” now it auto-connects

๐Ÿ› ๏ธ PlatformIO Configuration

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200
build_flags =
  -DCORE_DEBUG_LEVEL=3
lib_deps =
  bblanchon/ArduinoJson
  me-no-dev/ESP Async WebServer
  me-no-dev/AsyncTCP

๐Ÿ““ Future Improvements

  • Add OTA firmware updates
  • Role-based access (Admin vs Guest)
  • MQTT integration with external broker
  • Voice assistant control (Alexa/Google)

๐Ÿ–ผ๏ธ HardWare Demonstrative

insides front pink isometric ariel inside project backpanel


๐Ÿ–ผ๏ธ Screenshots & UI

loginpage controls Debugmode updatespage


๐Ÿ–ผ๏ธ Code & Algorithms

Challenge Generation & UUID MGMT Hash Verification Authentication WebSocket Event Handling Device Info MGMT

๐Ÿ“ฃ Credits

Developer: Mayur Borgude
Year: 2025
Project Type: B.E. Final Year Embedded + Web IoT System


๐Ÿ“œ License

This project is open-source and free to use under the MIT License. Please give credit where due.

About

Smart Home Automation Security and Control.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published