The Ultimate Guide to MAVSDK-Python Programming [Part 3]: Building the MAVSDK Server for Remote Communication
Hello again, university students and researchers dedicating yourselves to autonomous flight control and drone application development! Welcome back.
Up until our last session, we familiarized ourselves with the basic concepts of MAVSDK-Python and executed a simple warm-up code to make a drone take off in a local environment. However, let’s imagine a real-world lab environment or a field test scenario. Heavy 3D simulators (like Gazebo or ROS) or the actual PX4 Flight Controller (FC) are typically running on a high-performance Linux PC or a companion computer embedded within the drone. Meanwhile, the environment where you actually write and execute your control code is highly likely to be a Windows laptop or a separate workstation.
So, when the “computer housing the drone (or simulator)” and the “computer running the Python code” are different, how should we establish communication between them?
In this [Part 3: Building the MAVSDK Server for Remote Communication], we will thoroughly explore the professional process of manually building and linking the ‘MAVSDK Server’—the backbone of communication—to perfectly configure this remote control architecture.
1. Why Do We Need the MAVSDK Server? (Understanding the Architecture)
A crucial concept to grasp is that MAVSDK-Python scripts do not communicate directly with the drone (PX4) via UDP to issue commands. In the middle of this pipeline, there must always be a C++-based backend program called the MAVSDK Server to act as a bridge and relay communications.
By default, when you instantiate the System() class and run await drone.connect(), the Python library secretly runs this embedded mavsdk_server in the background for you.
However, to control a drone from a remote computer, you must manually configure the communication network following this structure:
- Your Laptop (Running the Python Script): Connects via your internal network to the gRPC port (50051) of the Linux PC (which is running the MAVSDK Server).
- Linux PC (MAVSDK Server + PX4 Simulator): The MAVSDK Server receives the gRPC commands from your Windows laptop, translates them into actual MAVLink commands, and communicates with the internal PX4 flight controller via UDP port (14540).

