11

My new Raspberry Pi 3 is great, but I am facing one difficulty: my router is in the lounge (one floor down), and my laptop has no Ethernet port. Since I am using SSH to control the Pi, I always have to connect it to the router via an Ethernet cable. Also, I can't use the GPIO pins from my room as I have to be close to the router.

Is there any way to automatically connect my Pi to wifi right after booting up? In other words, I want to power up the Pi without any network connection, and it should automatically connect to the wifi.

One thing I tried was to edit the /etc/wpa-supplicant/wpa-supplicant.conf file to include only the SSID and PSK of my home's wifi connection. This did not make the Pi connect automatically to wifi.

Any help would be greatly appreciated!

2

3 Answers 3

12

Add

auto wlan0
iface wlan0 inet dhcp 
wpa-ssid {ssid}
wpa-psk  {password}

To /etc/network/interfaces. then use the command sudo dhclient wlan0.

Or try option #2 from Here

3
  • 1
    Could you elaborate the purpose behind this? Will it auto-connect whenever connection is lost?
    – not2savvy
    Commented Feb 28, 2018 at 11:06
  • 1
    @not2savvy it will connect whenever a connection is available. If you can, setup wifi from the Pi's gui. That will automatically remember the network, and is much simpler.
    – jath03
    Commented Mar 1, 2018 at 15:51
  • you can't run sudo dhclient wlan0 if your raspberry pi can't even connect to the wifi and you can't ssh into it. This defeats the purpose of having it connect to Wifi automatically in the first place.
    – Mehdi
    Commented Jan 24, 2022 at 15:26
1

It should connect automatically after you set up wifi on the pi's GUI. To do this you need to connect a monitor and keyboard to the pi then boot up on the pi(not over SSH). Type startx to enter the GUI, then there should be a icon for wifi. Click on it, find your network, and it should remember the network, even after you reboot.

1
  • 1
    I did that using a remote desktop application, VNC. I suppose this should have the same effect as connecting a screen. The problem still persists; the Pi doesn't automatically connect to wifi. Is there perhaps a script I could run to do this?
    – abruzzi26
    Commented Jul 27, 2016 at 7:13
1

I had a similar problem with Pi 3. For unknown reason wicd (gui that is used) did not work. After struggles - and I know it is not an ideal solution - I created a script:

!/bin/bash
for  (( i=0;i<999999999; i++)); do
 echo $i '.' test=============================================
 ME=`iwconfig wlan0 | grep ESSID | awk -F\" '{print $2}' `
 echo i ... I am in :  $ME

 A=`sudo iwlist wlan0 scan | grep  ESSID `
 echo $A
 echo $A | grep MyWifiAP >/dev/null

 if [ "$?" = "0" ]; then
 if [ "$ME" != "MyWifiAP" ]; then
  echo ! ... seeing MyWifiAP ... killing previous
  sudo pkill wpa_supplicant
  echo W ... connecting to MyWifiAP
  sudo wpa_supplicant -Dnl80211 -iwlan0 -c /etc/wpa_supplicant/MyWifiAP.conf >/dev/null &
  sleep 1
  else
  echo i ... already in MyWifiAP
  sleep 1
  fi
 fi
done

Your AP is MyWifiAP and you must create file /etc/wpa_supplicant/MyWifiAP.conf that contains your access data.

The script resides wherever, it can be run on background from /etc/rc.local (nohup + &). VERIFY that it works with wpa_supplicant before you use it. A mistake in rc.local could lead to a necessity to edit your SD card to revert changes back.

I think this was some error in debian distribution or systemd...

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.