> For the complete documentation index, see [llms.txt](https://dronesim.gitbook.io/dronesim-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dronesim.gitbook.io/dronesim-docs/development-tutorials/forwarding-mavlink-packets.md).

# Forwarding MAVLink packets

Forwarding MAVLink Packets Using MAVProxy and MAVLink Router

MAVLink (Micro Air Vehicle Link) is a lightweight communication protocol used in various unmanned systems, including drones. It enables communication between different components like ground control stations (GCS), autopilots, and onboard computers. For some setups, there’s a need to forward MAVLink packets across multiple networks or interfaces to achieve smooth communication between these components. One of the most effective ways to accomplish this is by using tools like **MAVLink Router** and **MAVProxy**.

In this blog post, we’ll explain how to forward MAVLink packets using **MAVLink Router** and **MAVProxy**, provide configuration examples, and guide you through typical use cases.

***

#### Why Forward MAVLink Packets?

Forwarding MAVLink packets is necessary when you want to:

* Send telemetry data from a drone to multiple ground control stations (GCS).
* Relay MAVLink data across different communication mediums (e.g., serial, UDP, TCP).
* Enhance the scalability of your system by allowing multiple devices to communicate with the same autopilot.
* Debug and monitor MAVLink messages without disturbing the primary connection.

***

#### What is MAVLink Router?

**MAVLink Router** is a tool designed to route MAVLink messages between different communication interfaces. It supports multiple endpoints (UDP, TCP, and serial connections), which makes it a great option for forwarding MAVLink packets between devices. MAVLink Router is efficient and lightweight, making it ideal for embedded systems like companion computers running on drones.

#### Installing MAVLink Router

First, you need to install MAVLink Router on your system. For Linux-based systems (like Ubuntu), you can follow these steps:

```bash
sudo apt-get install git
git clone https://github.com/mavlink-router/mavlink-router.git
cd mavlink-router
git submodule update --init --recursive
meson setup build .
ninja -C build
sudo ninja -C build install
```

Once installed, you can begin forwarding MAVLink packets.

#### Example: Forwarding MAVLink Packets with MAVLink Router

Let’s consider an example where you want to forward MAVLink packets from a serial device (like `/dev/ttyUSB0` on your drone) to multiple ground stations using UDP.

You can achieve this with MAVLink Router using the following command:

```bash
mavlink-routerd /dev/ttyUSB0:115200 --endpoint 192.168.1.100:14550 --endpoint 192.168.1.101:14550
```

Explanation of the command:

* `/dev/ttyUSB0:115200`: The serial device and baud rate of the MAVLink telemetry from the drone’s flight controller.
* `--endpoint 192.168.1.100:14550`: This is the IP address and port of the first ground station where you want to forward MAVLink packets.
* `--endpoint 192.168.1.101:14550`: The second ground station.

This setup will read MAVLink data from `/dev/ttyUSB0` and forward it to both ground stations (192.168.1.100 and 192.168.1.101).

#### Configuration Using a .conf File

You can also use a configuration file to define endpoints and interfaces in a more organized manner.

Create a config file, `mavlink-router.conf`, with the following content:

```ini
[General]
# Logs are disabled by default. Enable them if you want to keep track of the packets.
Log=/var/log/mavlink-router

[UartEndpoint uart]
Device=/dev/ttyUSB0
Baud=115200

[UdpEndpoint gcs1]
Address=192.168.1.100
Port=14550

[UdpEndpoint gcs2]
Address=192.168.1.101
Port=14550
```

Then, run MAVLink Router with the config file:

```bash
mavlink-routerd -c mavlink-router.conf
```

***

#### What is MAVProxy?

**MAVProxy** is another powerful MAVLink ground control station and development tool. It can act as a proxy to forward packets between interfaces, allowing you to monitor and manipulate MAVLink messages. MAVProxy is often used for testing, debugging, and creating custom GCS applications.

#### Example: Forwarding MAVLink Packets with MAVProxy

In a scenario where you have a telemetry link over a serial connection, you can use MAVProxy to forward data to a UDP endpoint.

First, install MAVProxy:

```bash
sudo pip install mavproxy
```

To start forwarding MAVLink packets from a serial device (`/dev/ttyUSB0`) to a UDP port (`192.168.1.100:14550`), run the following command:

```bash
mavproxy.py --master=/dev/ttyUSB0 --out=udp:192.168.1.100:14550
```

Explanation of the command:

* `--master=/dev/ttyUSB0`: The serial device connected to the drone.
* `--out=udp:192.168.1.100:14550`: The IP address and port of the ground station where the packets will be forwarded.

#### Additional MAVProxy Commands

MAVProxy allows you to add multiple outputs if you need to forward data to several endpoints. For example:

```bash
mavproxy.py --master=/dev/ttyUSB0 --out=udp:192.168.1.100:14550 --out=udp:192.168.1.101:14550
```

You can also view MAVLink messages in real-time using MAVProxy:

```bash
mavproxy.py --master=/dev/ttyUSB0 --console
```

The `--console` option opens a real-time console to visualize incoming MAVLink messages.

***

***

####

Hopefully, this guide helps you set up MAVLink packet forwarding in your own projects. Happy flying!

***

**References**:

* MAVLink Router GitHub Repository: [MAVLink Router](https://github.com/mavlink-router/mavlink-router)
* MAVProxy Documentation: [MAVProxy](https://ardupilot.github.io/MAVProxy/)
