Interesting questions.
N.B.: I can't replicate your network setup. Consequently, the following answers have not been fully verified. I feel the alternate/sequential connections
approach will work for you assuming both APs (IoT & WiFi) are on functional networks.
Summary:
A "simultaneous" solution is possible only with hardware & drivers that support it. AFAIK, there is no RPi hardware that does.
An "alternate/sequential" solution is possible, and illustrated below. This solution employs the wpa_cli
app (part of wpa_supplicant
) to rotate AP priorities using set network <id> priority <n>
followed by a reassociate
to switch to the higher priority network id/AP. This rather obtuse approach is necessary to avoid the select_network
option that disables the other networks.
WRT Q1: connect to 2 Wi-Fi access points simultaneously ?
As I understand it, this requires both an interface (hardware) and a driver that supports dual-channel management. You should run the iw list
command on your Pi 0 W2 to determine if your system currently supports "simultaneous".
For my RPi (a 3B+ running bullseye), I get the result below where <=1
effectively means that the "simultaneous" option is not available for my 3B+. If you get <=1
result, then "simultaneous" is likely not available for you either. This may guide your selection of a suitable USB NIC if you want "simultaneous".
$ iw list | grep -A 4 'valid interface combinations'
valid interface combinations:
* #{ managed } <= 1, #{ P2P-device } <= 1, #{ P2P-client, P2P-GO } <= 1,
total <= 3, #channels <= 2
* #{ managed } <= 1, #{ AP } <= 1, #{ P2P-client } <= 1, #{ P2P-device } <= 1,
total <= 4, #channels <= 1
WRT Q2: alternate/sequential wifi connections
I believe this will do what you need using the single wlan0
interface built into your Pi 0 2W. You may wish to do some reading (see REFERENCES below) before you begin, and get some background on this process. Based on my reading of this & other research, and under the assumptions stated above, this option will work. The procedure is outlined below in two steps:
- Declare both networks in
/etc/wpa_supplicant/wpa_supplicant.conf
You didn't show your wpa_supplicant.conf
file, so I've created this one to serve as an example:
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=GB
network={
ssid="MyWiFiAP"
psk="mypasswd"
}
network={
ssid="MyIoTAP"
psk="mypasswd2"
}
- We use
wpa_cli
in its interactive mode below, but all of these commands may be written as stand-alone commands, suitable for scripting:
$ wpa_cli
... # preliminaries...
> list_networks
network id / ssid / bssid / flags
0 MyWiFiAP any [CURRENT]
1 MyIoTAP any
The above result shows the two SSIDs configured in wpa_supplicant.conf
> get_network 1 priority
0
> get_network 0 priority
0
The above results show the priority of the two SSID/network ids (0 & 1)
> set_network 1 priority 2
OK
Assign a higher priority to network id 1 (MyIoTAP)
> reassociate
OK
... a series of CTRL_EVENTS are listed ...
Connect to the higher priority network (MyIoTAP)
> list_networks
network id / ssid / bssid / flags
0 MyWiFiAP any
1 MyIoTAP any [CURRENT]
after reassociate
, connection has moved to higher priority network/SSID
to restore the original connection to MyWiFiAP:
use the set_network
priority commands above,
follow that with another reassociate
Note: when priorities of all networks are equal,
wpa_supplicant defaults to the one with the strongest signal
> quit
terminates the wpa_cli interactive session
$
And that's it... the alternate/sequential wifi connections
process. You should verify this works with your network configuration manually as I've shown above. Once verified, you may use the equivalent stand-alone commands to automate the process in a script - or experiment with wpa_cli
running in daemon mode.
REFERENCES:
- RE:
wlan0
vs. p2p-dev-wlan0
- ArchWiki
wpa_supplicant
documentation
man wpa_cli
on your RPi
- Linux Find Wireless WiFi Driver Chipset Information