In other words, you need to have a “standalone MAVSDK Server” perpetually running on your Linux machine (the drone side) that is always ready to accept external connections. Let’s log into our Linux environment and build this server right now!
2. Building the MAVSDK Server from Scratch
This task must be performed on the Linux (Ubuntu) computer where the PX4 simulator or the actual drone is connected. Since the core server is written in C++, we will download the source code and compile (build) it manually.
1️⃣ Install Required Dependency Packages
First, open your terminal and install the essential C++ compilers and libraries, such as gRPC and Protocol Buffers (protobuf), which are required for the build. This process is laying the foundation for your communication infrastructure.
sudo apt update && sudo apt upgrade -y
sudo apt install -y cmake ninja-build g++ git \
protobuf-compiler libprotobuf-dev \
libgrpc++-dev libgrpc-dev \
libssl-dev curl unzip
2️⃣ Download the MAVSDK C++ Source Code
Once the dependencies are installed, download the core MAVSDK C++ source code from GitHub. You must include the --recursive option to ensure all submodules are downloaded without omission.
cd ~
git clone https://github.com/mavlink/MAVSDK.git --recursive
cd MAVSDK
3️⃣ CMake Configuration (Key Point!)
By default, the MAVSDK library is configured to build without the server feature. Therefore, we must explicitly enable the server functionality using the cmake command. Make absolutely sure that the -DBUILD_MAVSDK_SERVER=ON option is included.
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DBUILD_MAVSDK_SERVER=ON -Bbuild/default -S.
4️⃣ Execute Parallel Build
With the configuration complete, let’s proceed with the actual compilation. Since the source code is extensive, use the -j8 option (utilizing 8 CPU cores) to build it quickly in parallel. You can adjust this to -j4 depending on your computer’s specifications.
cmake --build build/default -j8
Please wait a few moments until the build reaches 100%. ☕
5️⃣ Verify and Move the Executable
When the build finishes successfully, an executable file will be generated. To make this file easily accessible from anywhere in your Linux system, copy it to the /usr/local/bin directory.
sudo cp ~/MAVSDK/build/default/src/mavsdk_server/src/mavsdk_server /usr/local/bin/
(Note: Ensure your path matches your cloned directory, such as ~/MAVSDK/ or ~/mavsdk/)
Now, type mavsdk_server -p 50051 in your terminal. If it runs without errors, you have perfectly constructed your standalone MAVSDK Server!
3. Pro Tip to Elevate Your Research: Auto-starting the Server (systemd Configuration)
Opening a Linux terminal and typing mavsdk_server every single time you want to run a drone experiment is incredibly tedious for researchers. By leveraging Linux’s daemon manager, systemd, you can configure the server to automatically run in the background every time the computer boots up. This step is optional but highly recommended.
Enter the following command in the terminal to create a new service file:
sudo nano /etc/systemd/system/mavsdk_server.service
When the editor opens, paste the exact contents below. (Note: You can leave User=$USER as is, or if you encounter errors, change it to your actual Linux login username.)
[Unit]
Description=MAVSDK Server
After=network.target
[Service]
ExecStart=/usr/local/bin/mavsdk_server -p 50051
Restart=always
User=$USER
[Install]
WantedBy=multi-user.target
Once you’re done, press Ctrl+O then Enter to save, and Ctrl+X to exit the editor. Then, run the following three lines of commands to register and activate the service in your system.
sudo systemctl daemon-reload
sudo systemctl enable mavsdk_server
sudo systemctl start mavsdk_server
Now, your Linux machine is ready 24/7, 365 days a year to accept external remote connections!
4. Connecting to the Drone Remotely Using Python
The server setup is completely finished. It is time to return to your Windows laptop (or external computer) and write the Python code.
The most critical part to pay attention to when writing this code is the connection configuration. Previously, we used drone.connect(system_address="udp://:14540"). However, for a remote connection, the MAVSDK Server is already handling the UDP communication locally. Therefore, your Python script only needs to connect to the server via gRPC.
Let’s write the example code below. You must change the IP address to the actual IP address of the Linux PC where the MAVSDK Server is installed.
import asyncio
from mavsdk import System
async def run():
# 💡 Core Concept: Connect to the remote server's gRPC port (50051)
# instead of launching the embedded mavsdk_server locally!
# Make sure to replace "172.21.77.220" with your Linux PC's IP address.
drone = System(mavsdk_server_address="172.21.77.220", port=50051)
# We omit the system_address parameter inside connect().
# (The server is already communicating on UDP 14540, so it detects it automatically)
print("Attempting to connect to the MAVSDK Server on the remote Linux PC...")
await drone.connect()
# Monitoring the drone's connection state in real-time
print("Waiting for a response from the drone (SITL)...")
async for state in drone.core.connection_state():
if state.is_connected:
print("✅ Congratulations! Successfully connected to the remote drone!")
break
# You can add your mission code here, such as Takeoff or fetching Telemetry data.
if __name__ == "__main__":
asyncio.run(run())
If the success message prints when you run the code, it means you have broken free from the physical constraints of simulators and communication bottlenecks, enabling seamless and flexible remote research!

If the connection fails or you encounter errors like Connection failed: Invalid connection URL, double-check your Linux PC’s firewall settings (ensure port 50051 is open) or verify that the IP address is correct.
Wrapping Up
In Part 3, we thoroughly covered the essential steps to build an advanced drone research environment: from manually building the MAVSDK Server for remote communication to setting up auto-start configurations (systemd), and finally, integrating it with your Python scripts.
You now possess the infrastructure to communicate flexibly with your drone, regardless of restrictive hardware setups. Congratulations on successfully conquering the massive hurdles of hardware, servers, and network configurations!
In our next session, [Part 4], we will explore the absolute core of MAVSDK programming in an easy yet profound way: understanding “asyncio”, the asynchronous syntax in Python that is an unavoidable mountain you must climb to fully control a drone programmatically.
If you get stuck or have any questions while following along, please don’t hesitate to leave a comment. I wish all you researchers a successful flight. Thank you!

Author: maponarooo, CEO of QUAD Drone Lab
Date: March 3, 2026
