Uncategorized

PiZeroW AP + Wifi Client

So I wanted to be able to set the Wifi details of a Pi without connecting a monitor and keyboard. Easy, right? No. RaspAP almost does it out-of-the-box, but I couldn't quite crack it. It's the best solution once it's working.

Update May 2020: RaspAP has been slightly updated and install process is clarified for the PiZeroW. Use that.

Update June 2020: RaspAP installs and runs ok, but it (or something else) is flaky: wlan0 connection is repeatedly dropped. Legacy method didn't have this problem.

Legacy Method:

For now let's Frankenstein it: after burning a fresh Raspbian Lite to the PiZeroW:

Setup AP

Use this script based on other work - really nice. It setups up the Pi as a AP and connects to a AP as a client, simultaneously.

wget -O rpi-wifi.sh https://raw.githubusercontent.com/lukicdarkoo/rpi-wifi/master/configure 
chmod 755 rpi-wifi.sh
./rpi-wifi.sh  -a tmv-tripod-ap imagines -c "NetComm 0405" 12345678

Install RaspAP Manually (Take 2)

sudo apt-get install -y git 
sudo apt-get install -y lighttpd php7.3-cgi vnstat # qrencode  

sudo lighttpd-enable-mod fastcgi-php
sudo service lighttpd force-reload
sudo systemctl restart lighttpd.service

sudo rm -rf /var/www/html
sudo git clone https://github.com/billz/raspap-webgui /var/www/html

cd /var/www/html sudo cp installers/raspap.sudoers 
/etc/sudoers.d/090_raspap

# SKIP STEPS

sudo mkdir /etc/raspap/
sudo cp raspap.php /etc/raspap/
sudo cp config/config.php /var/www/html/includes/

sudo chown -R www-data:www-data /var/www/html 
sudo chown -R www-data:www-data /etc/raspap
# skip
sudo cp config/config.php /var/www/html/includes/

 # Add to /bin/rpi-wifi.sh 
echo sudo dhcpcd -f /etc/dhcpcd.conf | sudo tee -a /bin/rpi-wifi.sh 

Install RaspAP Manually (Take 1)

The networking setup in RaspAP didn't work for me, so I just use the web-server and service, which allows me change the Pi's WiFi network by connecting to the Pi's AP. Use manual instructions, adapted:

# no dhcpcd5 recommmneded for debian
# get php and monitoring stuff (some extras like hostapd dnsmasq will already be installed)
sudo apt-get install -y git # hostapd dnsmasq  
sudo apt-get install -y vnstat lighttpd qrencode php7.3-cgi
# php
sudo lighttpd-enable-mod fastcgi-php
sudo service lighttpd force-reload
sudo systemctl restart lighttpd.service
# add web content
sudo rm -rf /var/www/html
sudo git clone https://github.com/billz/raspap-webgui /var/www/html
#
cd /var/www/html
sudo cp installers/raspap.sudoers /etc/sudoers.d/090_raspap
#
sudo mkdir /etc/raspap/
sudo mkdir /etc/raspap/backups
sudo mkdir /etc/raspap/networking
sudo mkdir /etc/raspap/hostapd
sudo mkdir /etc/raspap/lighttpd
# don't know - exclude for now
# cat /etc/dhcpcd.conf | sudo tee -a /etc/raspap/networking/defaults > /dev/null
#
sudo cp raspap.php /etc/raspap 
sudo chown -R www-data:www-data /var/www/html 
sudo chown -R www-data:www-data /etc/raspap
# no
sudo mv installers/*log.sh /etc/raspap/hostapd 
sudo mv installers/service*.sh /etc/raspap/hostapd
#
sudo chown -c root:www-data /etc/raspap/hostapd/*.sh 
sudo chmod 750 /etc/raspap/hostapd/*.sh 
#
sudo cp config/config.php /var/www/html/includes/
#
sudo cp installers/configport.sh /etc/raspap/lighttpd
sudo chown -c root:www-data /etc/raspap/lighttpd/*.sh
# raspapd is not required
#sudo mv installers/raspapd.service /lib/systemd/system
#sudo systemctl daemon-reload
#sudo systemctl enable raspapd.service

And finally, I had to add the following to ensure dhcpcd ran for wlan0, as it failed on boot after install RaspAP.

# Add to /bin/rpi-wifi.sh
echo sudo dhcpcd -f /etc/dhcpcd.conf | sudo tee -a /bin/rpi-wifi.sh

Now, reboot and you can:

  1. Connect to your Pi via the AP, then browse to it's IP (192.168.10.1) to modify settings in RaspAP. Todo: it can be configured for a captive portal.
  2. It will connect to your router as a client too.

Leave a Reply

Your email address will not be published. Required fields are marked *