Configure connection to wireless network

Step 1 - Add systemd as your service manager

To enable systemd as a service manager it has to be added to your distribution level. Open golemos.conf in your distro folder and ensure that systemd and wifi are added to your distro features.

DISTRO_FEATURES += " systemd wifi"

It is also recommended to add sysvinit as a considered distro feature.

DISTRO_FEATURES_BACKFILL_CONSIDERED += "sysvinit"

At the end add systemd as a init manager.

VIRTUAL-RUNTIME_init_manager = "systemd"
VIRTUAL-RUNTIME_initscripts = "systemd-compat-units"

Step 2 - Add driver for wireless network card

Inside your core-packagegroup add following package to ensure that the appropriate driver is installed.

linux-firmware-rpidistro-bcm43430

Step 3 - Add instructions to default systemd_%.bb

Inside recipes-core folder create bbappend file to original recipe and add custom instructions.

mkdir -p ../meta-golemos/recipes-core/systemd/
touch ../meta-golemos/recipes-core/systemd/systemd_%.bbappend
PACKAGECONFIG_append = " networkd resolved"

This line will enable proper configuration of systemd.

Note

This step in not necessary but it will ensure that proper packages are installed on system.

Step 4 - Append instructions to systemd-conf_%.bb

In order to configure network devices, you have to create custom instructions, which will be appended to original systemd-conf_%.bb recipe. Create custom recipe in recipes-core folder.

mkdir -p ../meta-golemos/recipes-core/systemd-conf/files/
touch ../meta-golemos/recipes-core/systemd-conf/systemd-conf_%.bbappend

Inside this file place this instructions.

FILESEXTRAPATHS_prepend := "${THISDIR}/files:"

SRC_URI += " \
    file://wlan.network \
"

FILES_${PN} += " \
    ${sysconfdir}/systemd/network/wlan.network \
"

do_install_append() {
    install -d ${D}${sysconfdir}/systemd/network
    install -m 0644 ${WORKDIR}/wlan.network ${D}${sysconfdir}/systemd/network
}

Next step will be to create configuration file.

touch ../meta-golemos/recipes-core/systemd-conf/files/wlan.network

Place in it lines as follows.

[Match]
Name=wlan0
KernelCommandLine=!nfsroot

[Network]
DHCP=v4

[DHCPv4]
UseHostname=false

Step 5 - Enable WIFI

To the base package group inside connectivity section add package called wpa-supplicant. This will ensure that it is installed on system. For further configuration you have to create custom recipe.

Create recipe and appropriate folder for custom wpa-supplicant recipe.

mkdir -p ../meta-golemos/recipes-connectivity/wpa-supplicant/files/
touch ../meta-golemos/recipes-connectivity/wpa-supplicant/wpa-supplicant_%.bbappend

Inside this file place this instructions.

FILESEXTRAPATHS_prepend := "${THISDIR}/files:"

SRC_URI += "file://wpa_supplicant-nl80211-wlan0.conf"

SYSTEMD_AUTO_ENABLE = "enable"
SYSTEMD_SERVICE_${PN}_append = " wpa_supplicant-nl80211@wlan0.service "

do_install_append () {
    install -d ${D}${sysconfdir}/wpa_supplicant/
    install -D -m 600 ${WORKDIR}/wpa_supplicant-nl80211-wlan0.conf ${D}${sysconfdir}/wpa_supplicant/

    install -d ${D}${sysconfdir}/systemd/system/multi-user.target.wants/
    ln -s ${systemd_system_unitdir}/wpa_supplicant@.service ${D}${sysconfdir}/systemd/system/multi-user.target.wants/wpa_supplicant-nl80211@wlan0.service
}

Note

This configuration will auto enable wpa_supplicant on system boot. To disable this delete line with link in do_install_append and change enable to disable in SYSTEMD_AUTO_ENABLE variable.

If you are connected to the network you wish to connect device you can create configuration file by running

wpa_passphrase "YOUR_SSID" >  ../meta-golemos/recipes-connectivity/wpa-supplicant/files/wpa_supplicant-nl80211-wlan0.conf

In other situations you can manually create file and place inside them this configuration lines.

touch ../meta-golemos/recipes-connectivity/wpa-supplicant/files/wpa_supplicant-nl80211-wlan0.conf
ctrl_interface=/var/run/wpa_supplicant
ctrl_interface_group=0
update_config=1

network={
        ssid="Network SSID"
        psk="Network PASSWORD"
        proto=RSN
        key_mgmt=WPA-PSK
}

Summary

After all this steps you can compile your image and test if your device is connected to desired wireless network. This configurations is for DHCP.

Your layer structure after this steps should look like this.

../meta-golemos
├── COPYING.MIT
├── README
├── conf
│   ├── bblayers.conf.sample
│   ├── conf-notes.txt
│   ├── distro
│   │   └── golemos.conf
│   ├── layer.conf
│   └── local.conf.sample
├── recipes-connectivity
│   └── wpa-supplicant
│       ├── files
│       │   └── wpa_supplicant-nl80211-wlan0.conf
│       └── wpa-supplicant_%.bbappend
├── recipes-core
│   ├── images
│   │   ├── datalogger-dev-image.bb
│   │   ├── datalogger-extended-image.bb
│   │   └── datalogger-image.bb
│   ├── packagegroups
│   │   ├── datalogger-base-packagegroup.bb
│   │   ├── datalogger-core-packagegroup.bb
│   │   ├── datalogger-dev-packagegroup.bb
│   │   └── datalogger-extended-packagegroup.bb
│   ├── systemd
│   │   └── systemd_%.bbappend
│   └── systemd-conf
│       ├── files
│       │   └── wlan.network
│       └── systemd-conf_%.bbappend
└── recipes-example
    └── example
        └── example_0.1.bb