Files
drone-detector/SETUP.md
2025-09-15 20:49:46 +02:00

4.1 KiB

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

# Install all dependencies (root, server, and client)
npm run install:all

2. Database Setup

# 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

# 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:

# 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

# Start both backend and frontend in development mode
npm run dev

Or start separately:

# Start backend (port 3001)
npm run server:dev

# Start frontend (port 3000)
npm run client:dev

5. Access the Application

6. Default Login Credentials

  • Admin: admin / admin123
  • Operator: operator / operator123

Testing the System

1. Test Drone Detection API

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

curl -X POST http://localhost:3001/api/heartbeat \
  -H "Content-Type: application/json" \
  -d '{
    "type": "heartbeat",
    "key": "device_1941875381_key"
  }'

Common Issues

Database Connection Issues

  • Ensure PostgreSQL is running
  • Check database credentials in .env
  • Verify database exists: psql -l

Port Already in Use

# Find process using port 3001
netstat -ano | findstr :3001
# Kill process (Windows)
taskkill /PID <PID> /F

Missing Dependencies

# 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:

# 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