I have managed to setup my Raspberry Pi Zero W to work in both AP and Client mode simultaneously using this great guide.
Using 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 ctrl_interface_group=0
?):
ctrl_interface=/var/run/hostapd
ctrl_interface_group=0
Using 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 disabled=1
in .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?
sudo hostapd_cli disable
command has been run. There must be a point during boot that the enable command is run? Or else when the hostapd service is started, I want to run that disable command immediately after it...where would I incorporate that command? – Bassline Soup Jun 16 '20 at 12:03sudo hostapd_cli disable
stops the SSID but the interfaces are still up – Bassline Soup Jun 16 '20 at 13:36apt show nftables
). – Ingo Jun 17 '20 at 16:43systemctl edit hostapd.service
. But there is nodisable
command in it. What do you mean? – Ingo Jul 03 '20 at 10:23ExecStartPost=/usr/sbin/hostapd_cli disable
so that the Pi boots without AP enabled, but thensudo systemctl restart hostapd.service
does not seem to bring the AP up enabled as it did before. I haven't dug into it deeply yet as someone is using the pi so just commented out the line in the drop in file and rebooted to get the AP to work for them, but thought it is probably something to do with the last sentence of your answer: that it might be too early for that disable command in the drop in. – Bassline Soup Jul 03 '20 at 15:32