The Discount Mars Rover Project

STEP 11: ESTABLISHING A WIFI CONNECTION

We need to find a way to communicate with our rover. Instead of using NASAs Deeps Space Network to communicate with Mars we will use a much more cost effective solution: WIFI. Please keep in mind that this still the Discount Mars Rover Project.

Which parts do I need?

For this step no new parts are required. 

Set Up WiFi Access Point

Make sure your Raspberry Pi is connected to the Internet. Open a terminal window (either in a console window or over a serial/SSH connection). Install Packages To install the required packages, enter the following into the console:

sudo apt-get -y install hostapd dnsmasq

Hostapd is a program that allows you to use the WiFi radio as an access point, and Dnsmasq is a lightweight combination of DHCP and DNS services (handing out IP addresses and translating domain names into IP addresses). Since the configuration files are not ready yet, turn the new software off as follows:

sudo systemctl stop dnsmasq
sudo systemctl stop hostapd

Configuring a static IP

We are configuring a standalone network to act as a server, so the Raspberry Pi needs to have a static IP address assigned to the wireless port. This documentation assumes that we are using the standard 10.11.12.x IP addresses for our wireless network, so we will assign the server the IP address 10.11.12.1. It is also assumed that the wireless device being used is wlan0. To configure the static IP address, edit the dhcpcd configuration file with:

sudo nano /etc/dhcpcd.conf

Go to the end of the file and edit it so that it looks like the following:

interface wlan0
    static ip_address=10.11.12.1/24
    nohook wpa_supplicant

Now restart the dhcpcd daemon and set up the new wlan0 configuration:

sudo service dhcpcd restart

Configuring the DHCP server (dnsmasq)

The DHCP service is provided by dnsmasq. By default, the configuration file contains a lot of information that is not needed, and it is easier to start from scratch. Rename this configuration file, and edit a new one:

sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig
sudo nano /etc/dnsmasq.conf

Type or copy the following information into the dnsmasq configuration file and save it:

interface=wlan0      # Use the require wireless interface - usually wlan0
dhcp-range=10.11.12.2,10.11.12.50,255.255.255.0,24h

So for wlan0, we are going to provide IP addresses between 10.11.12.2 and 10.11.12.50, with a lease time of 24 hours. If you are providing DHCP services for other network devices (e.g. eth0), you could add more sections with the appropriate interface header, with the range of addresses you intend to provide to that interface. Reload dnsmasq to use the updated configuration:

sudo systemctl reload dnsmasq

Configuring the access point host software (hostapd)

You need to edit the hostapd configuration file, located at /etc/hostapd/hostapd.conf, to add the various parameters for your wireless network. After initial install, this will be a new/empty file.

sudo nano /etc/hostapd/hostapd.conf

Add the information below to the configuration file. This configuration assumes we are using channel 7, with a network name "marsrover", and a password "wegotomars". Note that the name and password should not have quotes around them.


interface=wlan0
driver=nl80211
ssid=marsrover
hw_mode=g
channel=7
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=wegotomars
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

We now need to tell the system where to find this configuration file.

sudo nano /etc/default/hostapd

Find the line with #DAEMON_CONF, and replace it with this:

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

Start it up. Now enable and start hostapd:

sudo systemctl unmask hostapd
sudo systemctl enable hostapd
sudo systemctl start hostapd

Do a quick check of their status to ensure they are active and running:

sudo systemctl status hostapd
sudo systemctl status dnsmasq

Go to any computer in your network and check if the connection is up and running with:

ping 10.11.12.1