Using the WiFi Access Point
Connecting through a Captured Portal
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.
After reading this guide, you may be interested in reading:
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.
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.
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
Time to find out what SSIDs are nearby and available. The easy command is
nmcli dev wifi which outputs a table similar to:
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.
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.
Once you have a connection, connecting and disconnection are easy.
sudo nmcli con up connection_name
sudo nmcli con down connection_name
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.
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.
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 126.96.36.199 and 188.8.131.52 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.
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.