上回说到如何驱动树莓派的 WiFi 芯片,这回就来讲讲如何用其连接家里的 WiFi 上网。
顺便更新下,Buildroot 2022.05-rc1 版本中,树莓派编译 WiFi 驱动,要使能下面选项:
→ Target packages → Hardware handling → Firmware → brcmfmac-sdio-firmware-rpi → brcmfmac-sdio-firmware-rpi-wifi
用法非常简单,修改配置文件
# cat /etc/wpa_supplicant.conf
network={
ssid="TP-LINK"
psk="xxxx"
}
连接
# wpa_supplicant -B -d -i wlan0 -c /etc/wpa_supplicant.conf
[ 792.734336] IPv6: ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready
查看 IP
# ifconfig wlan0
wlan0 Link encap:Ethernet HWaddr B8:27:EB:DF:E9:A1
inet6 addr: fe80::ba27:ebff:fedf:e9a1/64 Scope:Link
inet6 addr: 240e:3a1:1834:4ad0:ba27:ebff:fedf:e9a1/64 Scope:Global
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:14 errors:0 dropped:1 overruns:0 frame:0
TX packets:9 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1752 (1.7 KiB) TX bytes:982 (982.0 B)
并未获得 IPv4 地址,那就手动获取一下
# udhcpc -i wlan0
udhcpc: started, v1.35.0
udhcpc: broadcasting discover
udhcpc: broadcasting select for 192.168.31.40, server 192.168.31.1
udhcpc: lease of 192.168.31.40 obtained from 192.168.31.1, lease time 43200
deleting routers
adding dns 192.168.31.1
#
# ifconfig wlan0
wlan0 Link encap:Ethernet HWaddr B8:27:EB:DF:E9:A1
inet addr:192.168.31.40 Bcast:192.168.31.255 Mask:255.255.255.0
inet6 addr: fe80::ba27:ebff:fedf:e9a1/64 Scope:Link
inet6 addr: 240e:3a1:1834:4ad0:ba27:ebff:fedf:e9a1/64 Scope:Global
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:33 errors:0 dropped:3 overruns:0 frame:0
TX packets:11 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:5069 (4.9 KiB) TX bytes:1714 (1.6 KiB)
联网测试
# ping www.baidu.com
PING www.baidu.com (180.101.49.11): 56 data bytes
64 bytes from 180.101.49.11: seq=0 ttl=54 time=9.273 ms
64 bytes from 180.101.49.11: seq=1 ttl=54 time=9.059 ms
64 bytes from 180.101.49.11: seq=2 ttl=54 time=9.440 ms
64 bytes from 180.101.49.11: seq=3 ttl=54 time=9.057 ms
OK