Auto connect to WiFi on boot on Yocto (Raspberry Pi 3B) - dhirajbennadi/ECEN5713-FinalProjectResources GitHub Wiki

Overview

This page contains the details to auto connect to a known wifi network on boot

The following page outlines the procedure to connect to WiFi using Yocto build system for a Raspberry Pi board. The implementation steps are generic irrespective of the board version.

Wifi Configuration

Prerequiste knowledge

  1. Understanding of the working of getting files from a remote github repository and using them as part of the build process with the help of bitbake (.bb) files
  2. Understanding of the working of adding secret keys to repositories.

All the above knowledge are covered as part of the course learnings

Copy of files on boot

  1. Host a github repository with the file wpa_supplicant.conf and a shell script (eg: wifi-startup-script.sh ) to copy the wpa_supplicant.conf file (/etc/wpa_supplicant.conf ) and shell script at the following location (etc/init.d/wifi-startup-script.sh) The wpa_supplicant.conf file generally has the following content
ctrl_interface=/var/run/wpa_supplicant
ctrl_interface_group=0
update_config=1

network={
  ssid="YOUR_SSID"
  psk="YOUR_PSWD"
  proto=RSN
  key_mgmt=WPA-PSK
  pairwise=CCMP
  auth_alg=OPEN
}

Replace the ssid and psk with your local network details.

  1. Create a layer (meta-layer) in the Yocto Repository to host the bitbake (.bb) file for the wifi-setup Example: wifi-autoconnect (layer) wifi-autoconnect.bb (bitbake file)

  2. Make sure this layer is built as part of the core-image.

  3. Provide the ssh link of the github repository which hosts the wpa_supplicant.conf file for the variable : SRC_URI = "link"

    Example: SRC_URI = "git://[email protected]/dhirajbennadi/aesd-final-project.git;protocol=ssh;branch=main"

  4. Provide the commit id of the repository which hosts the wpa_supplicant.conf for the variable : SRCREV = "commit id" Example: SRCREV = "34f1f8d47093752b285e53ccfde582714af3e37a"

  5. Create a template in the bitbake file for including the wifi-startup-script.sh to be run on boot.

    General Template:

INITSCRIPT_PACKAGES     = "${PN}"
INITSCRIPT_NAME_${PN}   = "wifi-startup-script.sh"
INITSCRIPT_PARAMS_${PN} = "default"
  1. In the do_install method perform the following steps

    1. Provide adequate permission using the command : install -m 0755 -d ${D}${bindir}

    Here {bindir} refers to the location /usr/bin/

    1. Copy the wpa_supplicant.conf from the remote repository to the {bindir} using the command: install -m 0755 ${S}/wpa_supplicant.conf ${D}${bindir}/

    The S over here refers the source location (github repository). For better organization use folder structure. The value of S in that case would look : S = "${WORKDIR}/git/wifi-autoconnect/

    1. Provide adequate permission to the init.d directory using the command : install -m 0755 -d ${D}${sysconfdir}/init.d
    2. Copy to the start-up script from the remote repository to the init.d using the command: install -m 0755 ${S}/wifi-startup-script.sh ${D}${sysconfdir}/init.d
  2. The start-up script would have the following commands

#!/bin/sh

echo "WiFi Autoconnect Script is Running"

ifdown wlan0

cp /usr/bin/wpa_supplicant.conf  /etc/wpa_supplicant.conf

ifup wlan0

The commands would copy the wpa_supplicant.conf from /usr/bin to /etc/ which the wifi interface will use to connect to the wifi

  1. Test the working using ping command to any host Example: ping www.google.com

General Checks

  1. Use a general template for the .bb file as used in the assignments

  2. The .bb file should contain the following command to be part of the initialization on boot Command: inherit update-rc.d

  3. Once the image is built, check if the wpa_supplicant.conf is available in the rootfs section.

    Location: /usr/bin/wpa_supplicant.conf

  4. Once the image is built, check if the wifi-startup-script.sh is available in the rootfs section

    Location: /etc/init.d/wifi-startup-script.sh

  5. Check if the wifi-startup-script.sh is running by including some echo statements in the script

Advantages

  1. The idea can to extended to create multiple such start-up scripts and bitbakes files for each of the packages and use the same steps as mentioned above and getting them running on boot.
  2. The above method will work for all versions of Raspberry Pi or any linux based embedded system.
⚠️ **GitHub.com Fallback** ⚠️