Old post but I have not found the answer to this question anywhere else so I decided to post here my solution:
There is a tool named wpa_cli
= WPA command line client (https://www.systutorials.com/docs/linux/man/8-wpa_cli/
) which is easy to use and solves this problem. You can search all over the internet for usage tutorials, however changing between known wifi's (present in wpa_supplicant.conf) you can just just type wpa_cli
which will open its own command line interface and then type these commands in order:
+ your preferred interface
, wlan0 is the raspi's onboard default so type interface wlan0
(this step is actually needed in my case , in which my rpi 3B+ defaults to an interface called 'p2p-dev-wlan0'
for dunno reason, as presented here https://raspberrypi.stackexchange.com/q ... ed-network
or you can replace this step by calling wpa_cli -i wlan0
or your preffered interface (useful for commands without opening wpa_cli own's CLI)
, find the respective id of the network you want to connect and then type
+ the id of the network from previous step
eg. select_network 1
. Beware, you need to type network id, not name!
and you are good to go. A one line command to connect to your preffered network with name example_name
is, combining all together:
wpa_cli -i wlan0 select_network $(wpa_cli -i wlan0 list_networks | grep example_name | cut -f 1)
where you replace example_name
with the network you want to connect to.
(idea stolen from https://superuser.com/a/759153
P.s. Python users beware, How do I run a command with a pipe | in it ?
see --> https://stackoverflow.com/questions/678 ... -in-python