Creating a Wifi Access Point

In a previous post we saw how to connect to a wireless network to ssh into a linux board and control it headlessly. This presents the obvious advantage of not needing to setup a screen and keyboard, which is not necessarily a given in every board anyway, but also has a few drawbacks, such as not knowing in advance the IP address and having to perform a network scan to find it, or not being able to log in in a place without wifi.

nanoPiAP

To solve this problem while retaining the benefits of ssh-ing, an Access Point (AP) could be set up. This way the board would create its own wireless network to which we could connect, and since we can control every aspect of the system it would be simple matter of assigning a known static IP address to which to connect directly. This of course has the disadvantage of not being able to connect to the Internet but files needed can be transferred over scp or downloaded before creating the AP.

The modified files will follow this structure:

tree

The first thing to do while we’re still connected to the Internet is to install hostapd and udhcpd in the embedded board:

sudo apt-get install hostapd udhcpd

We’re going to set up hostapd to create the network and udhcpd to manage IP addresses.

Hostapd

First we modify (or create) the file to contain the following parameters to create the AP. We will then change SSID and WPA_PASSPHRASE to reflect our chosen name and password.

Once the network is defined we tell the program where the configuration file is located.

Udhcpd

We now configure DHCP, taking care to modify the following lines:

This time instead of giving the location to the file we just comment the first parameter to enable it.

Interfaces

Since in the previous tutorial we set up the board to automatically connect to a network we must now adapt the file to its new behaviour.

Once all the files have been updated we reboot the board and the new network should appear,  making it now possible to log in headlessly anywhere.

However we will probably want to connect to the internet to download packages in the future, so instead of going through all the hassle of modifying the files each time I wrote the script toggleWifiMode.py to toggle between AP and regular client automatically.

To execute it simply write

sudo python toggleWifiMode.py

This will create the files and restart the board to apply the changes. Happy hacking!

github
https://github.com/alvaroferran/WifiAP

Leave a Reply

Your email address will not be published. Required fields are marked *