24. 板载wifi

24.1. wifi模块跳帽说明

  • wifi与sd卡共用核心板引出的一个sdio接口,进行配置wifi之前,要确认开发板是从eMMC或者nandflash启动, 不能在从sd卡启动时用wifi。

  • 修改两个跳线帽①与②为下图中连接方式。①号跳帽在右侧竖时为给wifi模块供电,②号跳帽为连接SD1_CLK信号到wifi模块,取板子左上角或者其他暂不用的跳帽盖。(开发板出厂时默认隔开②号,SD1_CLK信号只给sd卡处,第一款底板只需要换盖①)

wifi接线

24.2. wifi模块型号说明

1.如果底板wifi模块为AP6236,可以继续后面的wifi连接步骤。

2.如果底板wifi模块为AP6212,使用命令cat /etc/issue 查看镜像,如果镜像为最新版本(ebf_debian_2021_06 或以上),可以继续后面的wifi连接步骤。

否则,需要先将开发板插入能上网的网线,执行sudo apt update与sudo apt upgrade。 如果手边没有网线,可以下载下面云盘两个deb包文件,放入U盘,然后将文件拷贝到开发板内,然后执行命令安装deb包,可以网上搜索Linux挂载U盘与命令安装deb包操作。

链接:https://pan.baidu.com/s/167aHmo7ByssZm_q4MyBSlw 提取码:qqv3

或者 在 http://doc.embedfire.com/products/link/zh/latest/linux/ebf_i.mx6ull.html 综合资料百度云资料链接->3-Debian镜像->ebf_debian_202x->USB烧录文件夹,重新烧录一下最新镜像。

24.3. wifi连接步骤

  1. 在终端执行sudo fire-config命令,选择“Network”项。 如下图:

wifi配置
  1. 选择“WiFi config”项,如下图:

wifi配置
  1. 选择“Onboard Enable/Disable the on board WiFi of npi-Pro board”,如下图所示

wifi配置
  1. 出现以下界面选择 “Enable” 。

wifi配置

使能成功之后将会提示WiFi已经使能。

wifi配置
  1. 回到fire-config的首界面,选择“Finish”

wifi配置

提示是否重启系统,选择“Yes”

wifi配置

6. 重启系统之后,重新选择进入“WiFi config”界面 系统重启后,继续在系统中执行sudo fire-config命令,选择“Network -> WiFi config -> WiFi scan”项, 系统会扫描搜索所有周围的无线网络,并在界面显示wifi的名字和信号强弱. 如果暂时没有识别到wifi,多尝试几次扫描。 如下图:

wifi配置
  1. 选择 “Network -> WiFi config -> WiFi connect”,输入wifi名称

wifi配置

输入wifi密码

wifi配置
  1. 最后返回到首界面选择“Finish”,并使用ifconfig查看网络连接状态,出现如下界面显示wifi连接成功。

wifi配置

24.4. 常用的wifi常用操作命令

sudo ifconfig wlan0 down                关闭wifi使用

sudo ifconfig wlan0 up                  启动wifi使用

wpa_cli -i wlan0 status                 查看当前连接状态

wpa_cli -i wlan0 list_networks          列出输入过的网络

wpa_cli -i wlan0 disconnect      AP1   断开当前连接AP1名wifi(CURRENT)

wpa_cli -i wlan0 reconnect      AP1   重新连接AP1或其他

wpa_cli -i wlan0 select_network  AP2   切换连接list_networks里面的AP2 wifi

wpa_cli -i wlan0 remove_network  AP1   删除不用的AP1(删除前断开)

wpa_cli -i wlan0 save_config     保存配置(如执行完上述删除操作,需要执行保存,否则重启后重新使用上次配置)

更多操作可以网上搜索wpa_cli工具用法

24.5. WiFi AP模式

  1. 安装相关工具

sudo apt update
sudo apt install wireless-tools hostapd dnsmasq iw git
  1. 下载脚本

依次执行以下指令

sudo apt install git

git clone  https://github.com/Embedfire-imx6/ebf-tools-src.git

cd ebf-tools-src/create_ap/

