6. Install and setup mavlink-router

mavlink-router

What is mavlink-router?

Whether the flight controller communicates with the Raspberry Pi or the Raspberry Pi communicates with the ground station, they are all through mavlink.

When the Raspberry Pi receives the mavlink data from the flight controller via the serial port, the mavlink-router will distribute the mavlink data to other devices. (e.g. ground station, simulator or your computer visual program, etc.)

Install mavlink-router

Login to your raspberry pi, then:

If you didn’t install git, you may install it

sudo apt update
sudo apt install git

Download the source

git clone https://github.com/intel/mavlink-router.git
cd mavlink-router
git submodule update --init --recursive

Config it

./autogen.sh && ./configure CFLAGS='-g -O2' \
--sysconfdir=/etc --localstatedir=/var --libdir=/usr/lib64 \
--prefix=/usr

In my case, there are some warning echo but still works

Make

make
make install

If show ImportError: No module named 'future' when make
Install it by pip3 install future
If no pip3
Install it by sudo apt-get install python3-pip\

Create a config file

sudo mkdir /etc/mavlink-router
sudo pico main.conf

My config is:

[UartEndpoint rpi]
# Device = /dev/ttyAMA0
# Device = /dev/ttyS0
Device = /dev/serial0
Baud = 57600

It tells mavlink-router where is the serial port of the mavlink input. In my case, it is /dev/serial0

Please find the sample of config file here.

###Run The command below will read the mavlink data then forward it to the 192.168.1.100 port 14550 and localhost port 14550.

mavlink-routerd -e 192.168.1.100:14550 -e 127.0.0.1:14550

Connect the Ground Station

For example, your ground station is on 192.168.1.100, above mavlink-router command can let it receives the mavlink data from UDP port 14550. The QGroundControl will listen the UDP port 14550 by default, no need to config it. It is a sample below:

Auto start mavlink-router when system boot

Create the file below to /etc/mavlink-router.service

[Unit]
Description=MAVLink Router
Wants=zerotier-one.service
After=network-online.target zerotier-one.service

[Service]
Type=simple
ExecStart=/usr/bin/mavlink-routerd -e {groundstation}:14550
Restart=on-failure
RestartSec=3

[Install]
WantedBy=multi-user.target

Replace the {groundstation} to the IP of your ground station

Testing the service

sudo systemctl start mavlink-router.service

Enable the service

If the testing runs fine, we can enable the service.

sudo systemctl enable mavlink-router.service

Check the status

If you find the mavlink-router didn’t start up, you can check the status:

systemctl status mavlink-router.service

2 thoughts on “6. Install and setup mavlink-router”

  1. Hi, thank you for this guide. I am facing one problem: The connection between Pi and flight controller (FC) is inconsistent. On some occasions I am able to connect and get log messages and also send specific Mac commands. However on some random occasions the connection does not work. Generally this happens if I leave the Pi and the FC in powered on and idle state for about 15 mins. Once this happens then I need to keep restarting the Pi and FC several times to finally get it to work.
    I am using the following setup:
    FC – Pixhawk Cube Orange
    Firmware – Arducopter 4.0.7
    Pi – Pi zero W and Pi 4 (faces similar problems on both)
    Please let me know if you have come across such problem and can give me any indication on what may be the cause of this.
    Thank you.

    1. Hi Siddhesh,
      I didn’t face similar problems. How do you connect the drone with your Mac (the software config)?

Welcome your comments