====== Wi-Fi STA/AP Mode ====== ===== Introduction ===== This document mainly introduces the STA+AP mode of Wi-Fi. You'll learn how to open a hotspot while connected to the Internet. ===== System Configuration ===== ==== Upgrade System ==== Please make sure you use the latest image, if not please follow [[/products/sbc/common/configurations/upgrade-system|Upgrade The System]] to upgrade your system. ==== Configuration Instructions ==== Configure ''wlan0'' to ''STA'' mode, and ''wlan1'' to ''AP'' mode. === Add Wlan1 Interface === ```shell khadas@Khadas:~$ sudo iw phy phy0 interface add wlan1 type managed ``` Use ''ifconfig'' to check if ''wlan1'' has been added successfully: ```shell khadas@Khadas:~$ ifconfig wlan0: flags=4099 mtu 1500 ether 18:93:7f:a9:9d:0e txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 2 bytes 180 (180.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 wlan1: flags=4099 mtu 1500 ether 1a:93:7f:a9:9d:0e txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 ``` === Setup Wlan1 as a Hotspot === Setup ''wlan1'' as a hotspot, and allow automatic connections. == 2.4 GHz Frequency == We shall name our hotspot ''khadas_ap'', with password ''12345678''. ```shell sudo nmcli con add type wifi ifname wlan1 con-name Hostspot autoconnect yes ssid khadas_ap sudo nmcli con modify Hostspot 802-11-wireless.mode ap 802-11-wireless.band bg ipv4.method shared sudo nmcli con modify Hostspot wifi-sec.key-mgmt wpa-psk sudo nmcli con modify Hostspot wifi-sec.psk "12345678" sudo nmcli con modify Hostspot ipv4.addresses 192.168.2.20/24 sudo nmcli con modify Hostspot ipv4.gateway 192.168.2.1 sudo nmcli con up Hostspot ``` == 5 GHz Frequency == To setup a 5GHz network, you’ll need to use the channel argument. \\ We shall name our hotspot ''khadas_ap'', with password ''12345678''. ```shell sudo nmcli con add type wifi ifname wlan1 con-name Hostspot autoconnect yes ssid khadas_ap_5G sudo nmcli c modify Hostspot 802-11-wireless.mode ap 802-11-wireless.band a 802-11-wireless.channel 149 802-11-wireless.powersave 2 ipv4.method shared sudo nmcli con modify Hostspot wifi-sec.key-mgmt wpa-psk sudo nmcli con modify Hostspot wifi-sec.psk "12345678" sudo nmcli con modify Hostspot ipv4.addresses 192.168.2.20/24 sudo nmcli con modify Hostspot ipv4.gateway 192.168.2.1 sudo nmcli con up Hostspot ``` Use ''ifconfig'' to check if everything has been setup correctly: ```shell khadas@Khadas:~$ ifconfig wlan0: flags=4099 mtu 1500 ether 18:93:7f:a9:9d:0e txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 2 bytes 180 (180.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 wlan1: flags=4163 mtu 1500 inet 192.168.2.20 netmask 255.255.255.0 broadcast 192.168.2.255 inet6 fe80::2069:83c5:2e4c:2614 prefixlen 64 scopeid 0x20 ether 1a:93:7f:a9:9d:0e txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 18 bytes 1312 (1.3 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 ``` ===== Go Online! ===== Verify that wlan0 has a working internet connection: You need to connect Wi-Fi first. ```shell khadas@Khadas:~$ sudo ping -I wlan0 www.khadas.com PING td-balancer-dc11-60-161.wixdns.net (185.230.60.161) from 192.168.124.80 wlan0: 56(84) bytes of data. 64 bytes from 185.230.60.161 (185.230.60.161): icmp_seq=1 ttl=240 time=293 ms 64 bytes from 185.230.60.161 (185.230.60.161): icmp_seq=2 ttl=240 time=316 ms 64 bytes from 185.230.60.161 (185.230.60.161): icmp_seq=3 ttl=240 time=238 ms ... ``` Verify that ''wlan1'' can be used as a hotpot: * Name: 2.4G/''khadas_ap'', 5G/''khadas_ap_5G'' * Password:''12345678''