Auto connect to WiFi on boot on Yocto (Raspberry Pi 3B) - dhirajbennadi/ECEN5713-FinalProjectResources GitHub Wiki
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.
- 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
- Understanding of the working of adding secret keys to repositories.
All the above knowledge are covered as part of the course learnings
- 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.
-
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)
-
Make sure this layer is built as part of the core-image.
-
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"
-
Provide the commit id of the repository which hosts the wpa_supplicant.conf for the variable : SRCREV = "commit id" Example: SRCREV = "34f1f8d47093752b285e53ccfde582714af3e37a"
-
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"
-
In the
do_install
method perform the following steps- Provide adequate permission using the command :
install -m 0755 -d ${D}${bindir}
Here {bindir} refers to the location /usr/bin/
- 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 ofS
in that case would look :S = "${WORKDIR}/git/wifi-autoconnect/
- Provide adequate permission to the init.d directory using the command :
install -m 0755 -d ${D}${sysconfdir}/init.d
- 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
- Provide adequate permission using the command :
-
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
- Test the working using ping command to any host
Example:
ping www.google.com
-
Use a general template for the .bb file as used in the assignments
-
The .bb file should contain the following command to be part of the initialization on boot Command:
inherit update-rc.d
-
Once the image is built, check if the wpa_supplicant.conf is available in the rootfs section.
Location: /usr/bin/wpa_supplicant.conf
-
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
-
Check if the wifi-startup-script.sh is running by including some echo statements in the script
- 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.
- The above method will work for all versions of Raspberry Pi or any linux based embedded system.