Third party cookies may be stored when visiting this site. Please see the cookie information.

PenguinTutor YouTube Channel

Setting up the Raspberry Pi as a host wireless hotspot

This guide is how to turn a Raspberry Pi into a host Wireless WiFi hotspot. First what does that mean?

This will not turn your Pi into a wireless router (although you'd be half-way there), but instead provides a way to connect and control a Raspberry Pi using a dedicated wireless network. The reason I wanted this was to control my Raspberry Pi powered robot. Originally the Raspberry Pi robot was configured to connect to my existing home WiFi network, which worked great at home, but meant that if I took the robot out to show at a Raspberry Jam (such as PyCON UK Raspberry Jam in Coventry) then I would either need to take my wireless network with me, or find a wireless network at the event and reconfigure Raspbian to use the wireless network provided. This is similar to how the GoPro Hero 3 camcorders work.

Raspberry Pi Wireless Robot

This is based on the Raspbian image on the NOOBs SD card. This is easiest using a serial connector connecting to the GPIO ports, but can be done by switching between the keyboard and USB WiFi dongle when required or by using a USB hub.

In my case I used a USB serial connector on Linux and connected using
screen /dev/ttyUSB0 115200

First make sure your Raspbian distribution is up-to-date.

sudo apt-get update
sudo apt-get dist-upgrade

Check your wireless dongle supports AP mode (Access Point)

It's a good idea to check that the wireless dongle is able to support Access Point mode (WAP). Most do, but there are some dongles around that do not. This is not actually required if you know your dongle definitely supports this, but there is no harm in doing it anyway.

First install the iw utility which is used to query the wireless adapter.

sudo apt-get install iw

List the features of the wireless dongle
iw list

And check for an entry relating to AP mode:

        Supported interface modes:
                 * IBSS
                 * managed
                 * AP
                 * AP/VLAN
                 * WDS
                 * monitor
                 * mesh point

If this scrolls off the screen too fast you can view it through less using
iw list | less
use the cursors to move around and press q when complete.

Set Raspberry Pi to use static P address

We are going to use one of the reserved IP address ranges, but avoiding the more common ranges so that it is possible to control the robot from a computer with two interfaces. We will therefore use the network 10.5.5.0 and set the IP address of the Raspberry Pi to 10.5.5.1

Edit the interfaces file
sudo nano /etc/network/interfaces

Remove the dhcp entry
iface default inet dhcp

and instead add the lines below

iface wlan0 inet static
        address 10.5.5.1
        netmask 255.255.255.0

This configures the Raspberry Pi with a static IP address.

Add access point and DHCP server software

Assuming the dongle supports wireless mode we can proceed to adding the relevant software. We will be using hostapd to provide the access point function and adding a DHCP server isc-dhcp-server which will give out IP addresses to devices that connect.

sudo apt-get install hostapd isc-dhcp-server

You will get an error saying unable to start the dhcp server. This is because we have not yet configured the server, don't worry once it is all configured you shouldn't get that message any more.

Configuring the DHCP server

Now we will configure the dhcp server so it is ready when we configure the access point.

Edit the /etc/dhcp/dhcpd.conf file - eg.
sudo nano /etc/dhcp/dhcpd.conf

Comment out the domain name servers as we don't need them for this set-up. They can be commented out by adding a hash character at the start of each line.

#option domain-name "example.org";
#option domain-name-servers ns1.example.org, ns2.example.org;

Make the authoritative by un-commenting (removing the # character) entry:

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
authoritative;

Edit the section titled

# A slightly different configuration for an internal subnet.

I have created a large subnet (254 addresses, but set it so it can give out 50 entries) this is far more than we need for this.

# A slightly different configuration for an internal subnet.
subnet 10.5.5.0 netmask 255.255.255.0 {
  range 10.5.5.100 10.5.5.150;
  option routers 10.5.5.1;
  option broadcast-address 10.5.5.255;
  default-lease-time 600;
  max-lease-time 7200;
}

Now edit the default start script

sudo nano /etc/default/isc-dhcp-server

Change interfaces to
INTERFACES="wlan0"

The dhcp server is configured.

Configure the Raspberry Pi as a Wifi Access Point (WAP)

Now to configure the access point.

Create and edit a new file: /etc/hostapd/hostapd.conf

add the following, replacing <ssidname> and <passphrase> as appropriate

# Host access point config file 

# device name 
interface=wlan0

# Driver interface
driver=hostap

# SSID for the network
ssid=ssidname
# set appropriate country parameters (maybe required for regulatory reasons)
country_code=GB

# Operation mode - for 802.11n still use g to indicate using same band as g devices
hw_mode=g

# set channel - channel=0 for Automatic Channel Select
channel=0

# mac address access list - 0 = accept unless in deny
macaddr_acl=0

## add deny rules here if required
#deny_mac_file=/etc/hostapd/hostapd.deny

# Use shared key authentication
auth_algs=1

# Enable WPA2
wpa=2

# set passphrase
wpa_passphrase=passphrase

# Use WPA PSK
wpa_key_mgmt=WPA-PSK

# Pairwise cipher for WPA (v1) 
wpa_pairwise=TKIP 
# Pairwise cipher for RSN/WPA2 
rsn_pairwise=CCMP

Finally edit the default startup file for hostapd

sudo nano /etc/default/hostapd

Add entry

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

Testing

Now reboot the Raspberry Pi and you should be able to see the new wireless network on another device (eg. Mobile phone / tablet) and connect to it. You should then be able to ssh to the Raspberry Pi @10.5.5.1 If there is a problem then look at the appropriate section. For example if you cannot see the wireless network check the WAP settings, if you see the wireless network, but you don't get an IP address then check the DHCP settings etc.