RPI 5 on Ubuntu 24.04 (headless): Connect to WiFi / Mobile Hotspot

Introduction

In my free time, I enjoy tinkering with my home lab, exploring new projects and challenges. Recently, I decided to connect my Raspberry Pi 5 to a mobile hotspot—a seemingly straightforward task. However, it turned out not so smooth. In this post, I’ll walk you through how I resolved the error brcmfmac: brcmf_set_channel: set chanspec fail, reason -52 and successfully connected Raspberry Pi to a mobile hotspot.

Prerequisites

  • Raspberry Pi 5
  • Ubuntu 24.04 (headless)
  • Mobile phone with hotspot enabled
  • Access to a terminal or SSH connection
  • Mobile hotspot credentials (SSID and password)

Step 1: Create wpa_supplicant.conf

Create and configure the wpa_supplicant configuration file to connect to your mobile hotspot.

vi /etc/wpa_supplicant/wpa_supplicant.conf

Add the following content, replacing YourHotspotSSID, YourHotspotPassword, YourContryCode with your actual hotspot credentials.

country=YourContryCode
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="YourHotspotSSID"
    psk="YourHotspotPassword"
    key_mgmt=WPA-PSK
}

Step 2: Configure Netplan

Netplan is used to configure networking on Linux. Create a netplan configuration file.

ℹ️ netplan

Netplan is a utility for easily configuring networking on a linux system. You simply create a YAML description of the required network interfaces and what each should be configured to do. From this description Netplan will generate all the necessary configuration for your chosen renderer tool.

Netplan reads network configuration from /etc/netplan/*.yaml which are written by administrators, installers, cloud image instantiations, or other OS deployments. During early boot, Netplan generates backend specific configuration files in /run to hand off control of devices to a particular networking daemon.

Netplan currently works with these supported renderers: NetworkManager Systemd-networkd

vi /etc/netplan/01-iphone-hotspot-ap.yaml

Add the following configuration, substituting wlan0 with your wireless interface name.

network:
  version: 2
  renderer: networkd
  wifis:
    wlan0:
      dhcp4: yes
      dhcp6: yes
      access-points:
        "YourHotspotSSID":
          password: "YourHotspotPassword"

Apply the netplan configuration.

netplan generate
netplan apply --debug

Step 3: Restart wpa_supplicant

Restart the wpa_supplicant service to apply the new configuration.

systemctl restart wpa_supplicant

Step 4: Check Connection Status

Verify that your device is connected to the mobile hotspot using netplan status.

netplan status
or
ip link show | grep wlan0

🧯 Troubleshooting: Resolving brcmfmac: brcmf_set_channel: set chanspec fail, reason -52

If you encounter the error brcmfmac: brcmf_set_channel: set chanspec fail, reason -52, it may indicate issues with the wireless regulatory domain settings or interference from USB 3.0 devices.

Check Regulatory Domain:

Ensure the regulatory domain is set correctly.

iw reg get
iw reg set US  # Replace US with your country code

To make this persistent, edit the CRDA configuration file.

vi /etc/default/crda

Add or modify the following line:

REGDOMAIN=US

Update Firmware and Drivers:

Ensure you have the latest firmware and drivers.

apt update
apt install --reinstall linux-firmware
reboot

Conclusion

Connecting a headless Ubuntu 24.04 system to a mobile hotspot involves configuring wpa_supplicant and netplan correctly. By following the steps outlined above, you can establish a stable Wi-Fi connection, even in the face of potential issues like the brcmfmac: brcmf_set_channel: set chanspec fail, reason -52 error. Properly setting the regulatory domain and ensuring up-to-date firmware are key to resolving such problems.

issues to follow:

https://github.com/raspberrypi/linux/issues/6049 https://lore.kernel.org/all/99977c876429f33d8dbab18d7c3e71590585263b.camel@sipsolutions.net/T/ https://forums.raspberrypi.com/viewtopic.php?t=367466 https://github.com/home-assistant/operating-system/issues/3367

netplan code spippets:

https://github.com/canonical/netplan/tree/main/examples

Happy serfing 🏄 :)

netplan_status