# ESP32 Smart Dashboard

A production-quality **Laravel 12** admin dashboard for controlling an **ESP32** device over HTTPS.

## ✨ Features

| Area | Details |
|------|---------|
| Authentication | Single admin account, bcrypt hashed, session-based |
| Dashboard | Live device status: last seen, IP, WiFi strength, firmware |
| Device Page | All display settings with live preview of API JSON |
| Settings | Admin password change with strength meter |
| REST API | `GET /api/device` returns JSON config for ESP32 |
| Heartbeat | `POST /api/device/heartbeat` lets ESP32 push its status |
| Design | Dark mode, Apple-inspired, Bootstrap 5.3, Inter font |

## 🚀 Quick Start

### 1. Requirements
- PHP 8.2+
- MySQL 8.x (via XAMPP)
- Composer

### 2. Install & Configure

```bash
# Dependencies already installed if you're reading this
# Just configure .env:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=esp32_dashboard
DB_USERNAME=root
DB_PASSWORD=
```

### 3. Create Database & Run Migrations

```bash
# Create the database first (via phpMyAdmin or mysql CLI):
mysql -u root -e "CREATE DATABASE esp32_dashboard CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"

# Then run migrations + seeder:
php artisan migrate --seed
```

**OR** import the reference SQL directly:
```bash
mysql -u root esp32_dashboard < database/esp32_dashboard.sql
```

### 4. Start the Dev Server

```bash
php artisan serve
```

Visit **http://localhost:8000**

## 🔑 Default Admin Credentials

| Field | Value |
|-------|-------|
| Email | `admin@esp32.local` |
| Password | `Admin@1234` |

> **Change the password** immediately via Settings page after first login.

## 📡 API Reference

### GET `/api/device`

Returns the current device configuration as JSON:

```json
{
  "name": "Ebad",
  "goal": "Finish Laravel",
  "weather": "37°C",
  "quote": "Keep Learning",
  "brightness": 80,
  "animation": "happy",
  "refresh": 30
}
```

### POST `/api/device/heartbeat`

Allows the ESP32 to report its status:

```json
{
  "ip": "192.168.1.100",
  "wifi_strength": -65,
  "firmware_version": "v1.2.0"
}
```

## 🗂 Project Structure

```
app/
├── Http/Controllers/
│   ├── Auth/LoginController.php
│   ├── DashboardController.php
│   ├── DeviceController.php
│   ├── SettingsController.php
│   └── Api/DeviceApiController.php
└── Models/
    ├── User.php
    └── Device.php

database/
├── migrations/
│   ├── 0001_01_01_000000_create_users_table.php
│   ├── 0001_01_01_000001_create_cache_table.php
│   ├── 0001_01_01_000002_create_jobs_table.php
│   └── 2025_01_01_000010_create_devices_table.php
├── seeders/DatabaseSeeder.php
└── esp32_dashboard.sql   ← reference SQL

resources/views/
├── layouts/app.blade.php
├── auth/login.blade.php
├── dashboard/index.blade.php
├── device/index.blade.php
└── settings/index.blade.php

routes/
├── web.php   ← login, dashboard, device, settings, logout
└── api.php   ← GET /api/device, POST /api/device/heartbeat
```

## 🌐 Shared Hosting Deployment

1. Upload all files **except** `node_modules/` and the root `vendor/` folder
2. Run `composer install --no-dev --optimize-autoloader` on the server
3. Point your domain's document root to the `/public` directory
4. Copy `.env.example` to `.env` and set production credentials
5. Run `php artisan key:generate` and `php artisan migrate --seed`

## 🔒 Security Notes

- CSRF protection is active on all web forms
- API routes use Laravel's `api` middleware (rate-limited)
- Session uses file driver (works on shared hosting without Redis)
- All user input is validated with Laravel's validator
- Passwords are hashed with bcrypt (12 rounds)
