3

How do I configure wifi to automatically without rebooting?

For example, like phone, when my phone detect wifi that has connected, it connect the wifi network automatically without reboot and any commands.
How to do same thing in raspberry pi4? I using raspi 4 with portable powerbank as a portable machine, so my raspi 4 is always on. I already setup wifi and make connect wifi automatically after startup.
But when the wifi stop suddenly then after that restart wifi, raspi4 does not re-connect wifi.

I suppose that need daemon for wifi detection and certification.
How to connect wifi automatically without any commands and reboot?

Additional information:

I using this OS: Ubuntu19.10(Not raspbian)

gatorback
  • 637
  • 1
  • 5
  • 16
KiYugadgeter
  • 131
  • 4

2 Answers2

2

Just download and install a Raspbian Buster image as described at Installing operating system images. Don't use NOOBS, instead flash a Rasbian image. Then enable WiFi as described at Setting up a Raspberry Pi headless and all is done. Connect and reconnect to an access point is doing out of the box on a default Raspbian installation.

On my RasPi I see this in journalctl if the remote access point switches off:

Jan 15 19:31:03 raspberrypi dhcpcd[647]: wlan0: carrier lost
Jan 15 19:31:03 raspberrypi dhcpcd[647]: wlan0: deleting address fe80::dfd3:f31e:1538:b9b6
Jan 15 19:31:03 raspberrypi avahi-daemon[497]: Withdrawing address record for fe80::dfd3:f31e:1538:b9b6 on wlan0.
Jan 15 19:31:03 raspberrypi avahi-daemon[497]: Leaving mDNS multicast group on interface wlan0.IPv6 with address fe80::dfd3:f31e:1538:b9b6.
Jan 15 19:31:03 raspberrypi avahi-daemon[497]: Interface wlan0.IPv6 no longer relevant for mDNS.
Jan 15 19:31:03 raspberrypi avahi-daemon[497]: Withdrawing address record for 192.168.50.194 on wlan0.
Jan 15 19:31:03 raspberrypi avahi-daemon[497]: Leaving mDNS multicast group on interface wlan0.IPv4 with address 192.168.50.194.
Jan 15 19:31:03 raspberrypi avahi-daemon[497]: Interface wlan0.IPv4 no longer relevant for mDNS.
Jan 15 19:31:03 raspberrypi dhcpcd[647]: wlan0: deleting route to 192.168.50.0/24
Jan 15 19:31:03 raspberrypi dhcpcd[647]: wlan0: deleting default route via 192.168.50.1

If the access point comes up again wpa_supplicant will reconnect automagically by itself:

Jan 15 19:32:59 raspberrypi dhcpcd[647]: wlan0: carrier acquired
Jan 15 19:32:59 raspberrypi dhcpcd[647]: wlan0: IAID 32:01:db:ed
Jan 15 19:32:59 raspberrypi dhcpcd[647]: wlan0: adding address fe80::dfd3:f31e:1538:b9b6
Jan 15 19:32:59 raspberrypi avahi-daemon[497]: Joining mDNS multicast group on interface wlan0.IPv6 with address fe80::dfd3:f31e:1538:b9b6.
Jan 15 19:32:59 raspberrypi avahi-daemon[497]: New relevant interface wlan0.IPv6 for mDNS.
Jan 15 19:32:59 raspberrypi avahi-daemon[497]: Registering new address record for fe80::dfd3:f31e:1538:b9b6 on wlan0.*.
Jan 15 19:32:59 raspberrypi dhcpcd[647]: wlan0: soliciting an IPv6 router
Jan 15 19:33:00 raspberrypi dhcpcd[647]: wlan0: rebinding lease of 192.168.50.194
Jan 15 19:33:00 raspberrypi dhcpcd[647]: wlan0: probing address 192.168.50.194/24
Jan 15 19:33:05 raspberrypi dhcpcd[647]: wlan0: leased 192.168.50.194 for 3600 seconds
Jan 15 19:33:05 raspberrypi avahi-daemon[497]: Joining mDNS multicast group on interface wlan0.IPv4 with address 192.168.50.194.
Jan 15 19:33:05 raspberrypi avahi-daemon[497]: New relevant interface wlan0.IPv4 for mDNS.
Jan 15 19:33:05 raspberrypi avahi-daemon[497]: Registering new address record for 192.168.50.194 on wlan0.IPv4.
Jan 15 19:33:05 raspberrypi dhcpcd[647]: wlan0: adding route to 192.168.50.0/24
Jan 15 19:33:05 raspberrypi dhcpcd[647]: wlan0: adding default route via 192.168.50.1
Jan 15 19:33:12 raspberrypi dhcpcd[647]: wlan0: no IPv6 Routers available
Ingo
  • 40,606
  • 15
  • 76
  • 189
1

You can follow this link to find the answer. However, I followed the procedure below on my Raspberry Pi 3B+. It would work for your Raspberry Pi 4B.

Change lines below on /etc/network/interfaces:

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp

The wpa-roam is the key and allows the wlan0 to self-heal. Feel free to set a static IP address.


UPDATE:
The solution above may not work on the newer version of Raspbian which released after Raspbian 9 Stretch. Thus follow the instructions below:

1. Install wicd-curses:

sudo apt-get install wicd-curses  

2. To start the wicd-curses:

sudo wicd-curses  

Then you would see a config menu like it:

enter image description here

If you get a message saying that no networks detected, press P (must be capital so use Shift+P) and type in wlan0 in the wireless interface field and press F10 to save.

3. Press Shift+R to refresh the list.
4. Choose the SSID and hit the Enter button.
5. Enter the password and make the "Automatically connect to this network" checked.

enter image description here

6. Hit the F10 to save.

M. Rostami
  • 4,235
  • 1
  • 15
  • 34