I have managed to setup my Raspberry Pi Zero W to work in both AP and Client mode simultaneously using this great guide.
wpa_cli -iwlan0 (no sudo), I am able to scan, connect and save networks dynamically (eventually programatically from Python).
For the AP, I have added the following two lines to
/etc/hostapd/hostapd.conf to enable cli control through
sudo hostapd_cli (strangely with sudo vs. wpa_cli which is without. Is that because of
sudo hostapd_cli disable I can turn off the AP without affecting the client. This does not bring down the interface, just the SSID I believe. Then, if I want to change the SSID and PSK etc. of the AP I can edit
sudo nano /etc/hostapd/hostapd.conf. Then when I want to start the AP (with or without changing SSID/PSK), I use
sudo systemctl restart hostapd.service. This gives and error but everything still works so I don't think that is an issue?
Warning: The unit file, source configuration file or drop-ins of hostapd.service changed on disk. Run 'systemctl daemon-reload' to reload units. I'm not using
sudo hostapd_cli enable as this gives an error and then causes issues, where restarting the service doesn't.
Like this there is very minimal client downtime since, as I understand, hostapd has full control of the interface and stopping hostapd.service brings down client mode.
Is this the best way to be doing all of this? Specifically with the AP part, I have not worked out a cleaner way to change the SSID and PSK without editing the file (e.g. by using
hostapd_cli), is there one?
My main sticking point now is that when the pi boots, I want the AP to NOT be enabled. i.e. I want it to be as if the command
sudo hostapd_cli disable has been run. I suppose I could run that command somewhere in the boot sequence but that means the SSID will likely come up for a short period and it would be much cleaner if it never enables in the first place. Any idea how I can stop the SSID from enabling on boot? I also tried
.conf but that crashed hostapd.
Edit: also very strangely, for some reason the AP works with bridge mode even though I did not follow the steps for that. Whilst this is great, I would like the option also of disabling it. Is that possible?