Initial commit
This commit is contained in:
210
SETUP.md
Normal file
210
SETUP.md
Normal file
@@ -0,0 +1,210 @@
|
||||
# Quick Setup Guide
|
||||
|
||||
This guide will help you get the Drone Detection System up and running quickly.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
1. **Node.js 16+** and npm
|
||||
2. **PostgreSQL 12+**
|
||||
3. **Twilio Account** (for SMS alerts)
|
||||
|
||||
## Step-by-Step Setup
|
||||
|
||||
### 1. Install Dependencies
|
||||
|
||||
```bash
|
||||
# Install all dependencies (root, server, and client)
|
||||
npm run install:all
|
||||
```
|
||||
|
||||
### 2. Database Setup
|
||||
|
||||
#### Option A: Automatic Setup (Recommended)
|
||||
```bash
|
||||
# Make sure PostgreSQL is running
|
||||
# Create database
|
||||
createdb drone_detection
|
||||
|
||||
# Copy environment file and configure
|
||||
cd server
|
||||
cp .env.example .env
|
||||
# Edit .env with your database credentials and Twilio settings
|
||||
|
||||
# Run automated setup
|
||||
cd ..
|
||||
npm run db:setup
|
||||
```
|
||||
|
||||
#### Option B: Manual Setup
|
||||
```bash
|
||||
# Create PostgreSQL database
|
||||
createdb drone_detection
|
||||
|
||||
# Configure environment
|
||||
cd server
|
||||
cp .env.example .env
|
||||
# Edit the .env file with your settings
|
||||
|
||||
# Run database setup script
|
||||
node scripts/setup-database.js
|
||||
```
|
||||
|
||||
### 3. Environment Configuration
|
||||
|
||||
Edit `server/.env` with your settings:
|
||||
|
||||
```bash
|
||||
# Database
|
||||
DB_HOST=localhost
|
||||
DB_PORT=5432
|
||||
DB_NAME=drone_detection
|
||||
DB_USER=postgres
|
||||
DB_PASSWORD=your_password
|
||||
|
||||
# JWT Secret (generate a random string)
|
||||
JWT_SECRET=your-super-secret-jwt-key
|
||||
|
||||
# Twilio (get from https://console.twilio.com/)
|
||||
TWILIO_ACCOUNT_SID=ACxxxxxxxxxxxxxxxxxxxxx
|
||||
TWILIO_AUTH_TOKEN=your_auth_token
|
||||
TWILIO_PHONE_NUMBER=+1234567890
|
||||
|
||||
# Server
|
||||
PORT=3001
|
||||
NODE_ENV=development
|
||||
CORS_ORIGIN=http://localhost:3000
|
||||
```
|
||||
|
||||
### 4. Start the Application
|
||||
|
||||
```bash
|
||||
# Start both backend and frontend in development mode
|
||||
npm run dev
|
||||
```
|
||||
|
||||
Or start separately:
|
||||
```bash
|
||||
# Start backend (port 3001)
|
||||
npm run server:dev
|
||||
|
||||
# Start frontend (port 3000)
|
||||
npm run client:dev
|
||||
```
|
||||
|
||||
### 5. Access the Application
|
||||
|
||||
- **Frontend**: http://localhost:3000
|
||||
- **Backend API**: http://localhost:3001/api
|
||||
|
||||
### 6. Default Login Credentials
|
||||
|
||||
- **Admin**: `admin` / `admin123`
|
||||
- **Operator**: `operator` / `operator123`
|
||||
|
||||
## Testing the System
|
||||
|
||||
### 1. Test Drone Detection API
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:3001/api/detections \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"device_id": 1941875381,
|
||||
"geo_lat": 59.3293,
|
||||
"geo_lon": 18.0686,
|
||||
"device_timestamp": 1691755018,
|
||||
"drone_type": 0,
|
||||
"rssi": -45,
|
||||
"freq": 20,
|
||||
"drone_id": 2
|
||||
}'
|
||||
```
|
||||
|
||||
### 2. Test Heartbeat API
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:3001/api/heartbeat \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"type": "heartbeat",
|
||||
"key": "device_1941875381_key",
|
||||
"battery_level": 85,
|
||||
"signal_strength": -50,
|
||||
"temperature": 22.5
|
||||
}'
|
||||
```
|
||||
|
||||
## Common Issues
|
||||
|
||||
### Database Connection Issues
|
||||
- Ensure PostgreSQL is running
|
||||
- Check database credentials in `.env`
|
||||
- Verify database exists: `psql -l`
|
||||
|
||||
### Port Already in Use
|
||||
```bash
|
||||
# Find process using port 3001
|
||||
netstat -ano | findstr :3001
|
||||
# Kill process (Windows)
|
||||
taskkill /PID <PID> /F
|
||||
```
|
||||
|
||||
### Missing Dependencies
|
||||
```bash
|
||||
# Reinstall all dependencies
|
||||
npm run install:all
|
||||
```
|
||||
|
||||
### Twilio SMS Not Working
|
||||
- Verify Twilio credentials in `.env`
|
||||
- Check phone number format (+1234567890)
|
||||
- Ensure Twilio account has sufficient credits
|
||||
|
||||
## Docker Setup (Alternative)
|
||||
|
||||
If you prefer Docker:
|
||||
|
||||
```bash
|
||||
# Copy environment file
|
||||
cp server/.env.example server/.env
|
||||
# Edit server/.env with your settings
|
||||
|
||||
# Build and start with Docker
|
||||
npm run docker:up
|
||||
|
||||
# Stop services
|
||||
npm run docker:down
|
||||
```
|
||||
|
||||
## Production Deployment
|
||||
|
||||
For production deployment:
|
||||
|
||||
1. Set `NODE_ENV=production` in server/.env
|
||||
2. Build frontend: `npm run client:build`
|
||||
3. Use a reverse proxy (nginx) for the frontend
|
||||
4. Use PM2 or similar for process management
|
||||
5. Set up SSL certificates
|
||||
6. Configure proper database backup
|
||||
|
||||
## Next Steps
|
||||
|
||||
1. **Configure Alert Rules**: Log in and set up SMS alert rules
|
||||
2. **Add Devices**: Register your drone detection hardware
|
||||
3. **Test Real-time Features**: Check the dashboard for live updates
|
||||
4. **Customize Settings**: Modify alert conditions and user roles
|
||||
|
||||
## Getting Help
|
||||
|
||||
- Check the main README.md for detailed documentation
|
||||
- Review the API endpoints in the backend routes
|
||||
- Check browser console for frontend issues
|
||||
- Review server logs for backend issues
|
||||
|
||||
## Security Notes
|
||||
|
||||
- Change default passwords immediately
|
||||
- Use strong JWT secrets in production
|
||||
- Enable HTTPS in production
|
||||
- Regularly update dependencies
|
||||
- Monitor access logs
|
||||
Reference in New Issue
Block a user