chmod +x create_ap
  1. 配置环境

使用systemctl status autowifi查看WiFi自动连接服务

root@npi:~# systemctl status autowifi
● autowifi.service - =booting wifi ...
Loaded: loaded (/lib/systemd/system/autowifi.service; enabled; vendor preset:
Active: active (running) since Tue 2021-03-02 10:21:24 CST; 1min 36s ago
Process: 623 ExecStart=/bin/bash /opt/scripts/boot/autowifi.sh (code=exited, s
    Tasks: 2 (limit: 388)
Memory: 1004.0K
CGroup: /system.slice/autowifi.service
        ├─653 wpa_supplicant -B -c /etc/wpa_supplicant/wpa_supplicant.conf -i
        └─678 udhcpc -b -i wlan0

Mar 02 10:21:20 npi bash[623]: udhcpc: started, v1.30.1
Mar 02 10:21:21 npi udhcpc[668]: wlan0: deconfigured
Mar 02 10:21:21 npi bash[623]: udhcpc: sending discover
Mar 02 10:21:23 npi bash[623]: udhcpc: sending discover
Mar 02 10:21:23 npi bash[623]: udhcpc: sending select for 192.168.0.61
Mar 02 10:21:23 npi bash[623]: udhcpc: lease of 192.168.0.61 obtained, lease tim
Mar 02 10:21:24 npi bash[623]: ip: RTNETLINK answers: File exists
Mar 02 10:21:24 npi udhcpc[677]: wlan0: bound: IP=192.168.0.61/255.255.255.0 rou
Mar 02 10:21:24 npi su[658]: pam_unix(su:session): session closed for user root
Mar 02 10:21:24 npi systemd[1]: Started =booting wifi ....

关闭WiFi自动连接服务

systemctl disable autowifi

执行命令sudo update-alternatives --config iptables,输入数字1

root@npi:/home/debian/ebf-tools-src/create_ap# sudo update-alternatives --config iptables
There are 2 choices for the alternative iptables (providing /usr/sbin/iptables).

Selection    Path                       Priority   Status
------------------------------------------------------------
* 0            /usr/sbin/iptables-nft      20        auto mode
1            /usr/sbin/iptables-legacy   10        manual mode
2            /usr/sbin/iptables-nft      20        manual mode

Press <enter> to keep the current choice[*], or type selection number: 1
update-alternatives: using /usr/sbin/iptables-legacy to provide /usr/sbin/iptables (iptables) in manual mode
root@npi:/home/debian/ebf-tools-src/create_ap#
  1. 运行脚本

假设wifi接口为wlan0,连接外网的接口是eth1,创建一个热点,名字为npi_wifi,密码为123456789, 运行以下脚本,并传入相关参数。

#以热点名称npi,密码123456789为例
./create_ap wlan0 eth1 npi 123456789 --no-virt

终端出现如下信息,说明创建成功

root@npi:~/ebf-tools-src/create_ap# ./create_ap wlan0 eth1 npi 123456789 --no-virt
Config dir: /tmp/create_ap.wlan0.conf.angbAubQ
PID: 1198
command failed: Input/output error (-5)
[ 2030.385168] [dhd-wlan0] wl_android_wifi_on : in g_wifi_on=0
[ 2031.789838] [dhd] dhd_conf_read_config : Ignore config file /lib/firmware/bcm/AP6236/Wi-Fi/config.txt
[ 2031.799704] [dhd] dhd_conf_set_path_params : Final fw_path=/lib/firmware/bcm/AP6236/Wi-Fi/fw_bcm43436b0.bin
[ 2031.811048] [dhd] dhd_conf_set_path_params : Final nv_path=/lib/firmware/bcm/AP6236/Wi-Fi/nvram_ap6236.txt
[ 2031.822085] [dhd] dhd_conf_set_path_params : Final clm_path=/lib/firmware/bcm/AP6236/Wi-Fi/clm_bcm43436b0.blob
[ 2031.833326] [dhd] dhd_conf_set_path_params : Final conf_path=/lib/firmware/bcm/AP6236/Wi-Fi/config.txt
[ 2032.071716] [dhd] dhd_conf_set_txglom_params : txglom_mode=multi-desc
[ 2032.081340] [dhd] dhd_conf_set_txglom_params : txglomsize=36, deferred_tx_len=0
[ 2032.090616] [dhd] dhd_conf_set_txglom_params : txinrx_thres=128, dhd_txminmax=-1
[ 2032.099353] [dhd] dhd_conf_set_txglom_params : tx_max_offset=0, txctl_tmo_fix=300
[ 2032.108213] [dhd] dhd_conf_get_disable_proptx : fw_proptx=1, disable_proptx=-1
[ 2032.195122] [dhd] dhd_conf_set_country : set country CN, revision 0
[ 2032.209100] [dhd] dhd_conf_set_country : Country code: CN (CN/0)
[ 2032.225268] [dhd] CONFIG-ERROR) dhd_conf_set_intiovar : ampdu_mpdu setting failed -29
[ 2032.233274] [dhd-wlan0] wl_android_wifi_on : Success
Sharing Internet using method: nat
hostapd command-line interface: hostapd_cli -p /tmp/create_ap.wlan0.conf.angbAubQ/hostapd_ctrl
Configuration file: /tmp/create_ap.wlan0.conf.angbAubQ/hostapd.conf
rfkill: Cannot open RFKILL control device
[ 2032.744618] [dhd-wlan0] wl_cfg80211_del_station : Disconnect STA : 66:66:3a:66:66:3a scb_val.val 3
Using interface wlan0 with hwaddr 28:ed:e0:75:3c:9e and ssid "npi"
[ 2032.842184] [dhd-wlan0] wl_cfg80211_set_channel : netdev_ifidx(5), chan_type(1) target channel(1)
[ 2032.907914] [dhd-wlan0] wl_cfg80211_bcn_bringup_ap : Creating AP with sec=wpapsk/mfpn/0x46
[ 2032.922593] [dhd-wlan0] wl_iw_event : Link UP with 28:ed:e0:75:3c:9e
[ 2032.929155] [dhd-wlan0] wl_ext_iapsta_event : [A] Link up w/o creating? (etype=16)
[ 2032.946892] [dhd-wlan0] wl_notify_connect_status_ap : AP/GO Link up
wlan0: interface state UNINITIALIZED->ENABLED
wlan0: AP-ENABLED

24.6. 常见问题

24.6.1. wifi自动连接失败

fire-config使能wifi会同时使能wifi自动连接服务,如果账号密码错误或者信号不良等其他原因导致wifi无法连接,则会出现下面图片情况。

wifi_auto_fail.png

出现以上情况需要先关闭wifi,防止其信息输出影响后续操作,执行以下命令

#关闭wifi
sudo ifconfig wlan0 down

#如果需要重新开启则使用以下命令
sudo ifconfig wlan0 up

然后确认账号密码是否正确,wifi的账号密码保存在/etc/wpa_supplicant/wpa_supplicant.conf中

#打开wifi账号密码配置文件
sudo vi /etc/wpa_supplicant/wpa_supplicant.conf

确认账号密码是否正确,如果是正确的但连不上,就把下面部分删除

network={
    ssid="wifi账号"
    psk="wifi密码"
    priority=1
}

然后重新用fire-config连接wifi,或者试试连手机热点。

24.6.2. 无法找到wifi无线接口

如果出现下面这种情况,则可能是没有使能wifi或者wifi俩个跳帽没有接上,请重新使能以及确认跳帽连接。

wifi_no_wireless.jpg

24.6.3. 无法扫描到wifi信号

如果没有扫描到wifi信号,请先确认板卡的wifi型号,如果是AP6236,请多扫几次,每次搜索完毕都请进入输账号密码选项尝试连接wifi。

如果是AP6212型号,需要确认镜像日期,使用命令cat /etc/issue 查看镜像,如果镜像为最新版本(ebf_debian_2021_06 或以上),请多扫几次,每次搜索完毕都请进入输账号密码选项尝试连接wifi,否则,需要先将开发板插入能上网的网线,执行sudo apt update与sudo apt upgrade,更新系统再尝试。