<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Raine Virta</title>
    <description>The latest articles on DEV Community by Raine Virta (@raine).</description>
    <link>https://dev.to/raine</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F132568%2F9bb377c0-c67b-498c-8c3b-77c607d1784c.jpeg</url>
      <title>DEV Community: Raine Virta</title>
      <link>https://dev.to/raine</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/raine"/>
    <language>en</language>
    <item>
      <title>Connecting to a wireless network on Ubuntu Server 21.04 and Raspberry Pi 4</title>
      <dc:creator>Raine Virta</dc:creator>
      <pubDate>Sat, 22 May 2021 19:35:49 +0000</pubDate>
      <link>https://dev.to/raine/connecting-to-a-wireless-network-on-ubuntu-server-21-04-and-raspberry-pi-4-3eeo</link>
      <guid>https://dev.to/raine/connecting-to-a-wireless-network-on-ubuntu-server-21-04-and-raspberry-pi-4-3eeo</guid>
      <description>&lt;p&gt;Problems solved here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Connecting to a wireless network on Ubuntu Server 21.04 and Raspberry Pi 4&lt;/li&gt;
&lt;li&gt;Prefer 5 GHz WiFi when 2.4 GHz exists with the same SSID&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Add the wifi network configuration to &lt;code&gt;/etc/netplan/50-cloud-init.yaml&lt;/code&gt;. Looks like this file is generated by netplan somehow and there's probably a better way but this persists through restarts so it's good enough for now.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;vim /etc/netplan/50-cloud-init.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;network:
    ethernets:
        eth0:
            dhcp4: true
            optional: true
    version: 2
    wifis:
        wlan0:
            optional: true
            dhcp4: true
            access-points:
                "{{WIFI NAME}}":
                    password: "{{WIFI PASSWORD}}"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Raspberry Pi should connect to the network after restarting.&lt;/p&gt;

&lt;p&gt;Next problem: It is preferring the 2.4 GHz wifi over 5 GHz. Or at least it was for me.&lt;/p&gt;

&lt;p&gt;We need to hardcode the basic service set identifier (BSSID) of 5 GHz network in the above configuration.&lt;/p&gt;

&lt;p&gt;Find out the BSSID for the 5 GHz network:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Will not return results without sudo&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;iwlist wlan0 scan
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the output, look for an entry like this for the 5 Ghz network:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Cell 01 - Address: 2C:FD:A1:DD:D3:34
          Channel:36
          Frequency:5.18 GHz (Channel 36)
          Quality=56/70  Signal level=-54 dBm
          Encryption key:on
          ESSID:"{{WIFI NAME}}"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The thing after &lt;code&gt;Address:&lt;/code&gt; is the BSSID.&lt;/p&gt;

&lt;p&gt;Add it to &lt;code&gt;/etc/netplan/50-cloud-init.yaml&lt;/code&gt; on same indentation level as &lt;code&gt;password&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;network:
    ethernets:
        eth0:
            dhcp4: true
            optional: true
    version: 2
    wifis:
        wlan0:
            optional: true
            dhcp4: true
            access-points:
                "{{WIFI NAME}}":
                    password: "{{WIFI PASSWORD}}"
                    bssid: "2C:FD:A1:DD:D3:34"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Done. Restart and Raspberry Pi should connect to the 5 Ghz network.&lt;/p&gt;

</description>
      <category>raspberrypi</category>
      <category>ubuntu</category>
    </item>
  </channel>
</rss>
