1.查看USB无线网卡是否识别
#lsusb %查看USB设备
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 0bda:8176 Realtek Semiconductor Corp. RTL8188CUS 802.11n WLAN Adapter
3.查看USB无线网卡否被内核支持
#lsmod %查看内核驱动
Module Size Used by
snd_bcm2835 19584 0
snd_soc_bcm2708_i2s 6202 0
regmap_mmio 2818 1 snd_soc_bcm2708_i2s
snd_soc_core 127841 1 snd_soc_bcm2708_i2s
snd_compress 8259 1 snd_soc_core
regmap_i2c 1661 1 snd_soc_core
snd_pcm_dmaengine 5505 1 snd_soc_core
regmap_spi 1913 1 snd_soc_core
snd_pcm 83845 3 snd_bcm2835,snd_soc_core,snd_pcm_dmaengine
snd_page_alloc 5132 1 snd_pcm
snd_seq 55484 0
snd_seq_device 6469 1 snd_seq
snd_timer 20998 2 snd_pcm,snd_seq
8192cu 550797 0
leds_gpio 2079 0
led_class 4118 1 leds_gpio
snd 62252 7 snd_bcm2835,snd_soc_core,snd_timer,snd_pcm,snd_seq,snd_seq_device,snd_compress
3.查看USB无线网卡配置
下面的wlan0就是USB无线网卡
#iwconfig %查看无线设备配置
wlan0 IEEE 802.11bgn ESSID:"QU SHI JI TUAN" Nickname:""
Mode:Managed Frequency:2.437 GHz Access Point: D0:C7:C0:9E:12:8A
Bit Rate:150 Mb/s Sensitivity:0/0
Retry:off RTS thr:off Fragment thr:off
Power Management:off
Link Quality=100/100 Signal level=88/100 Noise level=0/100
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:0 Invalid misc:0 Missed beacon:0
lo no wireless extensions.
eth0 no wireless extensions.
4.查看网络流量
#ifconfig %查看网络流量
eth0 Link encap:Ethernet HWaddr b8:27:eb:a0:7b:8d
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)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 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:20:2f:e6
inet addr:192.168.1.103 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:6674 errors:0 dropped:713 overruns:0 frame:0
TX packets:6168 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:6085359 (5.8 MiB) TX bytes:9334945 (8.9 MiB)
5.编辑/etc/network/interfaces文件内容
#sudo vim /etc/network/interfaces
auto lo
iface lo inet loopback
iface eth0 inet dhcp
auto wlan0
allow-hotplug wlan0
iface wlan0 inet manual
#iface wlan0 inet dhcp
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
我开始参考了很多网上的配置,最后发现只有这样配置才能上网,如果注释掉iface wlan0 inet manual,启用iface wlan0 inet dhcp不能上网,网上清一色都是这样的配置。
6.编辑/etc/wpa_supplicant/wpa_supplicant.conf文件
#sudo vim /etc/wpa_supplicant/wpa_supplicant.conf
#ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
#pdate_config=1
network={
ssid="OpenWrt-1"
proto=RSN
key_mgmt=WPA-PSK
pairwise=CCMP
group=CCMP
psk="password"
}
network={
ssid="OpenWrt-2"
proto=RSN
key_mgmt=WPA-PSK
pairwise=CCMP
group=CCMP
psk="password"
}
如果无线路由器设置的加密方式不同,配置也有差异,可以按照下面的配置自行修改。另外,可以同时设置两个网络,Raspberry Pi可以自行连接其中一个。
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="YOURSSID"
psk="YOURPASSWORD"
# Protocol type can be: RSN (for WP2) and WPA (for WPA1)
proto=WPA
# Key management type can be: WPA-PSK or WPA-EAP (Pre-Shared or Enterprise)
key_mgmt=WPA-PSK
# Pairwise can be CCMP or TKIP (for WPA2 or WPA1)
pairwise=TKIP
#Authorization option should be OPEN for both WPA1/WPA2 (in less commonly used are SHARED and LEAP)
auth_alg=OPEN
}
然后重启就可以连网络了。
7.使用wicd-curses配置
如果上面的配置还是不行的话,可以试试使用wicd-curses来配置。
sudo apt-get update
sudo apt-get install wicd-curses
sudo wicd-curses
8.Raspberry Pi无线自动重连
据说wpa_supplicant能够自动断线重连,但是实际上不能重新连接。这个使用的场景就是,Raspberry Pi 一天24h不关机,但是路由器晚上需要关机,但是Raspberry Pi在路由器开机后不会自动连接。
Python代码autowifi.py,放在/home/pi目录下:
#!/usr/bin/python
import os, time
while True:
if '192' not in os.popen('ifconfig | grep 192').read():
print 'n****** wifi is down, restart... ******n'
os.system('sudo /etc/init.d/networking restart')
time.sleep(5*60) #5 minutes
Shell脚本autowifi.sh,也放在/home/pi目录下:
#!/bin/sh
python /home/pi/autowifi.py&
开机自动启动以上脚本:
sudo cp -f /home/pi/autowifi.sh /etc/init.d/
sudo chmod +x /etc/init.d/autowifi.sh
sudo chown root:root /etc/init.d/autowifi.sh
sudo update-rc.d autowifi.sh defaults
每5分钟检测一次,若wifi断线,则自动重新连接。副作用就是SSH 5分钟不使用就会自动掉线。
9.wap_supplicant官网信息
http://hostap.epitest.fi/
http://w1.fi/wpa_supplicant/
参考资料:
1.http://www.howtogeek.com/167425/how-to-setup-wi-fi-on-your-raspberry-pi-via-the-command-line/
2.http://www.raspyfi.com/wi-fi-on-raspberry-pi-a-simple-guide/
3.http://www.shumeipai.net/thread-21355-1-1.html
4.http://www.chinaxing.org/articles/linux/2013/03/08/2013-03-08-raspberry-pi-usb-wifi-config.html
Recent Comments