Addicted
Posts: 52
Joined: Wed Oct 14, 2015 2:40 am

Use Wifi in latest raspbian lite stretch in headless mode

Sun Nov 05, 2017 11:50 am

Hi, after stretch update i downloaded lite image for my headless setup.
I created ssh file in boot partition & wpa_supplicant.conf file with necessary content.
However it didn't connected to Wifi.
Then i connected it through ethernet & added following to /etc/network/interfaces.

Code: Select all

auto lo
iface lo inet loopback

iface eth0 inet manual

auto wlan0
allow-hotplug wlan0
iface wlan0 inet manual
        wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
after that i did

Code: Select all

sudo systemctl enable wpa_supplicant.service
sudo reboot
After that wifi worked normally.

Is there anyway to do this without ethernet or display?
Last edited by Addicted on Mon Nov 06, 2017 1:47 pm, edited 1 time in total.

SurferTim
Posts: 1376
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Use Wifi in latest raspbian lite stretch in headless mode

Sun Nov 05, 2017 11:58 am

Normally this is caused by an error in the wpa_supplicant.conf file. You should have posted the contents of that file.

Addicted
Posts: 52
Joined: Wed Oct 14, 2015 2:40 am

Re: Use Wifi in latest raspbian lite stretch in headless mode

Sun Nov 05, 2017 12:03 pm

This is the content of wpa_supplicant.conf file.

Code: Select all

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

network={
    ssid="My_ssid"
    scan_ssid=1
    psk="My_pass"
    key_mgmt=WPA-PSK
    }
But there were nothing in interfaces file when i opened it.
only following were in interfaces file.

Code: Select all

# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
Last edited by Addicted on Sun Nov 05, 2017 2:12 pm, edited 1 time in total.

User avatar
mikerr
Posts: 2572
Joined: Thu Jan 12, 2012 12:46 pm
Location: UK
Contact: Website

Re: Use Wifi in latest raspbian lite stretch in headless mode

Sun Nov 05, 2017 12:12 pm

In Wheezy/Jessie you could get away with a short wpa_supplicant.conf file:

Code: Select all

network={
   ssid="MYSSID"
   psk="my  wifi password"
}
Since Stretch you do now need the ctrl_interface line for it to work.

Code: Select all

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
   ssid="MYSSID"
   psk="my  wifi password"
}
Android app - Raspi Card Imager - download and image SD cards - No PC required !

SurferTim
Posts: 1376
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Use Wifi in latest raspbian lite stretch in headless mode

Sun Nov 05, 2017 12:37 pm

Is this a typo? No closing brace on the network section. Any error will cause a fail.

Code: Select all

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

