This project makes it easier to connect a headless Raspberry Pi to a wifi network.
So, if I take my Pi to a new environment, it does the following:
- Looks in wpa_supplicant.conf for a password for all visible wifi networks in the room.
- Fails to find a suitable entry (because I have never been there before)
- Turns the Pi into a local server and wireless Access Point and broadcasts its SSID
On my phone, I:
- Connect to the Access Point
- Browse to 10.0.0.1
- Access the RaspiWifi page running on the Pi
- Select the room SSID
- Enter the password
The Pi then reboots and connects to the room SSID.
Sweet!
The problem is that the current code overwrites the wpa_supplicant.conf instead of appending to it.
So, when I get home, I have to repeat the whole process to reconnect, and will have to repeat again when I go back to the remote location.
I know just enough programming to brief a programmer, but not enough to actually do the work!
Can anyone help? @Kyle?
Here’s what I know:
“\RaspiWiFi-master\libs\configuration_app\app.py” lines 87 to 105 are responsible for creating the new wpa_supplicant.conf and overwriting the existing one.
There is a command line script (wpa_cli) which is native to RaspbianOS that allows one to programatically interact with the existing wpa_supplicant.conf - adding and deleting entries.
The manual for wpa_cli is here.
A forum post demonstrating its use is here
I just tried wpa_cli in interactive mode and it worked (added another wifi).
I guess one challenge would be knowing what network entry to add.
It appears that the command “add network” returns the numerical identifier of the next entry that should be added. That identifier would need to be used to construct the command line that actually enters the network credentials.
The changes to the RaspiWifi code seem relatively trivial:
Line 88 to 105 are replaced with (warning, PSEUDOCODE):
// return the numerical id of the next network to be added
wpa_cli add_network
// turn the returned id into a variable $ID
code here
// Enter a new entry for the wifi
wpa_cli set_network $ID ssid “$SSID”
wpa_cli set_network $ID psk “$PASSWORD” (this may have to be in HEX)
// Write to file
wpa_cli save_config