40

I just put a freshly flashed card (with 2017-09-07-raspbian-stretch-lite) into a Raspberry Pi Zero W.

Then I added these lines:

network={
    ssid="myWifiSsid"
    psk="myWifiPassword"
}

to /etc/wpa_supplicant/wpa_supplicant.conf.

The data entered was 100% correct. I waited 10 minutes and checked: It did not connect automatically.

Then I went back to the official instructions and ran sudo wpa_cli reconfigure as suggested. Same result: It did not connect.

Then I tried to manually restart wlan0:

sudo ifconfig wlan0 down
sudo ifconfig wlan0 up

Still the same: Is does not connect.

Then I did a reboot and it instantly automatically connected.

It's soo frustrating. It feels like the official instructions aren't tested at all.

So what is missing here, how can this be done without a reboot?

Forivin
  • 627
  • 3
  • 7
  • 11

8 Answers8

41

As of 2018, the previous answers don't work anymore, you need to run the following command:

sudo wpa_cli -i wlan0 reconfigure

Source: https://www.raspberrypi.org/forums/viewtopic.php?t=198274#p1238023

user000001
  • 511
  • 4
  • 4
33

I too saw this issue with my RaspberryPi Zero W using 2017-09-07-raspbian-stretch-lite.

Updating the wpa_supplicant.conf file, sudo wpa_cli reconfigure, and sudo systemctl restart wpa_supplicant did not work. My Pi would not get an IP on wlan0.

I noticed that wpa_supplicant is spawned as a child of the dhcpcd service.

$ sudo systemctl status

└─dhcpcd.service
  ├─890 wpa_supplicant -B -c/etc/wpa_supplicant/wpa_supplicant.conf -iwlan0
  └─912 /sbin/dhcpcd -q -w

I found that using daemon-reload and restarting the dhcpcd.service unit worked for me.

sudo systemctl daemon-reload
sudo systemctl restart dhcpcd

It seems like you should first run sudo systemcl daemon-reload before restarting dhcpcd. I am not entirely sure why, but it seems that the daemon-reload will alert service units to config file changes.

If I restarted dhcpcd without running daemon-reload, I got this warning. Warning: dhcpcd.service changed on disk. Run 'systemctl daemon-reload' to reload units., but it restarted just fine with or without daemon-reload. So I do not think it's vital, but probably a good practice.

Will Haley
  • 439
  • 2
  • 5
  • 8
6

I'm using a Raspberry Pi 3 with 2018-03-13-raspbian-stretch and my issue is marginally different, but I found a solution, so I think this can help you too.

I boot the RPi with /etc/wpa_supplicant/wpa_supplicant.conf set up so that I have one SSID and password set and the RPi connects automatically to the configured SSID on boot. In addition, I wanted to change /etc/wpa_supplicant/wpa_supplicant.conf using some automated text processing script and then reload the wifi settings.

After searching around for a bit, I found this post on the official Raspberry Pi forums and found this set of commands inside that worked for me at least:

sudo dhclient -r wlan0
sudo ifdown wlan0
sudo ifup wlan0
sudo dhclient -v wlan0

I don't know how or why they work, so no guarantees...

rmarques
  • 111
  • 1
  • 8
5

After adding a network in wpa_supplicant.conf:

Run the cli
(3 commands are used here: interface, reconfigure and quit)

root@raspberrypi:~# wpa_cli
wpa_cli v2.4
Copyright (c) 2004-2015, Jouni Malinen <j@w1.fi> and contributors

This software may be distributed under the terms of the BSD license.
See README for more details.


Selected interface 'p2p-dev-wlan0'

Interactive mode

<3>CTRL-EVENT-SCAN-RESULTS
> interface wlan0
Connected to interface 'wlan0.
> reconfigure
OK
<3>CTRL-EVENT-SCAN-STARTED
<3>CTRL-EVENT-SCAN-RESULTS
<3>WPS-AP-AVAILABLE
<3>Trying to associate with XX:Xa:aX:Xa:XX:Xa (SSID='wifissid' freq=2437 MHz)
<3>Associated with XX:Xa:aX:Xa:XX:Xa
<3>WPA: Key negotiation completed with XX:Xa:aX:Xa:XX:Xa [PTK=CCMP GTK=CCMP]
<3>CTRL-EVENT-CONNECTED - Connection to XX:Xa:aX:Xa:XX:Xa completed [id=0 id_str=]
> quit

Then verify that you have an IP address.

root@raspberrypi:~# ifconfig wlan0
wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.10.XX.XXX  netmask 255.255.255.0  broadcast 10.10.XX.XXX
        inet6 fe80::aab2:d96e:d3ef:836d  prefixlen 64  scopeid 0x20<link>
        ether bX:XX:Xb:XX:Xe:aX  txqueuelen 1000  (Ethernet)
        RX packets 162  bytes 31128 (30.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 75  bytes 11385 (11.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
erpguy
  • 59
  • 1
  • 1
1

I had similar problem with Raspbian GNU/Linux 10 (buster). I made changes in wpa_supplicant.conf and run

# wpa_cli -i wlan0 reconfigure

But it did not work all the way.

# dhclient -v

made it work.

I found info at https://kb.isc.org/docs/isc-dhcp-44-manual-pages-dhclient

Output from

$ sudo dhclient -v
Internet Systems Consortium DHCP Client 4.4.1
Copyright 2004-2018 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/

Listening on LPF/wlan0/a0:f3:c1:26:04:9c
Sending on   LPF/wlan0/a0:f3:c1:26:04:9c
Listening on LPF/eth0/b8:27:eb:1f:ab:6e
Sending on   LPF/eth0/b8:27:eb:1f:ab:6e
Sending on   Socket/fallback
DHCPREQUEST for 192.168.7.28 on wlan0 to 255.255.255.255 port 67
DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 4
DHCPACK of 192.168.7.28 from 192.168.7.1
RTNETLINK answers: File exists
bound to 192.168.7.28 -- renewal in 1717 seconds.
RalfFriedl
  • 2,180
  • 2
  • 11
  • 12
Joni
  • 11
  • 1
1

You should run this command line to restart the network

/etc/init.d/networking restart

Darryl RN
  • 129
  • 4
0

EDIT 1:

I landed up on this answer with my Raspberry pi Zero W configured as a dual mode wifi and I wanted to change the wifi credentials (wifi router that wlan0 must connect to) by sharing them over the ap0 interface (which had a REST API hosted on it) with a mobile app.

The thing is I assumed that the accepted answer or any other answers will work in my case. But that was not the case.

So, for anyone who has landed here just like me, please follow the setup steps mentioned here.

Then, for a change in wifi connection without reboot, I am currently testing with 2 ways:

  1. wpa_cli -i wlan0 reconfigure
  2. sudo systemctl restart wpa_supplicant@wlan0.service

Once the tests are done, I will be updating it here.

thewebjackal
  • 151
  • 8
0

You can use the NetworkManager tool, which uses nmcli commands to setup a connection profile.

Install it using apt:

sudo apt-get install network-manager

Comment out wlan and Ethernet interfaces in /etc/network/interfaces.

Reboot the device.

Then use:

sudo nmcli device wifi con "SSID" password "PSK" 

to connect to a Wi-Fi network.

Darth Vader
  • 4,218
  • 24
  • 47
  • 70