TheRemote / Ubuntu-Server-raspi4-unofficial

Ubuntu Server 18.04.4 Raspberry Pi 4 Image + Build Script (unofficial)
https://jamesachambers.com/raspberry-pi-4-ubuntu-server-desktop-18-04-3-image-unofficial/
Apache License 2.0
536 stars 93 forks source link

Raspberry is not properly connecting to wifi network #14

Closed jcgarciaca closed 5 years ago

jcgarciaca commented 5 years ago

Hi, I am using Release V6 and it works well. However, raspberry does not connect to wifi properly.

I added lines below to /etc/network/interfaces:

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

And /etc/wpa_supplicant/wpa_supplicant.conf is defined as follow:

network={
ssid="my-network-name"
psk="network-password"
proto=RSN
key_mgmt=WPA-PSK
pairwise=CCMP
auth_alg=OPEN
}

But after reboot the device does not connect to wifi.

I also tried with doing:

sudo wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf
sudo dhclient wlan0

After commands above, the raspberry receives an ip address but ping from/to other devices in same network does not get response. With ifconfig I get the address for wlan0 but it says <UP BROADCAST MULTICAST>. RUNNING does not appear for wlan0.

Am I missing anything else? Thank you.

yashiki2005 commented 5 years ago

Try this out. 1.Check that there are no extra wpa_supplicant processes with ps -ax | grep wpa 2.Edit /etc/wpa_supplicant/wpa_supplicant.conf and add "country = xx"(your country code,US represents USA) to the top of the file.

If the country code is not set by raspi-config etc., wifi is disabled by default after rpi3b.

jcgarciaca commented 5 years ago

Hi @yashiki2005

  1. I think there aren't extra wpa_supplicant processes, if I run the command you suggested I get:
    ubuntu@ubuntu:~$ ps -ax | grep wpa
    355 ?        Ss     0:00 /sbin/wpa_supplicant -s -B -P /run/wpa_supplicant.wlan0.pid -i wlan0 -D nl80211,wext -c /etc/wpa_supplicant/wpa_supplicant.conf -C /run/wpa_supplicant
    527 ?        Ss     0:00 /sbin/wpa_supplicant -u -s -O /run/wpa_supplicant
    790 pts/0    S+     0:00 grep --color=auto wpa
  2. I added country entry to /etc/wpa_supplicant/wpa_supplicant.conf. I tried with my country code as well as with US, but they did not work.

I noted that if I run sudo ifdown wlan0 && sudo ifup -v wlan0 then the raspberry gets a valid ip address and I can ping well, but I need to do it automatically at startup. So, I added that command to rc.local file, but still doesn't work.

yashiki2005 commented 5 years ago

Oh, I was misunderstood. To connect automatically, Ubuntu 18.04 or later uses netplan to generate a configuration file. Make sure /etc/netplan/ is empty (delete or move if there is a file), for example when using DHCP create /etc/netplan/raspberrypi-config.yaml with the following contents. Warning: Indentation is important for this file. If you make a mistake, you will get an error.

network:
  version: 2
  wifis:
    wlan0:
      dhcp4: true
      dhcp6: true
      access-points:
        “Your AP name”:
          password: “Your AP WPA password”

And "sudo netplan apply" netplan apply suceed, wifi will automatically connect after the next startup.

jcgarciaca commented 5 years ago

@yashiki2005 Thank you for your help!! I can automatically connect now.