项目十四--便携式3G路由器
本节教程将介绍如何基于MicroWRT实现一个可以自由上网的路由器。我们知道可以在电脑上插上USB 3G上网卡,然后在任何地方都可以上网了。 现在市面上也有一些热点设备。那么如何把MicroWRT变成一个上网热点呢?我们将在下面介绍。
3G路由器原理MicroWRT有USB接口,在此接口上插入一个3G上网卡,通过配置相应的驱动和设置参数,MicroWRT就可以通过这个3G上网卡进行上网了。同时 MicroWRT本身可以作为热点,所以其他设备连接到MicroWRT后就可以上网了。 硬件连接图如下: 硬件设备1. MicroWRT 核心板 2. MicroWRT HUB 扩展板 3. 3G 上网卡。并不是市面上所有的3G上网卡都能够被完美支持,在本教程中测试了两款华为的3G 上网卡,都可以正常使用。如下是购买链接(此处非广告^_^) https://item.taobao.com/item.htm?spm=a1z09.2.0.0.Jt8psG&id=524801150207&_u=h4s2b1167a5 https://item.taobao.com/item.htm?spm=a1z09.2.0.0.Jt8psG&id=524641523142&_u=h4s2b11bbae 这两款的下行速率不一样,购买时请注意。 安装软件使用make menuconfig命令来配置3G拨号需要的驱动和应用。具体需要按照如下软件: kmod-usb-acm kmod-usb-ohci kmod-usb-serial kmod-usb-serial-option kmod-usb-sierrawireless kmod-usb2 usb-modeswitch usb-modeswitch-data kmod-ppp chat,comgt,pppd. 其中comgt是拨号用的,可以用comgt -d /dev/ttyUSBx来测试3G SIM卡的状态,chat是保存命令的脚本,在pppd的options 配置文件中。 将编译好的固件烧写到MicroWRT上。 添加/修改配置文件如下的配置文件都是配合上面两款3G上网卡。 vi /etc/modules.d/usb-serial 添加如下内容 usbserial vendor=0x12d1 product=0x1446 在目录/etc/chatscripts下创建文件3g.chat,内容如下: ABORT BUSY ABORT 'NO CARRIER' ABORT ERROR REPORT CONNECT TIMEOUT 10 "" "AT&F" OK "ATE1" OK 'AT+CGDCONT=1,"IP","$USE_APN"' SAY "Calling UMTS/GPRS" TIMEOUT 30 OK "ATD$DIALNUMBER" CONNECT ' 然后运行下面命令,在network文件中添加3G配置。 vi /etc/config/network 添加如下内容: config 'interface' '3g' option 'proto' '3g' option 'apn' '3gnet' option 'maxwait' '0' option 'service' 'umts' option 'device' '/dev/ttyUSB0' 测试完成上面配置后,重启MicroWRT,然后插入3G上网卡,如果打印出如下日志,说明网卡已经被识别。 root@microWrt:/# [ 1264.350000] usb 1-1.1: new high-speed USB device number 3 using ehci-platform [ 1264.490000] usb-storage 1-1.1:1.0: USB Mass Storage device detected [ 1264.510000] scsi host0: usb-storage 1-1.1:1.0 [ 1264.620000] usb 1-1.1: USB disconnect, device number 3 [ 1272.030000] usb 1-1.1: new high-speed USB device number 4 using ehci-platform [ 1272.170000] usb-storage 1-1.1:1.0: USB Mass Storage device detected [ 1272.190000] option 1-1.1:1.0: GSM modem (1-port) converter detected [ 1272.190000] usb 1-1.1: GSM modem (1-port) converter now attached to ttyUSB0 [ 1272.200000] usb-storage 1-1.1:1.1: USB Mass Storage device detected [ 1272.210000] option 1-1.1:1.1: GSM modem (1-port) converter detected [ 1272.220000] usb 1-1.1: GSM modem (1-port) converter now attached to ttyUSB1 [ 1272.220000] usb-storage 1-1.1:1.2: USB Mass Storage device detected [ 1272.240000] scsi host3: usb-storage 1-1.1:1.2 [ 1272.240000] usb-storage 1-1.1:1.3: USB Mass Storage device detected [ 1272.250000] scsi host4: usb-storage 1-1.1:1.3 [ 1273.250000] scsi 3:0:0:0: CD-ROM HUAWEI Mass Storage 2.31 PQ: 0 ANSI: 2 [ 1273.250000] scsi 3:0:0:0: Attached scsi generic sg0 type 5 [ 1273.270000] scsi 4:0:0:0: Direct-Access HUAWEI MMC Storage 2.31 PQ: 0 ANSI: 2 [ 1273.280000] sd 4:0:0:0: Attached scsi generic sg1 type 0 [ 1273.290000] sd 4:0:0:0: [sda] Attached SCSI removable disk [ 1277.910000] 3g-3g: renamed from ppp0 运行命令,查看是否可以访问网络。 ping www.baidu.com 正常情况下会有如下输出: root@microWrt:/# ping www.baidu.com PING www.baidu.com (61.135.169.125): 56 data bytes 64 bytes from 61.135.169.125: seq=0 ttl=55 time=1300.160 ms 64 bytes from 61.135.169.125: seq=1 ttl=55 time=848.980 ms 64 bytes from 61.135.169.125: seq=2 ttl=55 time=338.960 ms 64 bytes from 61.135.169.125: seq=3 ttl=55 time=348.480 ms 64 bytes from 61.135.169.125: seq=4 ttl=55 time=628.260 ms 64 bytes from 61.135.169.125: seq=5 ttl=55 time=558.380 ms ^C --- www.baidu.com ping statistics --- 6 packets transmitted, 6 packets received, 0% packet loss round-trip min/avg/max = 338.960/670.536/1300.160 ms |