network={
    ssid="My_ssid"
    scan_ssid=1
    psk="My_pass"
    key_mgmt=WPA-PSK
@mikerr: Are you on the Tinker Board forum also?

Addicted
Posts: 52
Joined: Wed Oct 14, 2015 2:40 am

Re: Use Wifi in latest raspbian lite stretch in headless mode

Sun Nov 05, 2017 2:20 pm

SurferTim wrote:
Sun Nov 05, 2017 12:37 pm
Is this a typo? No closing brace on the network section. Any error will cause a fail.

Code: Select all

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

network={
    ssid="My_ssid"
    scan_ssid=1
    psk="My_pass"
    key_mgmt=WPA-PSK
@mikerr: Are you on the Tinker Board forum also?
Ya thats a typo. Corrected in my post

@mikerr: Ya but wpa_supplicant.conf file is ok & as i posted in 1st post i created wpa_supplicant.conf file in boot partition & it contains ctrl_interface line.
So is that /etc/network/interfaces file supposed to be empty?

SurferTim
Posts: 1376
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Use Wifi in latest raspbian lite stretch in headless mode

Sun Nov 05, 2017 2:24 pm

The source-directory line should be the only uncommented line in /etc/network/interfaces.

Insure the editor you use to create that file is a true text editor. There have been a few problems caused by using a word processor or copy-and-paste from examples where the double quotes were not correct.

Also insure your passphrase is at least 8 characters long.

Addicted
Posts: 52
Joined: Wed Oct 14, 2015 2:40 am

Re: Use Wifi in latest raspbian lite stretch in headless mode

Sun Nov 05, 2017 2:28 pm

SurferTim wrote:
Sun Nov 05, 2017 2:24 pm
The source-directory line should be the only uncommented line in /etc/network/interfaces.

Insure the editor you use to create that file is a true text editor. There have been a few problems caused by using a word processor or copy-and-paste from examples where the double quotes were not correct.
But i was only able to connect to wifi after coping following from my 2nd pi running jessie to new stretch headless 1.

Code: Select all

auto lo
iface lo inet loopback

iface eth0 inet manual

auto wlan0
allow-hotplug wlan0
iface wlan0 inet manual
        wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
btw i'm using rpi2 & using a wifi dongle.


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

Re: Use Wifi in latest raspbian lite stretch in headless mode

Mon Nov 06, 2017 2:02 am

Editing the /etc/network/interfaces file is not needed, and in fact, it shouldn't be modified. If you need a static IP that's done in /etc/dhcpcd.conf now. If you are using DHCP you should not need to edit anything but /etc/wpa_supplicant/wpa_supplicant.conf in Jessie or Stretch. You can actually place that file in the small FAT32 boot partition to connect to your wireless network automatically.

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 Pi3, or a Raspbian compatible USB WiFi dongle on other models (tested on an old model B, Pi2 and Pi Zero). Everything is done before you boot the SD card, and can be done on a Windows or Mac computer which only has access to the small FAT32 boot partition of a Raspbian 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. Install Etcher and use it 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 choose the Raspbian .zip, pick your SD card and write (if you have trouble, verify the SHA256 checksum of the download).
  4. Remove and reinsert the SD card so that your Windows or Mac PC can see the small FAT32 partition on the SD card.
  5. On that small partition, create a file with the name ssh (or ssh.txt).
  6. To connect to a wireless network, create another file on the FAT32 partition 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 SSID"
    	psk="Your WPA/WPA2 security key"
    	key_mgmt=WPA-PSK
    }
  7. Edit country=, ssid= and psk= with your information and save the file.
  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. You can try to connect to the Pi with ssh pi@raspberrypi (or raspberrypi.local), and if that doesn't work, login to your router to find the Pi's IP address. If you have an ASUS router they have a nice phone app to access and control the router.

If this doesn't work, then check your router for security settings like MAC address filtering or wireless client/AP isolation. Also, make sure you are editing wpa_supplicant.conf with a pure text editor (anything that adds hidden formatting codes will mess it up).

Another nice tool to have is a serial console cable which will let you monitor output and login to the Pi without a network connection. I use a CP2102 USB TTL serial adapter, which is compatible with the Pi's 3V3 GPIO and can be found on ebay for less than $2 (or $5-$10 on Amazon).

Here is my Pi Zero connected to an old Netbook with the CP2102 adapter (with a pcDuino WiFi dongle for wireless).
Image

For the Pi3 or Zero-W you'll have to disable Bluetooth to restore GPIO serial console output, but it's plug-n-play with other models. To disable Bluetooth add dtoverlay=pi3-disable-bt to config.txt, and for the Desktop version of Raspbian, add enable_uart=1 to enable the serial console.

Search ebay for CP2102. There are zillions of them and prices are all over the place. As long as it's a CP2102 chip based model it should work the same as any other. Typically they run in the $2-$5 range, but there are a few for under $2, and even some under $1.50.

There are 5 and 6 pin models. The 5 pin models are mostly missing the DTR line, which is important for Arduino but not needed for the Pi serial console (Pi only needs RXD, TXD and GND, which they all have). So if you don't care about Arduino compatibility, get either type. The ones I have are all 6 pin, but even some of those don't have DTR, so it's a little whacky because they all aren't wired the same.

As long as you follow the labels on the output pins you'll be okay. The connections from the USB TTL adapter to the Pi are:

GND (ground) > GPIO pin 06 (GND)
RXD > GPIO pin 08 (TXD)
TXD > GPIO pin 10 (RXD)

Note that in my picture the Pi Zero has four connections, and no micro-USB power cord. The CP2102 also has 3V3 and 5V outputs, so for the Zero I connected the 5V to GPIO pin 02 (5V) to provide power. It would probably be okay for a model A or B as well (although it would bypass the power protection), but a Pi2 or Pi3 should have its own power supply and only the 3 connections listed above.

For a serial terminal under Linux I install screen and open the serial terminal with sudo screen /dev/ttyUSB0 115200. Under Windows you can use PuTTY with Serial as the connection type, the COM port number under Serial line, and 115200 as the speed (check the port number in Device Manager). With Windows 10 you can also use the Windows Subsystem for Linux (WSL), but you'll need the Fall Creators Update to use serial ports. The procedure is similar to Linux, but the COM port will be ttyS# (note the capital S), with # being the port number Windows 10 assigned to your adapter (if Device Manager shows COM4, you'll use sudo screen /dev/ttyS4 115200 to open the serial terminal). WSL is still beta, so PuTTY might be a little more reliable, but I have found that hitting enter a few times will often connect when the terminal window isn't showing any output.

Image

