Linux WiFi Setup¶
This is a step-by-step guide for connecting to a WPA/WPA2 WiFi network from the Linux command line.
Note
The WiFi support must be enabled in your image first — see WiFi/BT Guide.
The tools used are:
wpa_supplicant- connects to a WPA/WPA2 networkiw- WiFi tasks such as scanning for access pointsip- enabling/disabling devices and general network interface informationping- testing the connection
1. Find the WiFi device¶
ip link show
The result should look something like this:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue
4: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast qlen 1000
6: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop qlen 1000
link/ether 00:07:80:a9:50:e5 brd ff:ff:ff:ff:ff:ff
The example above shows one physical WiFi card, designated as wlan0.
2. Bring up the device¶
Check the flags of the device — UP must be present in the first line:
ip link show wlan0
6: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop qlen 1000
If it is not up, bring it up:
ip link set wlan0 up
3. Scan for networks¶
iw wlan0 scan
wlan0 Scan completed :
Cell 01 - Address: D3:4D:B3:3F:E0:03
ESSID:"Test AP"
Frequency:2.437 GHz (Channel 6)
Quality=26/40 Signal level=-21 dBm
Encryption key:on
IE: IEEE 802.11i/WPA2 Version 1
Authentication Suites (1) : PSK
[...]
The two important pieces of information are the SSID (Test AP above) and the security protocol
(WPA2-PSK here), which determines how to connect.
4. Connect¶
This is a 3-step process:
As
karo-image-minimalmounts the rootfs read-only by default, re-mount it writeable:mount -o remount,rw /Generate a
wpa_supplicantconfiguration containing the pre-shared key (PSK/passphrase) for the network:wpa_passphrase "Test AP" >> /etc/wpa_supplicant.confType in the passphrase and press enter.
wpa_passphrasetakes the SSID as its single argument; its output is appended to/etc/wpa_supplicant.conf(you may freely choose name and location of the file):cat /etc/wpa_supplicant.confnetwork={ ssid="Test AP" #psk="testtest" psk=4dfe1c985520d26a13e932bf0acb1d4580461dd854ed79ad1a88ec221a802061 }Run
wpa_supplicantwith the new configuration:wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant.confHint
When using the Laird USB dongle, use the supplicant from the Laird layer instead — see WiFi/BT Guide.
5. Obtain an IP address¶
dhcpcd wlan0
Verify the assigned address:
ip addr show wlan0
6: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq qlen 1000
link/ether 00:07:80:a9:50:e5 brd ff:ff:ff:ff:ff:ff
inet 192.168.43.128/24 brd 192.168.43.255 scope global wlan0
6. Test the connection¶
ping www.karo-electronics.com
PING www.karo-electronics.com (83.169.24.12): 56 data bytes
64 bytes from 83.169.24.12: seq=0 ttl=47 time=97.929 ms
[...]
--- www.karo-electronics.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss