17. 板载wifi

17.1. wifi配置前提

将J5处的跳线帽插上使得wifi芯片工作。

wifi接线

17.2. 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配置

17.3. 常用的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工具用法

17.4. 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,连接外网的接口是eth0,创建一个热点,名字为npi_wifi,密码为123456789, 运行以下脚本,并传入相关参数。

./create_ap wlan0 eth0 npi 123456789 --no-virt

终端出现如下信息,说明创建成功,若在创建wifi失败,请重启开发板后重试。

root@npi:~/ebf-tools-src/create_ap# ./create_ap wlan0 eth0 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