[原创]在树莓派上使用腾达(Tenda)W311MI迷你无线USB网卡(RT5370芯片)/Using Tenda W311MI mini wireless USB adapter(based on RT5370 chipset) on Raspberry Pi

For non-Chinese readers:
I'm a software engineer in Shanghai, China, and since I bought a Raspberry Pi, I spent some spare time on it and I'm glad to share something with Pi users all over the world, so this article has two languages: Chinese & English, and I try to translate the Chinese to English as accurately as possible, but, there might be some translation mistakes, so if you don't know what I mean in the article, just leave a comment, and I'll reply when I get an answer. Also welcome to contact me via Email.

Raspberry Pi是什么?

The Raspberry Pi is a credit card sized single-board computer developed in the UK by the Raspberry Pi Foundation with the intention of stimulating the teaching of basic computer science in schools.

简单地说,它就是一个基于ARM CPU的、信用卡那么大的迷你计算机。
In short, Pi is an ARM-based mini computer which has a credit card size.

Before reading this article, I recommend you to read another one on Pi configuration because this article has some connection with it.

为了能让树莓派摆脱每次使用都要插网线的麻烦,我最终还是决定为它配备一块USB无线网卡。在Google了一番之后,我发现很多树莓派用户都提到基于Ralink RT5370芯片的USB无线网卡,于是我购买了一个基于RT5370芯片的腾达(Tenda)W311MI迷你无线USB网卡(如下图所示),非常便宜的白菜价:只要¥30。
To get rid of the inconveniency of connecting a network cable to Raspberry Pi I decided to equip it with a wireless USB adapter. After Googling the Internet I found that many Pi users mention the wireless USB adapter based on Ralink RT5370 chipset, so I bought one too - the Tenda W311MI 150Mbps Wireless Mini USB Adapter(shown as below), which based on RT5370 and has a very low price: only $4.8 .

Tenda W311MI 150Mbps Wireless Mini USB Adapter

关于如何在使用Arch Linux ARM系统的树莓派上使用RT5370芯片的USB无线网卡,网上很难找到完整的教程(用Debian系统的倒是有),所以我走了不少弯路,搞定了之后决定要写出来。所以,再次提醒你,如果你用的是Arch Linux ARM系统,并且使用的是RT5370芯片的USB无线网卡,那么阅读本文可能对你有所帮助;如果不是,那么就不用看下去了。
It's hard to find a detailed tutorial on how to use a RT5370-chipset-based wireless USB adapter on Raspberry Pi which runs the Arch Linux ARM os(but there are some good tutorials on Debian), so I wasted a lot of time in the setup process and when I figured it out I decided to write them down. So be sure again that if you are running the Arch Linux ARM on Pi and using a wireless USB adapter which based on RT5370 chipset, then you'll read something useful in this article, if not, don't waste your time and just close this webpage.
【1】关于驱动 / About the driver

这个页面是Ralink RT5370芯片的官方驱动下载页面,不过,在整个配置过程中我们完全不用下载此驱动,因为Arch Linux ARM已经自带了,非常方便。
This page is the official driver download page, but we don't need it in the whole setup process because Arch Linux ARM has it installed already.

After plugging the wireless USB adapter, use following command to have a check:
[root@alarmpi ~]# lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp. LAN9500 Ethernet 10/100 Adapter
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. 
Bus 001 Device 004: ID 148f:5370 Ralink Technology, Corp. RT5370 Wireless Adapter
可见Ralink RT5370芯片已经被识别出来了,这是成功的第一步。
So the Ralink RT5370 chipset has been recognized and this is the first step to success.
Then we can check the modules which have been loaded by the OS:
[root@alarmpi ~]# lsmod
Module                  Size  Used by
rt2800usb              12977  0 
rt2800lib              47334  1 rt2800usb
rt2x00usb              10895  1 rt2800usb
rt2x00lib              40765  3 rt2x00usb,rt2800lib,rt2800usb
spidev                  5028  0 
mac80211              234117  3 rt2x00lib,rt2x00usb,rt2800lib
cfg80211              173637  2 mac80211,rt2x00lib
crc_ccitt               1433  1 rt2800lib
spi_bcm2708             4357  0 
i2c_bcm2708             3557  0 
ipv6                  289527  16
According to this article, the rt2x00 is the uniform driver for Ralink chipsets.
【2】安装wireless_tools / Install wireless_tools
First we need to install a wireless network interface configuration tool - iwconfig :
[root@alarmpi ~]# pacman -S wireless_tools
Then you can use iwconfig to check the info of your wireless USB adapter:
[root@alarmpi ~]# iwconfig 
ifb0      no wireless extensions.

lo        no wireless extensions.

wlan0     IEEE 802.11bgn  ESSID:"XXX"  
          Mode:Managed  Frequency:2.412 GHz  Access Point: XXXXXXXXXXX   
          Bit Rate=54 Mb/s   Tx-Power=20 dBm   
          Retry  long limit:7   RTS thr:off   Fragment thr:off
          Encryption key:off
          Power Management:on
          Link Quality=70/70  Signal level=-39 dBm  
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:0  Invalid misc:18   Missed beacon:0

eth0      no wireless extensions.