Linux supports the CP2102 directly. Windows will need a driver: CP210x_Windows_Drivers.zip (not sure about Mac).
My password is the last 8 digits of Pi.

Addicted
Posts: 52
Joined: Wed Oct 14, 2015 2:40 am

Re: Use Wifi in latest raspbian lite stretch in headless mode

Mon Nov 06, 2017 7:28 am

Editing the /etc/network/interfaces file is not needed
ok. But without doing that i can't connect to wifi.
& your tutorial & those steps, i already followed that & unable to connect to wifi. Thats why i created this thread in the 1st place.
I appreciate that you were trying to help. But You didn't read what i tried & what i want to do.
You were giving me a solution through using a USB to ttl serial connection when i was asking to access pi ssh through wifi.

User avatar
rpdom
Posts: 12119
Joined: Sun May 06, 2012 5:17 am
Location: Essex, UK

Re: Use Wifi in latest raspbian lite stretch in headless mode

Mon Nov 06, 2017 7:55 am

Addicted wrote:
Mon Nov 06, 2017 7:28 am
Editing the /etc/network/interfaces file is not needed
ok. But without doing that i can't connect to wifi.
& your tutorial & those steps, i already followed that & unable to connect to wifi. Thats why i created this thread in the 1st place.
I appreciate that you were trying to help. But You didn't read what i tried & what i want to do.
You were giving me a solution through using a USB to ttl serial connection when i was asking to access pi ssh through wifi.
Ignore the USB serial connection thing. 99.9% of Pi users won't need or want such a device. I don't know why HawaiianPi is spamming the forum with this at the moment.

The rest of the information about using wpa_supplicant.conf is valid though.

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4818
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: Use Wifi in latest raspbian lite stretch in headless mode

Mon Nov 06, 2017 7:58 am

If you can get your pi in the state where your wpa_supplicant.conf is valid but you can't connect with an empty interfaces file, please post the output of 'sudo journalctl'. It should tell you exactly why.

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

Re: Use Wifi in latest raspbian lite stretch in headless mode

Mon Nov 06, 2017 7:09 pm

rpdom wrote:
Mon Nov 06, 2017 7:55 am
Ignore the USB serial connection thing. 99.9% of Pi users won't need or want such a device. I don't know why HawaiianPi is spamming the forum with this at the moment.
Because it's an inexpensive tool that helps to troubleshoot problems like this (and others). Seriously, it's 2 bucks, and it can be very helpful, so why not recommend it?
My password is the last 8 digits of Pi.

mikew
Posts: 3
Joined: Tue Nov 20, 2012 9:53 pm

Re: Use Wifi in latest raspbian lite stretch in headless mode

Wed Nov 29, 2017 10:01 am

FIXED IP ADDRESS FOR ETHERNET AND WIFI DONGLE ON RASPBERRY PI 2

I followed very many false leads trying to get wifi with fixed ip address to work
on a nov 2017 install of NOOBS_v2_4_4 on a pi-2 with Raspi wifi dongle.

On a clean new install, ONLY modify these 2 files:

/etc/wpa_supplicant/wpa_supplicant.conf
to look like:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=YR #your 2 letter code

network={
ssid="your wifi SSID"
psk="your wifi pass"
key_mgmt=WPA-PSK
}

/etc/dhcpcd.conf
uncomment the lines as shown below and put in the required ip address settings:
save the file and reboot.

(I used 192.168.1.40 for eth0 and 192.168.1.20 for wlan0)

# Example static IP configuration:
interface eth0
static ip_address=192.168.1.40/24
static ip6_address=fd51:42f8:yyyy:xxxx::ff/64
static routers=192.168.1.1
static domain_name_servers=192.168.1.1 8.8.8.8 fd51:42f8:caae:d92e::1

interface wlan0
static ip_address=192.168.1.20/24
#static ip6_address=fd51:42f8:xxxx:yyyy::ff/64
static routers=192.168.1.1
static domain_name_servers=192.168.1.1 8.8.8.8

# It is possible to fall back to a static IP if DHCP fails:
# define static profile
#profile static_eth0
#static ip_address=192.168.1.20/24
#static routers=192.168.1.1
#static domain_name_servers=192.168.1.1

# fallback to static profile on eth0
#interface eth0
#fallback static_eth0

timdonovan
Posts: 7
Joined: Wed Oct 28, 2015 3:50 pm

Re: Use Wifi in latest raspbian lite stretch in headless mode

Fri Dec 22, 2017 11:12 am

Sigh. After 2 hours of messing around, I find that wpa_supplicant.conf headlessly is totally broken in Stretch (or at least, the previous wpa_supplicant is completely incompatible with previous ones). Why?!!?

What fixed it for me was one of the following (taken from various threads and google searches):

