On a freshly imaged stretch lite (it would be the same on a regular stretch or jessie) I've set-up wpa_supplicant.conf
with 2 known wifi networks. After boot, the system selects one of the network specified in wpa_supplicant.conf
, but how do I select the other one from the command line (without editing wpa_supplicant.conf
of course!)?
Asked
Active
Viewed 2,909 times
2

calocedrus
- 601
- 9
- 12
-
Why? What are you attempting to achieve? – Milliways Jan 30 '18 at 08:50
-
Just chose one network over the other one. One of the SSID is my phone hotspot the other is a company's and requires a different password every 24hrs. – calocedrus Jan 31 '18 at 00:04
-
Related: https://raspberrypi.stackexchange.com/q/58304/63024 – calocedrus Jan 31 '18 at 01:22
-
See this for more thorough explanations: https://raspberrypi.stackexchange.com/questions/58304/how-to-set-wifi-network-priority – jshep321 Jul 10 '20 at 16:49
1 Answers
2
It is not AFAIK possible to select by SSID, but you can manually select with something like the following.
wpa_cli select_network 1
It is quite a while since I used this, but networks are identified by position in wpa_supplicant.conf
.
If you want to prefer one network setting priority is a better method.

Milliways
- 59,890
- 31
- 101
- 209
-
So the index 1 in
wpa_cli select_network 1
corresponds to the order of my networks in wpa_supplicant.conf? I'll try this soon. – calocedrus Jan 31 '18 at 00:07 -
Feedbacks on your answer: (1)
wpa_cli select_network x
with x = 0 or 1 returns the sameSelected interface 'p2p-dev-wlan0'
OK
, and with both WiFi networks correctly broadcasting, my RPi still connects to only one of them, so this doesn't allow to switch between networks. (2) The position inwpa_supplicant.conf
does not select the priority (setting my own hotspot in 2nd position inwpa_supplicant.conf
will chose it even with the other WiFi turned on and set in 1st position). – calocedrus Jan 31 '18 at 01:14 -
And (3): I suppose that by setting priority you mean adding
priority = x
with x = 1, 2, ... insidenetwork {...}
inwpa_supplicant.conf
? – calocedrus Jan 31 '18 at 01:16 -
As I said it has been some time since I used it (while testing with a number of AP). According to
wpa_cli list_networks
it works, I just switched from1 PiNET any [CURRENT]
to1 PiNET any [DISABLED]
butiwconfig
showswlan0 IEEE 802.11 ESSID:"PiNET"
Maybe the wireless hook indhcpcd
gets in the way. – Milliways Jan 31 '18 at 01:37 -
Here's my experiment: (a) after reboot I'm connected to wifi_hotspot. (b)
wpa_cli list_networks
shows the 2 lines0 other_wifi any
and1 myhostpot any
(c)wpa_cli select_network 1
(d)wpa_cli list_networks
then shows0 other_wifi any [DISABLED]
and1 myhostpot any [CURRENT]
(e)wpa_cli select_network 0
(f)wpa_cli list_networks
shows0 other_wifi any [CURRENT]
1 myhostpot any [DISABLED]
. But I still see me as a connected user on my hotspot and still have the same IP address (ifconfig), and can do apt-get install (I didn't set the other wifi password so not connectd)! – calocedrus Jan 31 '18 at 02:58