Skip to content

adhamNemr/MySmartHome

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

15 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🏠 MySmartHome - IoT Home Automation System

A full-stack IoT home automation system that enables real-time monitoring and control of smart home devices through a web interface, WebSocket communication, and Telegram bot integration.

Node.js Express.js WebSocket SQLite

πŸ“Έ Screenshots

Dashboard Interface

Dashboard UI Modern, responsive dashboard for controlling smart home devices with real-time sensor data

Real-time WebSocket Communication

WebSocket Data Stream Live sensor data streaming via WebSocket - temperature, humidity, gas, flame, and motion detection

Telegram Bot Integration

Telegram Integration Automated Telegram alerts for critical events and remote control capabilities

API Endpoints

API Endpoint RESTful API handling alerts and device commands

IoT Device Code (ESP32/Arduino)

ESP32 Code Arduino/ESP32 firmware for sensor integration and WebSocket communication

🌟 Features

Core Functionality

  • Real-time Device Control: Control smart home devices instantly via WebSocket connections
  • Multi-Room Management: Organize and manage devices across different rooms
  • Sensor Data Logging: Track and store sensor readings (temperature, humidity, motion, etc.)
  • User Authentication: Secure login system with bcrypt password hashing
  • Telegram Bot Integration: Control your home remotely through Telegram commands
  • RESTful API: Comprehensive API for device management and data retrieval

Technical Highlights

  • WebSocket Server: Bi-directional real-time communication on port 8080
  • Express Backend: Robust REST API with proper middleware architecture
  • Database ORM: Sequelize for database operations and migrations
  • CORS Enabled: Configured for both local development and production deployment
  • Responsive Dashboard: Clean web interface for device monitoring and control

πŸ—οΈ Architecture

MySmartHome/
β”œβ”€β”€ config/          # Database configuration
β”œβ”€β”€ controllers/     # Business logic handlers
β”œβ”€β”€ models/          # Sequelize database models
β”œβ”€β”€ routes/          # API route definitions
β”œβ”€β”€ middleware/      # Custom middleware functions
β”œβ”€β”€ public/          # Frontend static files
β”‚   β”œβ”€β”€ css/        # Stylesheets
β”‚   β”œβ”€β”€ js/         # Client-side JavaScript
β”‚   └── images/     # UI assets
β”œβ”€β”€ scripts/         # Utility scripts
β”œβ”€β”€ __tests__/       # Jest test suites
└── server.js        # Main application entry point

πŸš€ Quick Start

Prerequisites

  • Node.js (v14 or higher)
  • npm or yarn
  • SQLite (or your preferred SQL database)

Installation

  1. Clone the repository
git clone https://github.com/adhamNemr/MySmartHome.git
cd MySmartHome
  1. Install dependencies
npm install
  1. Configure environment variables
cp .env.example .env
# Edit .env with your configuration
  1. Initialize the database
node createUser.js  # Create initial admin user
  1. Start the server
npm start

The application will be available at:

πŸ”§ API Endpoints

Authentication

  • POST /api/login - User authentication

Device Management

  • GET /api/devices - List all devices
  • POST /api/devices - Create new device
  • PUT /api/devices/:id - Update device
  • DELETE /api/devices/:id - Remove device

Room Management

  • GET /api/rooms - List all rooms
  • POST /api/rooms - Create new room

Sensor Data

  • GET /api/sensors-data - Retrieve sensor readings
  • POST /log-sensor - Log new sensor data

System Logs

  • GET /api/logs - Fetch system logs

Commands

  • POST /api/commands - Send device commands

πŸ§ͺ Testing

Run the test suite:

npm test

🌐 Deployment

The application is configured for deployment on platforms like:

  • Vercel (Optimized for frontend deployment)
  • Railway / Render (Backend)
  • Heroku

CORS is pre-configured for production deployment.

πŸ” Security Features

  • Password hashing with bcrypt
  • JWT-ready architecture
  • Environment variable protection
  • CORS configuration
  • Input validation middleware

πŸ“Š Database Schema

The system uses the following main models:

  • User: Authentication and user management
  • Device: Smart device information
  • Room: Room organization
  • SensorLog: Historical sensor data
  • Command: Device command history

πŸ€– Telegram Integration

Control your smart home via Telegram bot commands. Configure your bot token in the .env file.

πŸ› οΈ Tech Stack

Backend:

  • Node.js & Express.js
  • WebSocket (ws library)
  • Sequelize ORM
  • bcrypt for password hashing
  • JWT for authentication

Frontend:

  • Vanilla JavaScript
  • HTML5 & CSS3
  • WebSocket client

Testing:

  • Jest

πŸ“ Environment Variables

Create a .env file with the following variables:

# Database
DATABASE_URL=your_database_url

# JWT Secret
JWT_SECRET=your_jwt_secret

# Telegram Bot
TELEGRAM_BOT_TOKEN=your_telegram_bot_token

# Server Configuration
PORT=3000
WEBSOCKET_PORT=8080

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“„ License

This project is licensed under the ISC License.

πŸ‘¨β€πŸ’» Author

Adham Nemr

πŸ™ Acknowledgments

Built as a comprehensive IoT solution demonstrating full-stack development skills, real-time communication, and modern web technologies.


⭐ If you find this project useful, please consider giving it a star on GitHub!

About

Complete IoT residential automation ecosystem focused on hardware-software synergy.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors