Configuring your Onboard Computer as a WiFi Access Point

In the field, the easiest way to make a connection between the vehicle and QGroundControl is making the vehicle the WiFi Access Point (or Hot Spot). You would then use your laptop/tablet running QGroundControl to connect to it. Once connected to the vehicle WiFi, it receives an address automatically and communication between vehicle and QGroundControl can be established. This obviously assumes you have an USB WiFi adapter connected to the Onboard Computer and that this USB WiFi adapter supports Access Point mode.

As the Video Streaming page suggests, this assumes you have the Onboard Computer already loaded with an appropriate Debian based distribution (Raspbian on the Raspberry PI, Ubuntu for Odroid, etc.) and already configured for Ethernet communications with your ground station computer. Alternatively, you can boot the Onboard Computer with a monitor and keyboard and work directly with it.

It also assumes you have a USB WiFi adapter named wlan0. Change all occurrences of wlan0 to the appropriate interface if different (e.g. wlan1). There is no need to configure the WiFi as we will be configuring it as an Access Point below. The examples below show how to setup a USB WiFi dongle based on the Ralink Technology, Corp. RT2870/RT3070 or the Atheros Communications, Inc. AR9271 chipsets, both of which work right out of the box.

Confirmed to work:

  • TP-Link TL-WN722N
  • Edimax EW-7711USN
  • Kasens G9000

Turning the vehicle's Onboard Computer into an Access Point

For a more in depth explanation, you can look at RPI-Wireless-Hotspot

1. Install the necessary software

sudo apt-get install hostapd udhcpd

2. Configure DHCP. Edit the file /etc/udhcpd.conf and configure it like this:

start 192.168.2.100 # This is the range of IPs that the hostspot will give to client devices.
end 192.168.2.200
interface wlan0 # The device uDHCP listens on.
remaining yes
opt dns 8.8.8.8 4.2.2.2 # The DNS servers client devices will use (if routing through the ethernet link).
opt subnet 255.255.255.0
opt router 192.168.2.1 # The Onboard Computer's IP address on wlan0 which we will set up shortly.
opt lease 864000 # 10 day DHCP lease time in seconds

All other “opt” entries should be disabled or configured properly if you know what you are doing.

Edit the file /etc/default/udhcpd and change the line:

DHCPD_ENABLED="no"

to

#DHCPD_ENABLED=“no"

You will need to give the Onboard Computer a static IP address. Edit the file /etc/network/interfaces and replace the line “iface wlan0 inet dhcp” (or “iface wlan0 inet manual”) to:

iface wlan0 inet static
address 192.168.2.1
netmask 255.255.255.0
wireless-power off

The above is enough for the Raspbian (Raspberry PI). Ubuntu requires a bit more:

auto wlan0
iface wlan0 inet static
address 192.168.2.1
netmask 255.255.255.0
network 192.168.2.0
broadcast 192.168.2.255
wireless-power off

If the line “iface wlan0 inet dhcp/manual” is not present, add the above lines to the bottom of the file.

Let’s disable the original (WiFi Client) auto configuration. Change the lines (they probably won't all be next to each other or may not even be there at all):

allow-hotplug wlan0
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp

to:

#allow-hotplug wlan0
#wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
#iface default inet dhcp

3. Configure HostAPD

To create a WPA-secured network, edit the file /etc/hostapd/hostapd.conf (create it if it doesn't exist) and add the following lines:

auth_algs=1
channel=11            # Channel to use
hw_mode=g
ieee80211n=1          # 802.11n assuming your device supports it
ignore_broadcast_ssid=0
interface=wlan0
macaddr_acl=0
rsn_pairwise=CCMP
wpa=2
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
# Change the to the proper driver
driver=nl80211
# Change these to something else if you want
ssid=PixhawkPX4
wpa_passphrase=QGroundControl

Change ssid=, channel=, and wpa_passphrase= to values of your choice. SSID is the hotspot's name which is broadcast to other devices, channel is what frequency the hotspot will run on, wpa_passphrase is the password for the wireless network. For many more options see the file /usr/share/doc/hostapd/examples/hostapd.conf.gz

Look for a channel that is not in use in the area. You can use tools such as wavemon for that.

Edit the file /etc/default/hostapd and change the line:

#DAEMON_CONF=""

to:

DAEMON_CONF="/etc/hostapd/hostapd.conf"

Your Onboard Computer should now be hosting a wireless hotspot. To get the hotspot to start on boot, run these additional commands:

sudo update-rc.d hostapd enable
sudo update-rc.d udhcpd enable

This is enough to have the Onboard Computer present itself as an Access Point and allow your ground station to connect. If you truly want to make it work as a real Access Point (routing the WiFi traffic to the Onboard Computer’s ethernet connection), we need to configure the routing and network address translation (NAT).

First, enable IP forwarding in the kernel:

sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"

Second, to enable NAT in the kernel, run the following commands:

sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT

To make this permanent, run the following command:

sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"

Now edit the file /etc/network/interfaces and add the following line to the bottom of the file:

up iptables-restore < /etc/iptables.ipv4.nat

Note on the RTL8192CU USB WiFi Adapter

WARNING: As of this writing, the RTL8192CU drivers do not work properly. The instructions below will allow the Access Point to work but it is too unreliable. Until a proper Linux driver is made available, I suggest using a different chipset. So far, I've only had success with the Ralink RT2870/RT3070 and the Atheros AR9271 chipsets as described above. I'm still investigating other options.

The tricky part here is the USB WiFi Driver. Not all behave (or even support) when used as an Access Point. The example above assumes you are using the RT2870/RT3070 or the Atheros AR9271 chipsets. To find out what type of adapter you have, type:

lsusb

You will see a list of all USB devices connected to the Onboard Computer. The list will look something like:

Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 0bda:8178 Realtek Semiconductor Corp. RTL8192CU 802.11n WLAN Adapter
Bus 001 Device 005: ID 046d:082d Logitech, Inc.

As RTL8192CU has poor support in current kernels, some Linux distributions use realtek-provided drivers which do not work with stock hostapd. See this GitHub project for detailed instructions on how to build the necessary binaries from sources.

The basics are:

1. Remove non functional hostapd installed above

sudo apt-get remove hostapd

2. Build new one

cd
mkdir hostapd
cd hostapd
sudo apt-get install git build-essential fakeroot devscripts debhelper libnl-dev libssl-dev
git clone https://github.com/jekader/hostapd-rtl.git
cd hostapd-rtl
bash build.sh

3. Install newly built hostapd.

Note that it might ask you what to do with the configuration files already found in the system (as we created above). Respond “N” for each question to keep the configuration we already created.

sudo dpkg -i ../hostapd-rtl_2.4-4_armhf.deb
Translations of this page:


Quick Links

QR Code: URL of current page