Including this at the top:

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

Using wpa_passphrase on another pi to generate a network {} config, with a hashed password (I think you can no longer just do psk="yourpassword" in wpa_supplicant ).

Including a second dummy network such as:

network={
ssid="any_old_fake_ssid"
scan_ssid=1
psk="fakefake"
key_mgmt=WPA-PSK
}

Not sure why something that's been working fine for years had to then be broken and messed around with in Stretch.

SurferTim
Posts: 1376
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Use Wifi in latest raspbian lite stretch in headless mode

Fri Dec 22, 2017 12:34 pm

Headless wifi start is not broken in Stretch 2017-09-07. I haven't tested 2017-11-29 yet. I'll get to that soon. I've had a lot of other network checking with the new version. Are you using the full version or lite?

You must have this in your wpa_supplicant.conf file. Change the two letter country code to yours.

Code: Select all

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

network={
ssid="any_old_fake_ssid"
psk="fakefake"
}
Edit: Just tested 2017-11-29 Lite headless boot using a RPi Zero W. Worked fine as I described. I just SSH connected to it.

CraigT
Posts: 21
Joined: Mon Oct 27, 2014 10:45 pm

Re: Use Wifi in latest raspbian lite stretch in headless mode

Sat Jan 13, 2018 11:09 pm

Kind of re-iterating SurferTim.

I just had a similar problem getting my Wi-Fi to work on a completely fresh new Raspbian Stretch Lite install on a Pi Zero W.
Cutting a long story short, I believe the problem was with the way I had modified the wpa_supplicant.conf file.
I replaced my modified file with the original file (always good to backup a file before modifying it) and then started again, this time making less modifications (and no tabs), rebooted and it worked! Yay!

Note. In the working file, I only added the ssid and psk lines under my network entry.

I believe the problem could have been because I had used tabs when modifying the file in nano (I tried to remove them all but that didn't seem to fix things) OR because I tried to add network entries for 3 wireless networks (I am not sure whether multiple networks with no preference was an issue or maybe there was a typo in my config - made more likely by having three entries).

If I have a bit more time I may investigate more with the retained incorrect file.

Hope this helps someone else.

Craig

User avatar
mikerr
Posts: 2572
Joined: Thu Jan 12, 2012 12:46 pm
Location: UK
Contact: Website

Re: Use Wifi in latest raspbian lite stretch in headless mode

Sun Jan 14, 2018 10:34 am

timdonovan wrote:
Fri Dec 22, 2017 11:12 am
Sigh. After 2 hours of messing around, I find that wpa_supplicant.conf headlessly is totally broken in Stretch (or at least, the previous wpa_supplicant is completely incompatible with previous ones). Why?!!?
Stretch now requires the ctrl_interface line, whereas Jessie allowed you to omit it - see my post above.
Android app - Raspi Card Imager - download and image SD cards - No PC required !

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

Re: Use Wifi in latest raspbian lite stretch in headless mode

Sun Jan 14, 2018 12:29 pm

Networking works as advertised if you set up your SD card correctly. See my previous post in this thread.

viewtopic.php?p=1231189#p1231189

I have used that procedure many times on different Pi models and it works with the last version of Raspbian Jessie (early versions had some bugs), and all versions of Stretch.
My password is the last 8 digits of Pi.

psyke83
Posts: 1
Joined: Sun Feb 04, 2018 10:54 am

Re: Use Wifi in latest raspbian lite stretch in headless mode

Sun Feb 04, 2018 11:09 am

Hi folks,

I would suggest that all prior advice in this thread is disregarded, and the following is noted:

* When booting with an unconfigured wpa_supplicant.conf, if you add your network configuration and attempt to bring up the interface, the dhcpcd hooks for wlan0 will not trigger correctly. I'm not certain why this happens, but the following output can be seen directly after booting without wpa_supplicant.conf properly configured:

Code: Select all

$ systemctl status dhcpcd | grep Warn
Warning: dhcpcd.service changed on disk. Run 'systemctl daemon-reload' to reload units.
To fix, you can either do the following before attempting to bring up wlan0:

Code: Select all

sudo systemctl daemon-reload # not strictly necessary
sudo systemctl restart dhcpcd
Or simply reboot, because...

* When booting with a configured wpa_supplicant.conf, dhcpcd will trigger correctly on wlan0 up/down events, even though systemctl still warns about the service being changed on disk.

This also explains why a poster insisted that the method of installing a preconfigured /boot/wpa_supplicant.conf worked. In reality, all that matters is that a configured wpa_supplicant.conf in /etc/wpa_supplicant is present during boot.

Return to “Beginners”

Who is online

Users browsing this forum: boyoh and 63 guests