Well, as the title here says, these scripts enable a Paspberry Pi to switch between station mode (connect to an access point) and Access Point mode (it is an access point) without needing to reboot the Pi.
Well let's say that you want to have a Pi embedded in a thing that has no interface for a user to configure it. You could have a button connected to the Pi that triggers it to switch to AP mode. Then the user can connect to it with their smartphone or whatever and browse to a webserver (that you provide separately!) hosted by the Pi. Or maybe you just want to be able to demo some network functionality when you're not in range of your home or office router.
Run this script as root. Use the -h flag to see usage info.
./setup_wlan_and_AP_modes.sh -s <station mode SSID> -p <station mode password> -a <AP mode SSID> -r <AP mode password>
By default, the Pi will boot into station mode. You can change this by including the -d flag when running this script.
After running this script, you should reboot your Pi.
You can run the switchToAP.sh
or switchToWlan.sh
scripts (as root) to do what they say.
Just rerun the setup_wlan_and_AP_modes.sh script with whatever you need!
But if you live in another country, you can still make this work for you! You only need to edit the country codes. This can be done in two ways: Edit the setup script before running it OR edit the wpa-supplicant files after running the setup script. Thanks to cl for reminding me of this limitation.
Simply search for the phrase country=US
and replace it with country=XX
where XX
is your two letter country code. There are two places where you must make this change.
As root, edit two files, both are in the /etc/wpa_supplicant/ directory:
-
wpa_supplicant-wlan0.conf
This file is used for configuration when the Pi is in station mode (connecting to an access point). As above, replace
country=US
with whatever is appropriate for you. -
wpa_supplicant-ap0.conf
This file is used for configuration when the Pi is in AP mode (acting as an access point). Just as with the other wpa_supplicant file, edit the contry code as appropriate.
That's just like, your opinion, man. I like using 192.168.4.1. But if you don't, that's ok. You can choose whatever IP address you want to use by either editing the script or editing a file after you run the script.
Simply search for the phrase 192.168.4.1
and replace it with your preferred IP address.
Same as the last option. Search this file for 192.168.4.1
and replace it with your preferred IP address.