04 WIFI
1 WIFI 模块概述
GM-3568JHF 开发板集成了 RTL8723DU 无线网络模块,提供了完整的 IEEE 802.11 b/g/n 无线网络连接功能。该模块通过 USB 接口与主控芯片连接,支持 2.4GHz 频段的无线通信,为开发板提供了灵活的无线网络接入能力。
1.1 RTL8723DU 模块技术规格
| 参数 | 规格 |
|---|---|
| 芯片型号 | Realtek RTL8723DU |
| 接口类型 | USB 2.0 |
| 无线标准 | IEEE 802.11 b/g/n |
| 工作频段 | 2.4GHz (2.412~2.484GHz) |
| 传输速率 | 最大 150Mbps (802.11n) |
| 调制方式 | OFDM, CCK, BPSK, QPSK, 16-QAM, 64-QAM |
| 天线配置 | 1T1R (单发单收) |
| 发射功率 | 最大 20dBm |
| 接收灵敏度 | -70dBm @ 150Mbps |
| 加密支持 | WEP, WPA/WPA2-PSK, WPA/WPA2-Enterprise |
1.2 性能指标
| 模式 | 最大速率 | 典型范围 | 功耗 |
|---|---|---|---|
| 802.11b | 11Mbps | 100m | 低 |
| 802.11g | 54Mbps | 50m | 中 |
| 802.11n | 150Mbps | 30m | 中高 |
2 WIFI 连接配置
开发板使用 RTL8723DU 模块,系统已默认适配好 WIFI 驱动和相关软件组件。
2.1 连接 WIFI
如图所示,找到系统右上角点击网络图标连接 WIFI 
使用 ifconfig 命令查看 ip 地址等信息
root@linaro-alip:/# ifconfig
···
wlx78228877b4a5: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.137.149 netmask 255.255.255.0 broadcast 192.168.137.255
inet6 fe80::d175:3cd1:73ca:ecc8 prefixlen 64 scopeid 0x20<link>
ether 78:22:88:77:b4:a5 txqueuelen 1000 (Ethernet)
RX packets 69 bytes 954099 (931.7 KiB)
RX errors 0 dropped 143 overruns 0 frame 0
TX packets 72 bytes 116372 (113.6 KiB)
TX errors 0 dropped 23 overruns 0 carrier 0 collisions 02.2 连通性测试
执行如下命令查看获取的 IP 地址,并通过 ping 命令测试开发板与 PC 机通信是否正常。 192.168.49.85 为 PC 实际的 IP 地址,请确保开发板与 PC 机在同一局域网内。
root@linaro-alip:/# ping 192.168.49.85 -I wlx78228877b4a5 -c 8
ping 192.168.49.85 -I wlx78228877b4a5 -c 8
PING 192.168.49.85 (192.168.49.85) from 192.168.137.149 wlx78228877b4a5: 56(84) bytes of data.
64 bytes from 192.168.49.85: icmp_seq=1 ttl=127 time=5.14 ms
64 bytes from 192.168.49.85: icmp_seq=2 ttl=127 time=3.66 ms
64 bytes from 192.168.49.85: icmp_seq=3 ttl=127 time=2.83 ms
64 bytes from 192.168.49.85: icmp_seq=4 ttl=127 time=2.81 ms
64 bytes from 192.168.49.85: icmp_seq=5 ttl=127 time=9.44 ms
64 bytes from 192.168.49.85: icmp_seq=6 ttl=127 time=2.77 ms
64 bytes from 192.168.49.85: icmp_seq=7 ttl=127 time=3.46 ms
64 bytes from 192.168.49.85: icmp_seq=8 ttl=127 time=3.09 ms
--- 192.168.49.85 ping statistics ---
8 packets transmitted, 8 received, 0% packet loss, time 7011ms
rtt min/avg/max/mdev = 2.771/4.150/9.442/2.128 ms2.3 TCP带宽测试
如下使用 iperf3 工具测试开发板与 PC 机的网络通信带宽。
服务端
在开发板上联网安装 iperf3 工具,执行如下命令:
root@linaro-alip:/# sudo apt update
root@linaro-alip:/# sudo apt install iperf3开发板做服务端,执行以下命令:
root@linaro-alip:/# iperf3 -s
-----------------------------------------------------------
Server listening on 5201 (test #1)
-----------------------------------------------------------客户端
windows 的 iperf3 工具可以在测试工具包中获取。
在 windows 系统中打开 powershell,进入 iperf3 工具所在路径下 windows 做客户端发送数据,执行以下命令:
.\iperf3.exe -c 192.168.137.149 // 192.168.137.149 为服务端 IP 地址2.4 测试结果
服务端
root@linaro-alip:/# iperf3 -s
-----------------------------------------------------------
Server listening on 5201 (test #1)
-----------------------------------------------------------
Accepted connection from 192.168.137.1, port 65396
[ 5] local 192.168.137.149 port 5201 connected to 192.168.137.1 port 65397
[ ID] Interval Transfer Bitrate
[ 5] 0.00-1.00 sec 4.88 MBytes 40.9 Mbits/sec
[ 5] 1.00-2.00 sec 5.40 MBytes 45.3 Mbits/sec
[ 5] 2.00-3.00 sec 5.22 MBytes 43.8 Mbits/sec
[ 5] 3.00-4.00 sec 5.36 MBytes 45.0 Mbits/sec
[ 5] 4.00-5.00 sec 5.14 MBytes 43.1 Mbits/sec
[ 5] 5.00-6.00 sec 5.22 MBytes 43.8 Mbits/sec
[ 5] 6.00-7.00 sec 5.40 MBytes 45.3 Mbits/sec
[ 5] 7.00-8.00 sec 5.12 MBytes 43.0 Mbits/sec
[ 5] 8.00-9.00 sec 5.38 MBytes 45.1 Mbits/sec
[ 5] 9.00-10.00 sec 5.24 MBytes 43.9 Mbits/sec
[ 5] 10.00-10.05 sec 266 KBytes 45.9 Mbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bitrate
[ 5] 0.00-10.05 sec 52.6 MBytes 43.9 Mbits/sec receiver
-----------------------------------------------------------客户端

3 命令行 WIFI 配置
3.1 使用 wpa_supplicant 连接 WIFI
1)扫描可用网络
# 启动 WIFI 接口
sudo ifconfig wlx78228877b4a5 up
# 扫描可用的 WIFI 网络
sudo iwlist wlx78228877b4a5 scan | grep ESSID
# 或使用 iw 命令
sudo iw dev wlx78228877b4a5 scan | grep SSID2)创建 wpa_supplicant 配置文件
# 创建配置文件
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
# 添加以下内容
ctrl_interface=/var/run/wpa_supplicant
ctrl_interface_group=0
update_config=1
country=CN
# WPA/WPA2-PSK 网络配置
network={
ssid="YourWiFiName"
psk="YourPassword"
key_mgmt=WPA-PSK
priority=1
}
# 开放网络配置
network={
ssid="OpenWiFi"
key_mgmt=NONE
priority=2
}
# WEP 网络配置
network={
ssid="WEPNetwork"
wep_key0="your_wep_key"
key_mgmt=NONE
wep_tx_keyidx=0
}3)连接 WIFI 网络
# 启动 wpa_supplicant
sudo wpa_supplicant -B -i wlx78228877b4a5 -c /etc/wpa_supplicant/wpa_supplicant.conf
# 获取 IP 地址
sudo dhclient wlx78228877b4a5
# 检查连接状态
wpa_cli -i wlx78228877b4a5 status3.2 NetworkManager 管理 WIFI
命令行工具 nmcli
# 查看 WIFI 状态
nmcli radio wifi
# 扫描 WIFI 网络
nmcli dev wifi list
# 连接 WIFI 网络
nmcli dev wifi connect "SSID" password "PASSWORD"
# 查看已保存的连接
nmcli connection show
# 断开 WIFI 连接
nmcli dev disconnect wlx78228877b4a5
# 删除已保存的连接
nmcli connection delete "SSID"4 WIFI 热点模式 (AP 模式)
4.1 安装 hostapd
sudo apt-get update
sudo apt-get install hostapd dnsmasq4.2 配置 hostapd
# 创建 hostapd 配置文件
sudo nano /etc/hostapd/hostapd.conf
# 添加以下内容
interface=wlx78228877b4a5
driver=nl80211
ssid=GM-3568JHF-AP
hw_mode=g
channel=7
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=12345678
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP4.3 配置 DHCP 服务
# 备份原配置
sudo cp /etc/dnsmasq.conf /etc/dnsmasq.conf.backup
# 编辑 dnsmasq 配置
sudo nano /etc/dnsmasq.conf
# 添加以下内容
interface=wlx78228877b4a5
dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h4.4 配置网络接口
# 设置静态 IP
sudo ifconfig wlx78228877b4a5 192.168.4.1 netmask 255.255.255.0
# 启用 IP 转发
echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward
# 配置 NAT 规则
sudo iptables -t nat -A POSTROUTING -o end0 -j MASQUERADE
sudo iptables -A FORWARD -i end0 -o wlx78228877b4a5 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i wlx78228877b4a5 -o end0 -j ACCEPT4.5 启动热点服务
# 启动 hostapd
sudo hostapd /etc/hostapd/hostapd.conf &
# 启动 dnsmasq
sudo systemctl start dnsmasq
# 检查服务状态
sudo systemctl status hostapd
sudo systemctl status dnsmasq5 故障排除
1)WIFI 模块无法识别
检查步骤:
# 检查 USB 设备
lsusb | grep Realtek
# 检查内核模块
lsmod | grep rtl
# 手动加载驱动
sudo modprobe rtl8xxxu
# 检查固件文件
ls /lib/firmware/rtlwifi/2)无法连接 WIFI 网络
可能原因和解决方案:
# 检查网络接口状态
ip link show wlx78228877b4a5
# 重启网络接口
sudo ifconfig wlx78228877b4a5 down
sudo ifconfig wlx78228877b4a5 up
# 检查 wpa_supplicant 日志
sudo journalctl -u wpa_supplicant
# 重新配置网络
sudo wpa_cli -i wlx78228877b4a5 reconfigure3)信号弱或连接不稳定
优化建议:
# 检查信号强度
iwconfig wlx78228877b4a5 | grep "Signal level"
# 扫描信道使用情况
sudo iwlist wlx78228877b4a5 scan | grep Frequency
# 更换信道(AP 模式)
sudo iwconfig wlx78228877b4a5 channel 6
# 调整发射功率
sudo iwconfig wlx78228877b4a5 txpower 204)网络速度慢
诊断和优化:
# 检查当前连接速率
iwconfig wlx78228877b4a5 | grep "Bit Rate"
# 检查网络拥塞
ping -c 10 8.8.8.8
# 使用 iperf3 测试带宽
iperf3 -c speedtest.server.com
# 优化 TCP 窗口大小
echo 'net.core.rmem_max = 16777216' >> /etc/sysctl.conf
echo 'net.core.wmem_max = 16777216' >> /etc/sysctl.conf5)热点模式问题
常见问题解决:
# 检查 hostapd 状态
sudo systemctl status hostapd
# 查看 hostapd 日志
sudo journalctl -u hostapd
# 检查防火墙设置
sudo iptables -L
# 重启相关服务
sudo systemctl restart hostapd
sudo systemctl restart dnsmasq