分类: C/C++
2013-11-22 17:16:15
朋友又拿来个RaspberryPi, 用来换走配置了BMP085测温传感器的另一个, 而新的这个要用来调试Element14.com的摄像头.
于是下载Raspbain, image到SD卡上, 再搬出朋友拿来的显示器来配WIFI...不对, 干嘛还要用显示器呢...
上次用显示器, fgsj1122按照'标准流程'配置了WIFI, 很是麻烦(视频线不好找啊..), 后来某天拿着Pi上下翻转时(专业动作, 请勿模仿), 突然发现 -- RaspberryPi上不是还有个标准的Ethernet接口吗?!
所以呢, 无显示情况下配置RaspberryPi的WiFi实际很简单 -- 通过有线网络, 配置无线网络.
找根网线, 把RaspberryPi连接到路由器上, 再通过路由器配置页面获得其有线网卡的IP地址. 有了这个IP就可以SSH到RaspberryPi上配置其无线WiFi了. 过程如下:
1. 获得有线网卡的IP地址
RaspberryPi的Host名称就是raspberrypi, 好认又好记啊..
2. 通过SSH登录RaspberryPi
RaspberryPi的缺省用户名/密码是pi/raspberry, 一样好认又好记啊.. 默认只能用SSH登录, 传统的Telnet是不支持的.
3. 检查当前RaspberryPi网络配置
通过ifconfig命令可以看出无线网络已经配置了, 只是没有被分配地址
pi@raspberrypi:~$ ifconfig -a
eth0 Link encap:Ethernet HWaddr b8:27:eb:10:70:cf
inet addr:192.168.1.106 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:579 errors:0 dropped:0 overruns:0 frame:0
TX packets:247 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:85440 (83.4 KiB) TX bytes:32266 (31.5 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
wlan0 Link encap:Ethernet HWaddr e8:4e:06:13:0c:50
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
通过查看interfaces文件也能看到无线网卡是配置好的
pi@raspberrypi:~$ cat /etc/network/interfaces
auto lo
iface lo inet loopback
iface eth0 inet dhcp
allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
查看相对应的无线配置文件, 可用发现没有可用的network被配置
pi@raspberrypi:~$ sudo cat /etc/wpa_supplicant/wpa_supplicant.conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
4. 配置无线网络参数
所以呢, 加上类似下面的无线网络参加就好了. 具体的无线网络环境配置参数会有所不同, 那可能就需要参看其它文档了.
pi@raspberrypi:~$ sudo cat /etc/wpa_supplicant/wpa_supplicant.conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="Jie's"
psk="Helloworld?"
proto=RSN
key_mgmt=WPA-PSK
pairwise=CCMP
auth_alg=OPEN
}
OK, reboot后, 我们再看RaspberryPi的网络, 无线配好了, 那么拔掉网线, 玩去吧....
pi@raspberrypi:~$ ifconfig -a
eth0 Link encap:Ethernet HWaddr b8:27:eb:10:70:cf
inet addr:192.168.1.106 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:92 errors:0 dropped:1 overruns:0 frame:0
TX packets:79 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:12649 (12.3 KiB) TX bytes:10894 (10.6 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:8 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1104 (1.0 KiB) TX bytes:1104 (1.0 KiB)
wlan0 Link encap:Ethernet HWaddr e8:4e:06:13:0c:50
inet addr:192.168.1.102 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:71 errors:0 dropped:77 overruns:0 frame:0
TX packets:5 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:15377 (15.0 KiB) TX bytes:1398 (1.3 KiB)