This is using the latest Raspbian Stretch release dated 2018-06-27, Linux kernel 4.14 on a RPi 3 B+. I will note that this works perfectly fine on Raspbian Jessie, linux kernel 4.9, on either a RPI 3 B or B+.
I am able to switch Wifi networks using the on-board WiFi by modifying the ssid and psk in wpa_supplicant.conf and then executing
wpa_cli reconfigure. When using a USB WiFi dongle though this does not work. Opening up interactive mode on the wpa_cli shows the following message:
<3>CTRL-EVENT-SCAN-STARTED <3>CTRL-EVENT-SCAN-RESULTS <3>WPS-AP-AVAILABLE <3>Trying to associate with 2c:fd:a1:63:4d:28 (SSID='my ssid' freq=2457 MHz) <3>Association request to the driver failed
I have tried multiple USB WiFi dongles but none of them work, though they all seem to use the RTL8192CU chipset so I am guessing that is the issue but it must be specific to the driver used in Raspbian Stretch. I am not very experienced with kernel modules so I have not been able to investigate much further.
Would it possible to use the Jessie driver in Stretch? Or does anyone have any other ideas of what might be causing this or ways to resolve?
My ultimate goal is to be able to disable the interface and then bring it back up when I want to connect to WiFi. So far everything I have tried results in the error message mentioned above, whether the interface is brought up/down with
ip, or when restarting services.
EDIT: I was able to get it working by reloading the driver. Not the best solution but its better than nothing I suppose...
rmmod 8192cu modprobe 8192cu