Typescript frontend with FastAPI backend for drone control and telemetry monitoring.
This is a hybrid Next.js + Python app that provides a web-based drone control station. It uses Next.js as the frontend interface and FastAPI with MAVSDK as the API backend for drone communication.
- Real-time drone telemetry monitoring
- Web-based control interface
- MAVSDK integration for MAVLink communication
- Socket.io for real-time data streaming
- RESTful API endpoints for drone control
- Real-time GPS tracking with Google Maps integration
The Python/FastAPI server is mapped into to Next.js app under /api/
. The drone controller uses MAVSDK to communicate with drone systems via MAVLink protocol.
This is implemented using next.config.js
rewrites to map any request to /api/:path*
to the FastAPI server, which is hosted in the /api
folder.
On localhost, the rewrite will be made to the 127.0.0.1:5328
port, which is where the FastAPI server is running.
Before getting started, ensure you have the following installed on your Linux system:
- Node.js (v16 or higher) and pnpm
- Python 3.8+ and pip
- Git
- QGroundControl (for ground control station)
- PX4 SITL (for drone simulation)
# Install Node.js and pnpm
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs
npm install -g pnpm
# Install Python and pip (usually pre-installed)
sudo apt update
sudo apt install python3 python3-pip python3-venv
# Install Git
sudo apt install git
# Clone the repository
git clone <your-repo-url>
cd Control-station
# Create Python virtual environment
python3 -m venv venv
# Activate virtual environment
source venv/bin/activate
# Install Python dependencies
pip install -r requirements.txt
# Install Node.js dependencies
pnpm install
# Create a directory for MAVSDK server
mkdir -p ~/mavsdk
# Download MAVSDK server (replace with latest version)
cd ~/mavsdk
wget https://github.com/mavlink/MAVSDK/releases/download/v2.12.2/mavsdk_server_linux-x64-musl
chmod +x mavsdk_server_linux-x64-musl
# Create a symlink in your project directory
cd ~/Control-station
ln -sf ~/mavsdk/mavsdk_server_linux-x64-musl mavsdk_server
# OR copy it directly to your project
cp ~/mavsdk/mavsdk_server_linux-x64-musl ./mavsdk_server
chmod +x ./mavsdk_server
# Download QGroundControl AppImage
cd ~/Downloads
wget https://d176tv9ibo4jno.cloudfront.net/latest/QGroundControl.AppImage
chmod +x QGroundControl.AppImage
# Move to applications directory (optional)
sudo mv QGroundControl.AppImage /opt/
sudo ln -sf /opt/QGroundControl.AppImage /usr/local/bin/qgroundcontrol
# Now you can run QGroundControl from anywhere
qgroundcontrol
# Clone PX4 repository
cd ~
git clone https://github.com/PX4/PX4-Autopilot.git --recursive
cd PX4-Autopilot
# Install PX4 dependencies
bash ./Tools/setup/ubuntu.sh
# Build PX4 for simulation
make px4_sitl_default gazebo-classic
# Or build without Gazebo (lighter)
make px4_sitl_default
Follow these steps in order to run the complete system:
cd ~/PX4-Autopilot
make px4_sitl_default gazebo-classic
# Or without Gazebo (lighter, terminal-only)
make px4_sitl_default
Wait for the simulator to fully start (you'll see "INFO [commander] Ready for takeoff!")
cd ~/Control-station
./mavsdk_server -p 50051 udp://:14540
Note: The drone controller will automatically start MAVSDK server if needed.
qgroundcontrol
Configure QGroundControl:
- Go to Application Settings → Comm Links
- Create a new connection:
- Type: UDP
- Listening Port:
14540
- Target Host:
127.0.0.1
- Target Port:
14540
- Connect to the link
cd ~/Control-station
# Activate virtual environment
source venv/bin/activate
# Start the FastAPI server
python -m api.index
You should see:
INFO: Started server process
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:5328
cd ~/Control-station
# Start the development server
pnpm dev
You should see:
ready - started server on 0.0.0.0:3000
Open your web browser and navigate to:
- Frontend: http://localhost:3000
- API Documentation: http://localhost:5328/docs
The drone controller connects to port 14540 (standard drone simulation port) using the connection string udp://:14540
.
Option 1: Auto-Connect
- QGroundControl should automatically detect and connect to
localhost:14540
if you have PX4 SITL running
Option 2: Manual Connection
- Open QGroundControl
- Go to Application Settings → Comm Links
- Create a new connection with:
- Type: UDP
- Listening Port:
14540
- Target Host:
127.0.0.1
(localhost) - Target Port:
14540
GET /api/python
- Hello world endpointGET/POST /api/velocity
- Drone velocity dataGET/POST /api/battery
- Battery telemetryGET/POST /api/camera
- Camera feedPOST /api/rtl
- Return to launch command
# Error: ModuleNotFoundError: No module named 'api'
# Solution: Always run as module and ensure virtual environment is active
source venv/bin/activate
python -m api.index
# Error: mavsdk_server binary not found
# Solution: Download and make executable
wget https://github.com/mavlink/MAVSDK/releases/download/v2.12.2/mavsdk_server_linux-x64-musl
chmod +x mavsdk_server_linux-x64-musl
# Error: Port 5328 already in use
# Solution: Kill existing processes
sudo lsof -ti:5328 | xargs kill -9
sudo lsof -ti:3000 | xargs kill -9
# Error: Build failures or missing dependencies
# Solution: Clean build and reinstall dependencies
cd ~/PX4-Autopilot
make clean
make distclean
bash ./Tools/setup/ubuntu.sh
make px4_sitl_default
- Ensure PX4 SITL is running first
- Check that port 14540 is not blocked by firewall
- Try restarting QGroundControl
- Verify UDP connection settings
- Check that both frontend (port 3000) and backend (port 5328) are running
- Verify CORS settings in the API
- Check browser console for connection errors
# Monitor all processes
# Terminal 1: PX4 SITL
make px4_sitl_default
# Terminal 2: Python API (with auto-reload)
source venv/bin/activate
uvicorn api.index:socket_app --host 0.0.0.0 --port 5328 --reload
# Terminal 3: Next.js (with auto-reload)
pnpm dev
# Terminal 4: QGroundControl
qgroundcontrol
# Stop all processes
pkill -f "px4"
pkill -f "python -m api.index"
pkill -f "pnpm dev"
pkill -f "qgroundcontrol"
To learn more about the technologies used:
- Next.js Documentation - learn about Next.js features and API
- FastAPI Documentation - learn about FastAPI features and API
- MAVSDK Documentation - learn about MAVSDK drone communication
- MAVLink Protocol - drone communication protocol
- PX4 Documentation - PX4 autopilot documentation
- QGroundControl User Guide - ground control station documentation
You can check out the Next.js GitHub repository - your feedback and contributions are welcome!