Skip to content

Latest commit

Β 

History

21 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Remote Elevator Control System

Production-ready system for remotely controlling an elevator unlock relay through an ESP32 device. The system includes a backend API, cross-platform mobile/web applications, and ESP32 firmware.

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Mobile App    │◄───────►│   Backend API   β”‚
β”‚ (Android/iOS)   β”‚  HTTPS  β”‚    (NestJS)     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                     β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                  β”‚
β”‚    Web App      │◄──────────────────
β”‚   (Browser)     β”‚       HTTPS      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                  β”‚
                                     β”‚ HTTPS
                            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”
                            β”‚   ESP32 Device  β”‚
                            β”‚   (Firmware)    β”‚
                            β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                     β”‚
                              β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”
                              β”‚ LED/Relay   β”‚
                              β”‚  (Control)  β”‚
                              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“¦ Components

Backend (backend/)

  • Tech: NestJS + TypeScript + PostgreSQL + Prisma
  • Features: JWT auth, role-based access, device management, switch control API
  • Port: 3000 (default)

Frontend (app/)

  • Tech: Angular + Ionic + Capacitor
  • Platforms: Web, Android, iOS (single codebase)
  • Features: Manual control, GPS/WiFi auto-unlock, admin dashboard

ESP32 Firmware (esp32/)

  • Tech: Arduino framework + PlatformIO
  • Features: Server polling, PULSE mode, LED/relay control

🐳 Docker Deployment (Recommended)

Quick start with Docker:

docker-compose up -d

Access:

For detailed Docker instructions, see DOCKER.md.

πŸš€ Quick Start (Manual)

1. Backend Setup

cd backend
npm install
cp .env.example .env
# Edit .env with your database credentials
npm run prisma:generate
npm run migrate
npm run seed
npm run start:dev

Default admin: admin@remotecon.local / admin123

2. Frontend Setup

Web version:

cd app
npm install
npm start
# Open http://localhost:8100

Android/iOS:

npm install
ionic build
npx cap sync android  # or ios
npx cap open android  # or ios

3. ESP32 Setup

cd esp32
# Edit src/config.h with WiFi and server details
pio run --target upload
pio device monitor

βš™οΈ Configuration

Backend Environment Variables

DATABASE_URL="postgresql://user:pass@localhost:5432/remotecon"
JWT_ACCESS_SECRET="your-secret-key"
JWT_REFRESH_SECRET="your-refresh-secret"
PORT=3000

Frontend Environment

Edit app/src/environments/environment.ts:

apiUrl: 'http://localhost:3000/api'  // Your backend URL

ESP32 Configuration

Edit esp32/src/config.h:

#define WIFI_SSID "YourWiFi"
#define WIFI_PASSWORD "password"
#define SERVER_URL "http://192.168.1.100:3000/api"
#define DEVICE_KEY "test-device-key-12345"

πŸ”’ Security Features

  • βœ… JWT access + refresh tokens (15min / 7day)
  • βœ… Bcrypt password hashing
  • βœ… Rate limiting on auth endpoints (5 req/min)
  • βœ… Role-based authorization (USER, ADMIN)
  • βœ… Device authentication via deviceKey
  • βœ… User approval workflow (admin must approve new registrations)

πŸ“± Features

User Features

  • Register and login (requires admin approval)
  • Manual switch enable/disable
  • GPS auto-unlock (20 min when arriving home)
  • WiFi auto-unlock (10 min when connecting to home WiFi)
  • Persistent notification with "Turn Off" button
  • Configure home location and WiFi networks

Admin Features

  • Approve/reject user registrations
  • View all devices and their status
  • Monitor last ESP32 poll time
  • View current switch state per device

Switch Modes

  • OFF: Switch/LED off
  • PULSE: Toggle at intervals (e.g., 500ms ON every 10s)
  • CONTINUOUS: Stay on (not currently used)

πŸ§ͺ Testing

Backend:

cd backend
npm test
npm run test:cov

Frontend:

cd app
npm test

Integration:

  1. Start backend
  2. Start frontend (web or mobile)
  3. Register user β†’ Admin approves β†’ Login
  4. Enable switch β†’ ESP32 LED lights up
  5. Verify pulse timing matches settings

πŸ“ Project Structure

remotecon/
β”œβ”€β”€ backend/               # NestJS backend
β”‚   β”œβ”€β”€ prisma/           # Database schema & migrations
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ auth/         # Authentication module
β”‚   β”‚   β”œβ”€β”€ users/        # User management
β”‚   β”‚   β”œβ”€β”€ devices/      # Device & switch control
β”‚   β”‚   └── prisma/       # Prisma service
β”‚   └── README.md
β”œβ”€β”€ app/                   # Angular + Ionic frontend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”‚   β”œβ”€β”€ services/ # API, auth, switch services
β”‚   β”‚   β”‚   β”œβ”€β”€ guards/   # Route guards
β”‚   β”‚   β”‚   └── pages/    # UI pages/components
β”‚   β”‚   └── environments/
β”‚   β”œβ”€β”€ android/          # Android platform
β”‚   β”œβ”€β”€ ios/              # iOS platform
β”‚   └── README.md
β”œβ”€β”€ esp32/                 # ESP32 firmware
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ main.cpp      # Main firmware code
β”‚   β”‚   └── config.h      # Configuration
β”‚   β”œβ”€β”€ platformio.ini    # PlatformIO config
β”‚   └── README.md
└── README.md              # This file

πŸ”§ Development Workflow

  1. Backend first: Set up database, run migrations, seed data
  2. Test API: Use Postman/curl to test endpoints
  3. Frontend: Connect to backend, test auth flow
  4. ESP32: Configure device credentials, test polling
  5. Integration: Complete end-to-end flow

πŸ“‹ Platform Support

Feature Web Android iOS
Auth & Manual Control βœ… βœ… βœ…
GPS Auto-Unlock ❌ βœ… βœ…
WiFi Auto-Unlock ❌ βœ… ⚠️ Limited
Notifications ❌ βœ… βœ…
Admin Dashboard βœ… βœ… βœ…

πŸ› Troubleshooting

Backend won't start:

  • Check PostgreSQL is running
  • Verify DATABASE_URL in .env
  • Run migrations: npm run migrate

Frontend can't connect:

  • Check apiUrl in environment files
  • Ensure backend is running
  • Verify CORS settings in backend

ESP32 not polling:

  • Check WiFi credentials
  • Verify SERVER_URL is reachable from ESP32 network
  • Check device_key matches database
  • View serial monitor for errors

GPS/WiFi not working:

  • Mobile only feature (won't work on web)
  • Check platform permissions granted
  • iOS requires special entitlements for WiFi SSID

🚒 Production Deployment

Backend

  • Deploy to cloud (Heroku, AWS, DigitalOcean)
  • Use managed PostgreSQL
  • Enable HTTPS
  • Set strong JWT secrets
  • Configure CORS for frontend URL

Frontend

  • Web: Build and deploy to static hosting (Netlify, Vercel)
  • Android: Build APK/AAB, upload to Play Store
  • iOS: Archive in Xcode, upload to App Store

ESP32

  • Use production server URL (HTTPS recommended)
  • Store device credentials securely
  • Add watchdog timer
  • Use reliable power supply
  • Replace LED with actual relay for elevator control

πŸ“„ License

MIT

🀝 Support

For issues or questions:

  1. Check component-specific READMEs (backend/, app/, esp32/)
  2. Review troubleshooting sections
  3. Check serial monitor output (ESP32)
  4. Verify network connectivity between components

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages