jeffaf123
Posts: 5
Joined: Sat Jun 30, 2018 6:01 pm

WiFi on headless Pi Zero W

Sun Jul 01, 2018 2:03 pm

I've got a Pi Zero W and I want to set up WiFi, headless from the start. The SD card has been set up using "2018-06-27-raspbian-stretch-lite.img". I've followed the document in the Help section which deals with adding the wpa_supplicant.conf file to the boot partition before first boot and it has been correctly copied to rootfs. The content is as specified (obviously I've changed the SSID and key) ...

network={
ssid="MySSID"
psk="MyKey"
}

I've also tried with some extra content in the wpa_supplicant.conf file ...

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=GB

network={
ssid="My SSID"
psk="My key"
key_mgmt=WPA-PSK
}

Neither config results in connection. I've read various other posts on this topic but nothing seems to work.

What am I missing?

User avatar
HawaiianPi
Posts: 5202
Joined: Mon Apr 08, 2013 4:53 am
Location: Aloha, Oregon USA

Re: WiFi on headless Pi Zero W

Sun Jul 01, 2018 7:14 pm

jeffaf123 wrote:
Sun Jul 01, 2018 2:03 pm
I've followed the document in the Help section which deals with adding the wpa_supplicant.conf file to the boot partition before first boot and it has been correctly copied to rootfs.
If you copied it to rootfs, then you didn't follow the instructions. You copy it to the "boot" partition, not the /boot directory. The "boot" partition is the first partition on a Raspbian imaged SD card, which should be a tiny FAT32 partition (labelled "boot"). Unless you meant it was copied by Raspbian after booting (which was not clear from your statement), in which case it should be in the /etc/wpa_supplicant folder, not rootfs. :?

This is the procedure I use for setting up headless boot with SSH and wireless network. It works with Raspbian Jessie or Stretch, Desktop or Lite, and with the built-in WiFi on the Pi3B(+) & Pi Zero W, or a Raspbian compatible USB WiFi dongle on other models. Everything is done before you boot, and can be done on a Windows or Mac computer which only has access to the small FAT32 "boot" partition of a Raspbian imaged SD card.
  1. Grab the latest Raspbian image from https://www.raspberrypi.org/downloads/raspbian/
  2. Grab the Etcher software from https://etcher.io/
  3. Use Etcher to write the Raspbian image to your SD card.
    • You don't need to extract the image or format the card prior to writing.
    • Just run Etcher, choose the Raspbian .zip you downloaded, pick your SD card and write.
    • If you have trouble, verify the SHA256 checksum of the download.
    • Writing an image to your card will erase everything previously on it!
  4. Remove and reinsert the SD card so that your Windows or Mac PC can see the small FAT32 partition on the card (labelled "boot").
    • If you get a message telling you the card must be formatted, cancel it.
  5. On that small FAT32 partition, create a file with the name ssh (or ssh.txt). It can be empty, the contents don't matter.
  6. To connect to a wireless network, create another file on the card called wpa_supplicant.conf, which has the following inside:

    Code: Select all

    ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
    update_config=1
    country=US
    
    network={
         ssid="Your network name/SSID"
         psk="Your WPA/WPA2 security key"
         key_mgmt=WPA-PSK
    }
    • Edit country=, ssid= and psk= with your information and save the file.
    • Use the 2 letter country abbreviation in CAPS (without this you may have no WiFi).
    • Use a pure text editor, not a word processor, to edit the wpa_supplicant.conf file.
  7. Make sure that both files are in the main directory of the small FAT32 partition, not in any folder.
  8. Safely eject the card from your PC and use it to boot the Pi.
If Raspbian finds an ssh file it will enable SSH and delete the file. If it finds a wpa_supplicant.conf file, it will move it to its correct location and connect to your wireless network. Give your Pi some time to boot and connect to your network (the first boot always takes longer), then you should be able to SSH into the Pi and configure it how you like.

If you have a Zeroconf network service installed (Apple's iTunes or Bonjour install Zeroconf to Windows), you can SSH into [email protected] (provided you don't have any other Pi computers on your network with the same default hostname). Otherwise you must SSH into your Pi's IP address, which you can find by logging into your router and checking the list of connected clients, or using a network scanner app (like Fing for smartphones).
My mind is like a browser. 27 tabs are open, 9 aren't responding,
lots of pop-ups...and where is that annoying music coming from?

jeffaf123
Posts: 5
Joined: Sat Jun 30, 2018 6:01 pm

Re: WiFi on headless Pi Zero W

Sun Jul 01, 2018 8:27 pm

Yes, sorry, I put the file in the boot partition and it was copied to /etc/wpa_supplicant/wpa_supplicant.conf by the system as it booted for the first time. Both ifconfig and iwconfig still show no IP address and indicate that the pi is not associated with an access point.

I've been looking at the messages from booting an=gain and found a failure message (which I can't find now but I'll try to recreate) which included a command to get further info. See below

[email protected]:~$ systemctl status networking.service
● networking.service - Raise network interfaces
Loaded: loaded (/lib/systemd/system/networking.service; enabled; vendor prese
Active: failed (Result: exit-code) since Wed 2018-06-27 02:52:46 UTC; 58s ago
Docs: man:interfaces(5)
Process: 270 ExecStart=/sbin/ifup -a --read-environment (code=exited, status=1
Process: 159 ExecStartPre=/bin/sh -c [ "$CONFIGURE_INTERFACES" != "no" ] && [
Main PID: 270 (code=exited, status=1/FAILURE)

Jun 27 02:52:40 raspberrypi systemd[1]: Starting Raise network interfaces...
Jun 27 02:52:46 raspberrypi ifup[270]: /etc/network/if-pre-up.d/wpasupplicant: 1
Jun 27 02:52:46 raspberrypi ifup[270]: run-parts: /etc/network/if-pre-up.d/wpasu
Jun 27 02:52:46 raspberrypi ifup[270]: ifup: failed to bring up wlan0
Jun 27 02:52:46 raspberrypi systemd[1]: networking.service: Main process exited,
Jun 27 02:52:46 raspberrypi systemd[1]: Failed to start Raise network interfaces
Jun 27 02:52:47 raspberrypi systemd[1]: networking.service: Unit entered failed
Jun 27 02:52:47 raspberrypi systemd[1]: networking.service: Failed with result '
lines 1-16/16 (END)

mattmiller
Posts: 2178
Joined: Thu Feb 05, 2015 11:25 pm

Re: WiFi on headless Pi Zero W

Sun Jul 01, 2018 10:55 pm

Yes, sorry, I put the file in the boot partition and it was copied to /etc/wpa_supplicant/wpa_supplicant.conf by the system as it booted for the first time. Both ifconfig and iwconfig still show no IP address and indicate that the pi is not associated with an access point.
Looks like you've got keyboard/screen for your PiZeroW

SO I'd suggest loading SD card with full Raspbian not lite and trying to connect to your WiFi using desktop icon (after setting location info up)
(This eliminates a lot of cause of errors)

If that works - you can make a copy of your working wpa_supplicant.conf file and use it on lite versions in future

If it doesn't work you've got a faulty Pi or incompatible router

PS Try turning router off and on

jeffaf123
Posts: 5
Joined: Sat Jun 30, 2018 6:01 pm

Re: WiFi on headless Pi Zero W

Mon Jul 02, 2018 1:20 pm

mattmiller wrote:
Sun Jul 01, 2018 10:55 pm
Yes, sorry, I put the file in the boot partition and it was copied to /etc/wpa_supplicant/wpa_supplicant.conf by the system as it booted for the first time. Both ifconfig and iwconfig still show no IP address and indicate that the pi is not associated with an access point.
Looks like you've got keyboard/screen for your PiZeroW

SO I'd suggest loading SD card with full Raspbian not lite and trying to connect to your WiFi using desktop icon (after setting location info up)
(This eliminates a lot of cause of errors)

If that works - you can make a copy of your working wpa_supplicant.conf file and use it on lite versions in future

If it doesn't work you've got a faulty Pi or incompatible router

PS Try turning router off and on
Thanks for the reply (and to HawaiianPi)

I haven't got a monitor etc connected, I'm using a serial cable to connect to a console. It's true though, I can go and borrow a keyboard, mouse etc and get a working wpa_supplicant.conf through the gui. It would be nice to find out what's wrong with the original file - it looks OK to my eye

User avatar
HawaiianPi
Posts: 5202
Joined: Mon Apr 08, 2013 4:53 am
Location: Aloha, Oregon USA

Re: WiFi on headless Pi Zero W

Mon Jul 02, 2018 6:15 pm

Are you trying to connect to a 5GHz network (the Pi3B and Zero W only support 2.4GHz)?

What did you use to create or edit the wpa_supplicant.conf file?

Do you have any other wireless Pi set up and working (you can copy the wpa_supplicant.conf from that)?

What does the following command return?

Code: Select all

cat /sys/firmware/devicetree/base/model;echo
My mind is like a browser. 27 tabs are open, 9 aren't responding,
lots of pop-ups...and where is that annoying music coming from?

jeffaf123
Posts: 5
Joined: Sat Jun 30, 2018 6:01 pm

Re: WiFi on headless Pi Zero W

Mon Jul 02, 2018 7:06 pm

HawaiianPi wrote:
Mon Jul 02, 2018 6:15 pm
Are you trying to connect to a 5GHz network (the Pi3B and Zero W only support 2.4GHz)?

What did you use to create or edit the wpa_supplicant.conf file?

Do you have any other wireless Pi set up and working (you can copy the wpa_supplicant.conf from that)?

What does the following command return?

Code: Select all

cat /sys/firmware/devicetree/base/model;echo
Hi

The access point only provides a 2.4GHz network

I used Mousepad on my laptop running Debian to edit the file

I have another Pi Zero W which I'll try before I fiddle around borrowing keyboard etc. At least that should eliminate the faulty Pi suggested by MattMiller. I've just read about wpa_cli - with the serial cable I can try adding a network and saving the resulting config. I'll let you know.

The string returned from the command is ..
Raspberry Pi Zero W Rev 1.1

jeffaf123
Posts: 5
Joined: Sat Jun 30, 2018 6:01 pm

Re: WiFi on headless Pi Zero W

Tue Jul 03, 2018 7:51 am

Just realised last night that I'll have a working wpa_supplicant.conf on the laptop. I'll have a look at that when I get a chance

Return to “Troubleshooting”