View on GitHub

Using the WiFi Access Point

Connecting through a Captured Portal

Using the WiFi Access Point

Connecting through a Captured Portal

Description

Now that you have a wifi access point, how do you use it? It can be used on your home network, a public hotspot, and a captured portal hotspot. This how-to assumes that you have a Raspberry Pi wifi access point as setup in the RPi Wifi Access Point Guide.

Next up?

After reading this guide, you may be interested in reading:

Overview

This how-to covers the use of nmcli to scan, connect to and disconnect from access points. It also describes how to accept agreements or log into hotspot captive portals. Finally there is a section on troubleshooting.

  1. Start the Access Point
  2. Connect to the pi.
  3. Scan for SSIDs.
  4. Add new connections.
  5. Connect and disconnect a connection.
  6. Install links.
  7. Use links with a captive portal.
  8. Connect and Test.
  9. Shutting down.
  10. Troubleshooting.
  11. Conclusion.

Procedures

Start the Access Point

Basically, just give the pi power and the access point will start up. I use a simple USB to mini-USB cable and connect it from my laptop to my pi but you could use a dedicated power cord or even a battery pack.

Connect to the Pi

Once the pi is started it should broadcast its SSID. This is the SSID you gave it in /etc/hostapd/hostapd.conf. Connect to this SSID and provide the password you set in that file. Once connected, your device has an IP address in the same subnet as the AP and the device is using the nameservers you selected in the /etc/hostapd/hostapd.conf. These IP address were assigned via DHCP.

Now SSH into the AP's shell using ssh user@hostname.local.

Scan for SSIDs

Time to find out what SSIDs are nearby and available. The easy command is nmcli dev wifi which outputs a table similar to:

X SSID MODE CHAN RATE SIGNAL BARS SECURITY
. ap1 Infra 1 16 Mbit/s 100 ▂▄▆█ WPA2
X ap2 Infra 6 54 Mbit/s 100 ▂▄▆█ WPA2
. ap3 Infra 8 54 Mbit/s 100 ▂▄▆█ WPA2
. ap4 Infra 6 16 Mbit/s 42 ▂▄__ WPA2

The table shows all nearby broadcasting SSIDs, their signal strength, and their security requirements. This table also shows that there is an active connection to ap2.

Add new connections

Check to see if you already have a connection to one of these SSIDs by nmcli con. This displays a tabled list of saved connections. It is best to name new connections according to the SSID for ease of use. If you need more details on a connection, try nmcli con connection_name show

If you have previously added a connection to your desired SSID, then proceed to the next step. I found adding new connections using sudo nmtui to be easiest. Choose Edit a connection and then Add. The prompts and fields to be completed should be self-explantory.

Connect and disconnect a connection

Once you have a connection, connecting and disconnection are easy.

  • sudo nmcli con up connection_name
  • sudo nmcli con down connection_name

Connect

Try opening a browser window to a well known web site. If this works you are connected to the Internet, otherwise; review the Troubleshooting section.

Shutting down

It is always a good idea to follow a defined shutdown procedure and not just pull the plug on everything.

  • On your pi, sudo nmcli con down connection_name.
  • On your pi, sudo shutdown now.
  • On you main device, close your SSH session.
  • Shutdown your main device.

Troubleshooting

I have encountered only a few problems using the above procedures. The main problem has to do with the hotspot blocking certain types of services.

  • Problem Able to connect from the pi but not from the main device.
    • Solution This is likely due to the hotspot preventing external DNS lookups. The pi DHCP server assigns the 8.8.8.8 and 8.8.4.4 nameservers to your main device when it connects. The easiest way to solve this is by editing the configuration file to include the hotspot assigned nameservers.
    • Find the hotspot DNS, nmcli con show connection_name | grep DNS
    • Using comments, disable the Google domain-name-servers and make the hotspot domain-name-servers active instead, sudo nano /etc/dhcp/dhcpd.conf.
    • Restart the DHCP service, sudo service isc-dhcp-server restart.
    • Disconnect and then reconnect your main device's wifi.
  • Question I want to connect to the hotspot and click through the captive portal page automatically.
    • Answer I may choose to do this in the future but for now, there is no consensus on how a captive portal works and how to have express users on the portal. If you are interested in writing Python as a solution, have a look at python-networkmanager.

Conclusion

Verifying Internet connectivity when connected with hotspots is still in flux. Much of this is done by the operating system for the user. Here, we must do some of this work ourselves. In the future, I may choose to script the captive portal interaction. These links will be helpful, Fedora git and Exploring NetworkManager, D-Bus, systemd, and Raspberry Pi.