开发板 在虚拟机中 通过 wifi 联网

这篇博客记录开发板通过wifi连网的过程。

材料:

  1. 灵眸科技 EASY EAI开发板
  2. 电源线
  3. ADB调试线
  4. 开发板WIFI接收器

0、虚拟机必须连网(其实也不是必须):

https://blog.csdn.net/weixin_45824067/article/details/131904810

1、通过ADB调试线连接,进入开发板

首先给开发板上电,将WIFI接收器、ADB调试线连接好

 VMare Workstation软件右下角第四个图标亮起来的时候,表示ADB调试线连接好了

 

进入EASY-EAI编译环境:

~/develop_environment/run.sh

 新开一个终端,进入开发板:

2、/etc/wpa_supplicant.conf中加入你要连接的wifi信息

不要 修改 /etc/netpaln/99_config.yaml,用netplan来配置网络,我尝试了一晚上都没成功

还是按照这个博主的做法做

开发板linux连接wifi的方法(一)_wsx_iot的博客-CSDN博客

首先修改 /etc/wpa_supplicant.conf 文件内容,只修改该文件 network= 后面的内容即可

network={
	ssid="wifi名字"
	psk="wifi密码"
	scan_ssid=1
        proto=WPA RSN
        key_mgmt=WPA-EAP WPA-PSK IEEE8021X NONE
        pairwise=TKIP CCMP
        group=CCMP TKIP WEP104 WEP40
}

然后执行如下脚本,使得 wlan0 被分配 ip地址

#关闭有线连接
ifconfig eth0 down
#打开无线连接
ifconfig wlan0 up
#杀死以前配置进程
killall wpa_supplicant
#启动wifi配置,使文件生效
wpa_supplicant -B -Dwext -iwlan0 -c/etc/wpa_supplicant.conf
#启动有点慢,等一下启动完毕
sleep 3s
#杀死以前的dhcp进程
killall udhcpc
#启动dhcp获取ip
udhcpc -b -i wlan0
#static ip
#ifconfig wlan0 192.168.134.250 netmask 255.255.255.0
#route add default gw 192.168.134.1

关于上述脚本最后一步,如果你的开发板没有udhcpc命令,也可以这样获取ip

sudo dhclient wlan0

3、修改DNS服务器(用于解析域名)

修改/etc/resolv.conf 文件如下  这个只能一次生效

# This file is managed by man:systemd-resolved(8). Do not edit.
#
# This is a dynamic resolv.conf file for connecting local clients to the
# internal DNS stub resolver of systemd-resolved. This file lists all
# configured search domains.
#
# Run "resolvectl status" to see details about the uplink DNS servers
# currently in use.
#
# Third party programs must not access this file directly, but only through the
# symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way,
# replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.

#nameserver 127.0.0.53
#options edns0
nameserver 8.8.8.8
nameserver 114.114.114.114 

其实这两个DNS服务器我是 虚拟机联网 那篇博客中的DNS设置

修改 /etc/systemd/resolved.conf,主要是最后两行

https://www.cnblogs.com/zlslch/p/5842237.html

其实/etc/resolv.conf  只是 /etc/systemd/resolved.conf 的软链接,所以应该直接修改 /etc/systemd/resolved.conf,来设置DNS服务器用以解析域名

#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See resolved.conf(5) for details

[Resolve]
#DNS=
#FallbackDNS
#Domains=
#LLMNR=no
#MulticastDNS=no
#DNSSEC=no
#DNSOverTLS=no
#Cache=yes
#DNSStubListener=yes
nameserver 8.8.8.8
nameserver 114.114.114.114

执行下述命令,从缓冲中保存修改

sync

3、尝试退出板子,再进去,看看是否能板子联网

root@EASY-EAI-NANO:/# exit      解释:退出与板子
logout
developer@EASY-EAI-Develop:~$ adb shell   解释: 重新进入板子
root@EASY-EAI-NANO:/# ping www.baidu.com
PING www.a.shifen.com (14.119.104.189) 56(84) bytes of data.
64 bytes from 14.119.104.189 (14.119.104.189): icmp_seq=1 ttl=54 time=36.0 ms
64 bytes from 14.119.104.189 (14.119.104.189): icmp_seq=2 ttl=54 time=39.9 ms
64 bytes from 14.119.104.189 (14.119.104.189): icmp_seq=3 ttl=54 time=48.2 ms
64 bytes from 14.119.104.189 (14.119.104.189): icmp_seq=4 ttl=54 time=45.6 ms
64 bytes from 14.119.104.189 (14.119.104.189): icmp_seq=5 ttl=54 time=38.9 ms
64 bytes from 14.119.104.189 (14.119.104.189): icmp_seq=6 ttl=54 time=43.7 ms
64 bytes from 14.119.104.189 (14.119.104.189): icmp_seq=7 ttl=54 time=125 ms
^C
--- www.a.shifen.com ping statistics ---
8 packets transmitted, 7 received, 12.5% packet loss, time 7003ms
rtt min/avg/max/mdev = 36.039/53.836/124.576/29.134 ms
root@EASY-EAI-NANO:/# ping www.baidu.com
PING www.a.shifen.com (14.119.104.254) 56(84) bytes of data.
64 bytes from 14.119.104.254 (14.119.104.254): icmp_seq=1 ttl=54 time=28.2 ms
64 bytes from 14.119.104.254 (14.119.104.254): icmp_seq=2 ttl=54 time=33.8 ms
64 bytes from 14.119.104.254 (14.119.104.254): icmp_seq=3 ttl=54 time=37.5 ms
64 bytes from 14.119.104.254 (14.119.104.254): icmp_seq=4 ttl=54 time=38.5 ms
64 bytes from 14.119.104.254 (14.119.104.254): icmp_seq=5 ttl=54 time=41.1 ms
64 bytes from 14.119.104.254 (14.119.104.254): icmp_seq=6 ttl=54 time=43.5 ms
^C
--- www.a.shifen.com ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5009ms
rtt min/avg/max/mdev = 28.192/37.087/43.462/4.972 ms

可以发现,退出板子之后再进入,板子依旧是连网的,终于做到了,呜呜呜

4、查看开发板被分配的ip地址

SHH登录开发板,必须知道开发板的IP地址

root@EASY-EAI-NANO:/# ifconfig
wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 此处是Ip地址 netmask 255.255.255.0  broadcast 此处为广播地址
        inet6 fe80::ba13:32ff:fe8f:4716  prefixlen 64  scopeid 0x20<link>
        ether b8:13:32:8f:47:16  txqueuelen 1000  (Ethernet)
        RX packets 2166  bytes 103083 (103.0 KB)
        RX errors 0  dropped 39  overruns 0  frame 0
        TX packets 372  bytes 35756 (35.7 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

搞了一晚上终于让开发板连网了,作为小白,很感谢文中所引用几篇博客的作者!!!

猜你喜欢

转载自blog.csdn.net/weixin_45824067/article/details/131904810