ifb1      no wireless extensions.
The "wlan0" is what you should focus on.
【3】配置无线连接的帐户 / Setup the WiFi account
我的无线网络是WPA加密的,要连接到这样的无线网络,需要使用wpa_supplicant工具。如果不出意外,你会发现Arch Linux ARM已经安装好了这个工具:
In order to connected to a WPA encrypted wireless network we need to use a tool like wpa_supplicant. No accident that you'll find it already been installed:
[root@alarmpi ~]# pacman -Q | grep wpa     
wpa_supplicant 1.0-2
So we just use it. If you can't find the package, it's very easy to use pacman to install it.
Backup the configuration file of wpa_supplicant to avoid misoperation:
mv /etc/wpa_supplicant/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf.bak
Use wpa_passphrase tool to generate a very simple configuration file:
wpa_passphrase myWirelessSSID myPassword > /etc/wpa_supplicant/wpa_supplicant.conf
其中,“myWirelessSSID”是你的无线网络的SSID,“myPassword”是连接该无线网络的密码。wpa_passphrase工具会根据你提供的这两个信息生成一个非常简单的配置文件,此处我们将输出的信息写入了文件 /etc/wpa_supplicant/wpa_supplicant.conf 中。
The "myWirelessSSID" is the SSID of your wireless network, "myPassword" is the password used to connect the network. wpa_passphrase tool will generate a very simple configuration file according to the info you provided and here we write the output to file /etc/wpa_supplicant/wpa_supplicant.conf.
Bring wlan0 up:
ifconfig wlan0 up
Connect to the network:
wpa_supplicant -B -Dwext -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf
But we can't access Pi until it get an available IP address, use following command to get one:
[root@alarmpi ~]# dhcpcd wlan0
dhcpcd[286]: version 5.6.2 starting
dhcpcd[286]: wlan0: sending IPv6 Router Solicitation
dhcpcd[286]: wlan0: broadcasting for a lease
dhcpcd[286]: wlan0: offered 192.168.X.X from 192.168.X.X
dhcpcd[286]: wlan0: acknowledged 192.168.X.X from 192.168.X.X
dhcpcd[286]: wlan0: checking for 192.168.X.X
dhcpcd[286]: wlan0: sending IPv6 Router Solicitation
dhcpcd[286]: wlan0: leased for 86400 seconds
dhcpcd[286]: forked to background, child pid 327
Now Pi should be able to connect the wireless network.
【4】开机自动连接无线网络 / Connect on system startup
To let Pi connects the wireless network automatically, add the following 2 shell commands to OS startup execution list:
wpa_supplicant -B -Dwext -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf
dhcpcd wlan0
You can refer to this article, item 【2】 on how to execute shell command on startup.
* 先安装一个让你可以在shell命令行界面显示类似于图形界面对话框的程序:

pacman -S dialog

* 使用 wifi-menu 程序,来“图形化”(利用上面安装的dialog程序)地连接上无线网络:

wifi-menu -o

然后就会进入交互式界面,首先会扫描无线网络,如果扫描到了,会在一个类图形界面里显示出来所有无线网络的SSID,用键盘选择后进入下一步,输入无线网络的密码,以及设置一个配置文件的名字(可用默认名字,生成的配置文件在 /etc/netctl/ 目录下),然后就应该OK了,经过大概一两分钟的等待(界面完全没有任何文字或图形显示),无线网络就连上了,用 ifconfig 看看,是不是无线网卡已经分配到IP地址了?

netctl start xxx

其中,xxx 是你前面用 wifi-menu 程序生成的配置文件名,注意,这里是不需要写全路径的,netctl程序会自动地去 /etc/netctl/ 目录下找名为 xxx 的配置文件并用它里面写的配置内容来连接对应的网络。
当然,上面的开机启动方式可能有点不规范,可以用 systemd 的方式来设置开机启动:

netctl enable xxx

这里 xxx 也是你的WiFi配置文件名。这将创建并启用一个随计算机启动而自动运行的 systemd 服务(参考这个链接)。
At last show you the wireless USB adapter working on Pi(it's obvious that the LNK status LED is off):

Tenda W311MI 150Mbps Wireless Mini USB Adapter on Raspberry Pi

So the main purpose of this article has been reached. If you want to know more about Pi, please read these articles.

➤➤ 版权声明 ➤➤ 

wechat qrcode of codelast

《[原创]在树莓派上使用腾达(Tenda)W311MI迷你无线USB网卡(RT5370芯片)/Using Tenda W311MI mini wireless USB adapter(based on RT5370 chipset) on Raspberry Pi》有14条评论

  1. HELP!
    [root@alarmpi wpa_supplicant]# wpa_supplicant -B -Dwext -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf
    Successfully initialized wpa_supplicant
    ioctl[SIOCSIWAP]: Operation not permitted
    ioctl[SIOCSIWENCODEEXT]: Invalid argument
    ioctl[SIOCSIWENCODEEXT]: Invalid argument
    多谢了 >_<!

  2. 呃,根据阁下的教程弄了半天,可还是没有弄出来,55555555.在执行 wpa_supplicant -B -Dwext -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf 是提示(两行):ioctl[SIOCSIWENCODEEXT]: Invalid argument
    ioctl[SIOCSIWENCODEEXT]: Invalid argument
    请问阁下这是怎么回事?另外,我的pi上有个wifi config(openssl项目的),不知道配置好后,这个软件是否能用?

    • 这个...真心不知道是怎么回事,你只能去Google了。我也不知道wifi config能不能用,因为我没用过。