以下操作基于Raspberry Pi OS 32位系统Raspberry Pi OS with desktop进行
- 使用ifconfig检查wlan0是否开启,如果没有开启执行以下命令
sudo iwconfig wlan0 power on
sudo ifconfig wlan0 up
- 修改WiFi的名称和密码
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
在配置文件中添加如下内容:
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={ssid="ap" key_mgmt=WPA-PSK psk="12345678" priority=1
}
- ssid:WiFi的名称
- key_mgmt:WiFi的加密方式,如果没有密码则key_mgmt=NONE
- psk:WiFi的密码
- priority:树莓派支持配置多个WiFi,priority决定系统优先连接哪个WiFi,值越大优先级越高
- 重启系统
sudo reboot
- 查看获取到的ip地址
ifconfig
成功后得到如下内容:
wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500inet 192.168.1.150 netmask 255.255.255.0 broadcast 192.168.1.255inet6 fe80::397f:133d:aac4:81a6 prefixlen 64 scopeid 0x20<link>ether b8:27:eb:b0:2c:69 txqueuelen 1000 (Ethernet)RX packets 3316 bytes 567847 (554.5 KiB)RX errors 0 dropped 0 overruns 0 frame 0TX packets 1200 bytes 83554 (81.5 KiB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0