Skip to main content

5.1.1 PX4 Network & Serial

PX4 Ethernet

Ethernet connections offer a faster, more reliable, and more flexible communications alternative than using USB or other serial connections.

It can be used to connect to ground stations, companion computers, and other MAVLink systems. It is particularly recommended for connecting to systems that use Ethernet "natively" (such as IP radios).

PX4 uses the netman module to apply and update network settings.

The default configuration will first request an IP address from DHCP, and if that fails, will fall back to the default static address 10.41.10.2. You can explicitly set any static IP address (including the default address) to bypass the initial DHCP check, which will speed up the connection.

The network settings are defined in a configuration file on the SD card /fs/microsd/net.cfg. This is a text file with one setting per line, and each setting corresponds to a name=value configuration file. A configuration file might look like this:

DEVICE=eth0
BOOTPROTO=fallback
IPADDR=10.41.10.2
NETMASK=255.255.255.0
ROUTER=10.41.10.254
DNS=10.41.10.254

The values are:

  • DEVICE: Interface name. Defaults to eth0.
  • BOOTPROTO: Protocol for obtaining the PX4 IP address. Valid values for proto are: dhcp, static, fallback (use DHCP, but if that fails, revert to a static address after a while)
  • IPADDR: Static IP address ( static used if BOOTPROTO is or fallback)
  • NETMASK:Network mask
  • ROUTER: The address of the default route.
  • DNS: DNS server address.

To set up the above "example" configuration using QGroundControl:

  1. Connect the flight controller to your computer using a USB cable.
  2. Open QGroundcontrol > Analysis Tools > MAVLink Console
  3. Enter a command similar to the following in the MAVLink console (to write the value to the configuration file):
    echo DEVICE=eth0 > /fs/microsd/net.cfg
    echo BOOTPROTO=fallback >> /fs/microsd/net.cfg
    echo IPADDR=10.41.10.2 >> /fs/microsd/net.cfg
    echo NETMASK=255.255.255.0 >>/fs/microsd/net.cfg
    echo ROUTER=10.41.10.254 >>/fs/microsd/net.cfg
    echo DNS=10.41.10.254 >>/fs/microsd/net.cfg
  4. Once the network configuration is set up, you can disconnect the USB cable.
  5. Restart the flight controller to apply the settings.

Note that the above settings already provide an Ethernet address for the flight controller. You will also need to configure the Ethernet port to use MAVLink.

The Ethernet port configuration sets the properties of the serial link (i.e. how PX4 sees the Ethernet connection). This includes the MAVLink message set that is streamed, the data rate, the UDP port that remote systems can connect to and listen on, etc.

Configure the PX4 serial port to connect to the GCS via MAVLink, using the parameters shown below:

scopevaluedescribe
MAV_2_CONFIG1000Configuring Ethernet Ports
MAV_2_BROADCAST1Broadcast HEARTBEAT Message
MAV_2_MODE0Sending a "normal" MAVLink message set (i.e. GCS setup)
MAV_2_RADIO_CTL0Disable software restrictions for MAVLink traffic
MAV_2_RATE100000Maximum sending rate
MAV_2_REMOTE_PRT14550MAVLink remote port 14550 (GCS)
MAV_2_UDP_PRT14550MAVLink network port 14550 (GCS)

Typically, the companion computer will use the port 14540 (instead of 14550) and transmit the MAVLink message set specified in the configuration file Onboard. You can configure this by changing MAV_2_REMOTE_PRT and MAV_2_UDP_PRT to, 14540 and changing MAV_2_MODE 2 to (Onboard). However, please note that using the GCS configuration file will still work correctly.

For more information on MAVLink serial port configuration, see MAVLink Peripherals (GCS/OSD/Companion)