Khadas Docs

Amazing Khadas, always amazes you!

User Tools

Site Tools


products:sbc:common:applications:wifi-sta-ap-mode

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
products:sbc:common:applications:wifi-sta-ap-mode [2022/07/08 05:22]
frank
products:sbc:common:applications:wifi-sta-ap-mode [2025/02/19 02:32] (current)
jacobe
Line 1: Line 1:
-====== Wi-Fi STA/AP Mode ======+====== VIMs Wi-Fi STA/AP Mode Configuration ======
  
-===== Introduction =====+===== Download ===== 
 +``` 
 +wget https://raw.githubusercontent.com/khadas/fenix/refs/heads/master/archives/filesystem/common/usr/local/bin/khadas_ap.sh 
 +sudo chmod 777 khadas_ap.sh 
 +sudo mv khadas_ap.sh /usr/local/bin 
 +``` 
 +We will add it in next version and users could also rebuild the image. 
 +===== Overview ===== 
 +This guide explains how to configure dual Wi-Fi mode using the provided script (v1.0), enabling simultaneous operation in:
  
-This document mainly introduces the STA+AP mode of Wi-Fi. You'll learn how to open a hotspot while connected to the Internet.+STA+AP Mode: ''wlan0'' as STA (connects to existing Wi-Fi) + ''wlan1'' as AP (creates hotspot)
  
-===== System Configuration =====+ETH+AP Mode: ''eth0'' as Ethernet uplink + ''wlan1'' as AP (//Note: Not available on Edge2 devices//)
  
-==== Upgrade System ====+===== Prerequisites =====
  
-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.+Root privileges required
  
-==== Configuration Instructions ====+Ensure wireless interfaces are properly identified:
  
-Configure ''wlan0'' to ''STA'' mode, and ''wlan1'' to ''AP'' mode.+STA interface: ''wlan0''
  
-=== Add Wlan1 Interface ===+AP interface: ''wlan1''
  
-```shell +Ethernet interface: ''eth0'' (not present on Edge2)
-khadas@Khadas:~$ sudo iw phy phy0 interface add wlan1 type managed +
-```+
  
-Use ''ifconfig'' to check if ''wlan1'' has been added successfully:+===== Configuration Script Usage ===== 
 +Run the script with root privileges:
  
-```shell +``` 
-khadas@Khadas:~$ ifconfig  +sudo khadas_ap.sh 
-wlan0: flags=4099<UP,BROADCAST,MULTICAST>  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<UP,BROADCAST,MULTICAST>  mtu 1500 + 
-        ether 1a:93:7f:a9:9d:0e  txqueuelen 1000  (Ethernet) +==== Main Menu Options ===
-        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) + WiFi Configuration Tool v1.0 
-        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0+======================================== 
 +1STA+AP Mode 
 +2. ETH+AP Mode 
 +3. Stop All Services 
 +4. Exit 
 +======================================== 
 +Please select an option [1-4]:
 ``` ```
 +1.STA+AP Mode - Recommended for most devices: creates NAT forwarding between ''wlan0'' (STA) and ''wlan1'' (AP), requires existing Wi-Fi connection on ''wlan0'', hotspot IP: ''192.168.43.1'' (DHCP range: 192.168.43.2-254)
  
-=== Setup Wlan1 as a Hotspot ===+2.ETH+AP Mode - For devices with Ethernet port: creates NAT forwarding between ''eth0'' and ''wlan1''//Not functional on Edge2 devices// (no eth0 interface). Same hotspot IP range as STA+AP mode
  
-Setup ''wlan1'' as a hotspot, and allow automatic connections.+3.Stop All Services - Terminates AP/DHCP/NAT services
  
 +4.Exit - Quit the script
  
-== 2.4 GHz Frequency ==+==== Configuration Steps ====
  
-We shall name our hotspot ''khadas_ap'', with password ''12345678''. +Select operation mode from menu 
-```shell + 
-$ sudo nmcli con add type wifi ifname wlan1 con-name Hostspot autoconnect yes ssid khadas_ap +For AP modes (1 or 2): 
-$ 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 +  * Enter SSID for hotspot 
-$ sudo nmcli con modify Hostspot wifi-sec.psk "12345678" +  * Set password (WPA2-PSK required) 
-$ sudo nmcli con modify Hostspot ipv4.addresses 192.168.2.20/24 +  * Script automatically handles: 
-$ sudo nmcli con modify Hostspot ipv4.gateway 192.168.2.1 +  * Hostapd configuration 
-$ sudo nmcli con up Hostspot+  * Dnsmasq DHCP setup 
 +  * IP forwarding 
 +  * iptables NAT rules 
 + 
 +===== Verification ===== 
 +Check interface status after configuration: 
 + 
 +``` 
 +ifconfig wlan0 && ifconfig wlan1
 ``` ```
-== 5 GHz Frequency ==+Verify internet connectivity (STA+AP mode):
  
-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 
-$ 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 
 ``` ```
 +ping -I wlan0 google.com
 +```
 +Test hotspot access:
  
-Use ''ifconfig'' to check if everything has been setup correctly: +SSID[Your configured SSID]
-```shell +
-khadas@Khadas:~$ ifconfig +
-wlan0: flags=4099<UP,BROADCAST,MULTICAST>  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+
  
-wlan1flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500 +Password[Your set password]
-        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<link> +
-        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! =====+Client IP range: 192.168.43.2-254
  
 +===== Important Notes =====
 +<WRAP important>
 +Edge2 Device Limitations:
 +
 +No Ethernet interface (''eth0'')
 +
 +ETH+AP Mode (Option 2) will not function
 +
 +Use STA+AP Mode (Option 1) exclusively
  
-Verify that wlan0 has a working internet connection: 
-<WRAP info > 
-You need to connect Wi-Fi first. 
 </WRAP> </WRAP>
-```shell +===== Technical Details ===== 
-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 wlan056(84) bytes of data. +IP Configuration
-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 +  * AP Static IP: 192.168.43.1/24 
-64 bytes from 185.230.60.161 (185.230.60.161): icmp_seq=3 ttl=240 time=238 ms +  * DHCP Range: 192.168.43.2-254 
-...+  * DNSGoogle DNS (8.8.8.8via port 5353 
 + 
 +Security
 + 
 +  * WPA2-PSK encryption 
 +  * CCMP/AES cipher mandatory 
 + 
 +Default channel: 6 
 + 
 +Dependencies: 
 + 
 +  * dnsmasq (DHCP server
 +  * hostapd (AP configuration) 
 +  * iptables (NAT forwarding) 
 + 
 +===== Troubleshooting ===== 
 + 
 +AP Not Appearing: 
 + 
 +Confirm ''wlan1'' interface exists 
 + 
 +Check for conflicting services: 
 ``` ```
 +ps aux | grep -E 'hostapd|dnsmasq'
 +```
 +No Internet Access:
  
-Verify that ''wlan1'' can be used as a hotpot: +Verify STA connection:
-  * Name: 2.4G/''khadas_ap'', 5G/''khadas_ap_5G'' +
-  * Password:''12345678''+
  
 +```
 +iwconfig wlan0
 +```
 +Check NAT rules:
 +
 +```
 +iptables -t nat -L -n -v
 +```
 +DHCP Failures:
 +
 +Confirm dnsmasq running:
 +
 +```
 +systemctl status dnsmasq
 +```
Last modified: 2022/07/08 05:22 by frank