Khadas Docs

Amazing Khadas, always amazes you!

User Tools

Site Tools


products:sbc:vim4: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:vim4:applications:wifi-sta-ap-mode [2023/02/17 11:08]
hyphop
products:sbc:vim4:applications:wifi-sta-ap-mode [2025/02/19 02:32] (current)
jacobe
Line 1: Line 1:
-====== VIM4 Wi-Fi STA/AP Mode ======+====== VIM4 Wi-Fi STA/AP Mode Configuration ======
  
-How to setup the Wi-Fi working on STA+AP mode at the same time.+===== 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:
  
-Configure ''wlan0'' to ''STA'' mode, and ''wlan1'' to ''AP'' mode.+STA+AP Mode: ''wlan0'' as STA (connects to existing Wi-Fi) + ''wlan1'' as AP (creates hotspot)
  
 +ETH+AP Mode: ''eth0'' as Ethernet uplink + ''wlan1'' as AP (//Note: Not available on Edge2 devices//)
  
-===== Setup Wlan1 as a Hotspot =====+===== Prerequisites =====
  
-Setup ''wlan1'' as a hotspot.+Root privileges required
  
-==== 2.4 GHz Frequency ====+Ensure wireless interfaces are properly identified:
  
-For example, the following commands will create AP configuration named ''Hostspot'' on interface ''wlan1'', with SSID ''khadas_ap_2.4G'', ''2.4GHz'' band, ''channel 1'', ''WPA2-PSK'' security, ''CCMP encryption'' and passphrase ''12345678''.+STA interface''wlan0''
  
 +AP interface: ''wlan1''
  
-```shell +Ethernet interface: ''eth0'' (not present on Edge2)
-sudo nmcli con add type wifi ifname wlan1 mode ap con-name Hostspot ssid khadas_ap_2.4G +
-sudo nmcli con modify Hostspot 802-11-wireless.band bg +
-sudo nmcli con modify Hostspot 802-11-wireless.channel 1 +
-sudo nmcli con modify Hostspot 802-11-wireless-security.key-mgmt wpa-psk +
-sudo nmcli con modify Hostspot 802-11-wireless-security.proto rsn +
-sudo nmcli con modify Hostspot 802-11-wireless-security.group ccmp +
-sudo nmcli con modify Hostspot 802-11-wireless-security.pairwise ccmp +
-sudo nmcli con modify Hostspot 802-11-wireless-security.psk 12345678 +
-sudo nmcli con modify Hostspot ipv4.method shared +
-sudo nmcli con up Hostspot +
-```+
  
-==== 5 GHz Frequency ====+===== Configuration Script Usage ===== 
 +Run the script with root privileges: 
 + 
 +``` 
 +sudo khadas_ap.sh 
 +```
  
-For example, the following commands will create AP configuration named ''Hostspot'' on interface ''wlan1'', with SSID ''khadas_ap_5G'', ''5GHz'' band, ''channel 149'', ''WPA2-PSK'' security, ''CCMP encryption'' and passphrase ''12345678''. 
  
-```shell +==== Main Menu Options ====
-sudo nmcli con add type wifi ifname wlan1 mode ap con-name Hostspot ssid khadas_ap_5G +
-sudo nmcli con modify Hostspot 802-11-wireless.band a +
-sudo nmcli con modify Hostspot 802-11-wireless.channel 149 +
-sudo nmcli con modify Hostspot 802-11-wireless-security.key-mgmt wpa-psk +
-sudo nmcli con modify Hostspot 802-11-wireless-security.proto rsn +
-sudo nmcli con modify Hostspot 802-11-wireless-security.group ccmp +
-sudo nmcli con modify Hostspot 802-11-wireless-security.pairwise ccmp +
-sudo nmcli con modify Hostspot 802-11-wireless-security.psk 12345678 +
-sudo nmcli con modify Hostspot ipv4.method shared +
-sudo nmcli con up Hostspot+
 ``` ```
 +========================================
 + WiFi Configuration Tool v1.0
 +========================================
 +1. STA+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)
  
-Use ''ifconfig'' to check if everything has been setup correctly:+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
  
-```shell +3.Stop All Services - Terminates AP/DHCP/NAT services 
-$ ifconfig + 
-wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500 +4.Exit - Quit the script 
-        inet 192.168.31.219  netmask 255.255.254.0  broadcast 192.168.31.255 + 
-        inet6 fda2:a164:f7fb:4b66:1466:7d8b:b8e3:49a  prefixlen 64  scopeid 0x0<global> +==== Configuration Steps ==== 
-        inet6 fe80::6eed:eaf2:6ba8:5cd7  prefixlen 64  scopeid 0x20<link> + 
-        inet6 fda2:a164:f7fb:4b66:a823:4487:8651:4d61  prefixlen 64  scopeid 0x0<global> +Select operation mode from menu 
-        ether 10:2c:6b:10:d5:0a  txqueuelen 1000  (Ethernet+ 
-        RX packets 4271  bytes 3725737 (3.7 MB) +For AP modes (1 or 2)
-        RX errors 0  dropped 13  overruns 0  frame 0 + 
-        TX packets 1663  bytes 321613 (321.6 KB) +  * Enter SSID for hotspot 
-        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0+  * Set password (WPA2-PSK required
 +  * Script automatically handles: 
 +  * Hostapd configuration 
 +  * Dnsmasq DHCP setup 
 +  * IP forwarding 
 +  * iptables NAT rules 
 + 
 +===== Verification ===== 
 +Check interface status after configuration:
  
-wlan1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500 
-        inet 10.42.0.1  netmask 255.255.255.0  broadcast 10.42.0.255 
-        inet6 fe80::6342:2516:ef70:23a0  prefixlen 64  scopeid 0x20<link> 
-        ether 12:2c:6b:10:d5:0a  txqueuelen 1000  (Ethernet) 
-        RX packets 1569  bytes 299041 (299.0 KB) 
-        RX errors 0  dropped 0  overruns 0  frame 0 
-        TX packets 3241  bytes 3693502 (3.6 MB) 
-        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0 
 ``` ```
 +ifconfig wlan0 && ifconfig wlan1
 +```
 +Verify internet connectivity (STA+AP mode):
  
-===== Go Online! =====+``` 
 +ping -I wlan0 google.com 
 +``` 
 +Test hotspot access:
  
-Verify that ''wlan0'' has a working internet connection:+SSID: [Your configured SSID] 
 + 
 +Password: [Your set password] 
 + 
 +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
  
-<WRAP info > 
-You need to connect Wi-Fi first. 
 </WRAP> </WRAP>
 +===== Technical Details =====
 +
 +IP Configuration:
 +
 +  * AP Static IP: 192.168.43.1/24
 +  * DHCP Range: 192.168.43.2-254
 +  * DNS: Google DNS (8.8.8.8) via 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:
  
-```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 
-... 
 ``` ```
 +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_2.4G'', 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: 2023/02/17 11:08 by hyphop