概述

上一课中我们介绍如何用Console Cable远程登录Pi,本课将在上一课基础上,通过Console Cable远程登录Pi后在命令行模式下,配置wifi网络。

所需物料

Raspberry Pi Zero/W or Pi2/Pi3(焊接好排针)

Console Cable

USB转Micro USB电源线

5V/2A or 5V/2.5A USB电源适配器(可选)

Config WiFi

登录Pi

参考lesson 3登录远程Pi

To scan for WiFi networks, use the command  sudo  iwlist wlan0  scan

This will list all available WiFi networks, along with other useful information

At the prompt, enter the following command:

sudo  nano  /etc/network/interface

In the nano text editor, you’ll see something like this:

 
 
  1. # interfaces(5) file used by ifup(8) and ifdown(8)
  2. # Please note that this file is written to be used with dhcpcd
  3. # For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'
  4. # Include files from /etc/network/interfaces.d:
  5. source-directory /etc/network/interfaces.d
  6. auto lo
  7. iface lo inet loopback
  8. iface eth0 inet manual
  9. allow-hotplug wlan0
  10. iface wlan0 inet manual
  11.     wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
  12. allow-hotplug wlan1
  13. iface wlan1 inet manual
  14.     wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

That’s the very basic configuration that governs your Pi’s Ethernet connect (indicated by the eth0 portion). We need to add on a very minor bit to enable the Wi-Fi dongle. Use the arrow keys to move down below the existing entry and add the following lines:

 
 
  1. auto lo
  2. iface lo inet loopback
  3. iface eth0 inet dhcp
  4. allow-hotplug wlan0
  5. auto wlan0
  6. iface wlan0 inet dhcp
  7.         wpa-ssid "wifi-ssid"
  8.         wpa-psk "wifi-password"

wifi-ssid:wifi’s name

wifi-password:wifi’s password

 

Once you’ve annotated the file, press CTRL+X to save the file and exit the nano editor. At the prompt again, enter the following command:

sudo reboot

When the device finishes rebooting, it should automatically connect to the Wi-Fi node.

At the command prompt, enter the following command to check if the wifi is connected:

ifconfig  wlan0

可以看到pi已经连接上了wifi,并且分配到一个IP(192.168.1.120)

Leave a Reply

WordPress spam blocked by CleanTalk.
Bombax Theme designed by itx
"