ubantu下手動設定指令碼實現3G模組上網

來源:互聯網
上載者:User

標籤:style   io   color   ar   os   使用   sp   for   strong   

WCDMA


本節使用的是 huawei em770w 模組,使用中國聯通 WCDMA。

pppd 指令碼


pppd 指令碼預設放在/etc/ppp/peers/ 目錄下,比如我們使用 wcdma 這個名字為這個指令碼的

檔案名稱
使用命令
    #pppd call wcdma
這樣就啟動了 pppd 程式


pppd 程式的作用就是建立協議,產生網路介面 ppp0(如果第一個).下面是一個 pppd call 指令碼
的例子:

#/etc/ppp/peers/wcdma
#This is pppd script, used Huawei EM770W(Union)
/dev/ttyUSB0
115200
crtscts
modem
debug
nodetach
usepeerdns
defaultroute
user "3gnet"
0.0.0.0:0.0.0.0
connect ‘/usr/sbin/chat -s -v -f /etc/ppp/wcdma-connect-chat‘

有關 pppd 更多的意義請直接使用 linux 協助 man pppd

下面是一些重要參數的解釋
參數 意義
/dev/ttyUSB0 介面
115200         介面傳輸速率
crtscts           介面帶硬體流控
modem          這個參數使得 pppd 進程將等待模組發回的 CD (Carrier Detect)訊號,與
local               真好相反
debug             輸出調試資訊
nodetach        不後台運行,預設是後台啟動並執行
usepeerdns    使用 dns
defaultroute    本地和遠端的 ip 都設為 0 使得接入的 isp 分配本地的 ip 地址
user “3gnet”    使用者名稱
connect ‘...’     調用串連 chat 指令碼

chat 指令碼

  chat 指令碼是真正 AT 指令的發送和接收指令碼,下面是一個 chat 指令碼

#/etc/ppp/wcdma-connect-chat
TIMEOUT 5
ABORT "DELAYED"
ABORT "BUSY"
ABORT "ERROR"
ABORT "NO DIALTONE"
ABORT "NO CARRIER"
#"AT
#‘OK-+++\c-OK‘ ATH0
TIMEOUT 5
ECHO OFF
‘‘ AT
OK AT+CGDCONT=1,"IP","3gnet",,0,0
OK ATDT*99#
CONNECT ‘‘

#pppd call wcdma

  如果想在終端看到資訊就在pppd 指令碼中選擇nodetach,否則pppd將在後台運行,終端不顯示任何資訊,這樣可通過查看/var/log/ppp-connect-errors 記錄,瞭解程式啟動並執行過程。$ tail  -100 /var/log/ppp-connect-errors

如果沒有錯誤將出現

timeout set to 5 seconds
abort on (DELAYED)
abort on (BUSY)
abort on (ERROR)
abort on (NO DIALTONE)
abort on (NO CARRIER)
timeout set to 5 seconds
send (^MAT^M)
expect (OK)
A^M^M
OK
-- got it
send (AT+CGDCONT=1,"IP","3gnet",,0,0^M)
expect (OK)
^M
AT+CGDCONT=1,"IP","3gnet",,0,0^M^M
OK
-- got it
send (ATDT*99#^M)
expect (CONNECT)
^M
ATDT*99#^M^M
CONNECT
-- got it
send (^M)
Serial connection established.
using channel 9
Using interface ppp0
Connect: ppp0 <--> /dev/ttyUSB0
sent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0xf5d87df8> <pcomp> <accomp>]
rcvd [LCP ConfReq id=0x20 <asyncmap 0x0> <auth chap MD5> <magic 0x172fd2b> <pcomp>
<accomp>]
No auth is possible
sent [LCP ConfRej id=0x20 <auth chap MD5>]
rcvd [LCP ConfAck id=0x1 <asyncmap 0x0> <magic 0xf5d87df8> <pcomp> <accomp>]
rcvd [LCP ConfReq id=0x21 <asyncmap 0x0> <magic 0x172fd2b> <pcomp> <accomp>]
sent [LCP ConfAck id=0x21 <asyncmap 0x0> <magic 0x172fd2b> <pcomp> <accomp>]
sent [CCP ConfReq id=0x1 <deflate 15> <deflate(old#) 15> <bsd v1 15>]
sent [IPCP ConfReq id=0x1 <compress VJ 0f 01> <addr 0.0.0.0> <ms-dns1 0.0.0.0> <ms-dns3
0.0.0.0>]
rcvd [LCP DiscReq id=0x22 magic=0x172fd2b]
rcvd [LCP ProtRej id=0x23 80 fd 01 01 00 0f 1a 04 78 00 18 04 78 00 15 03 2f]
Protocol-Reject for ‘Compression Control Protocol‘ (0x80fd) received
rcvd [IPCP ConfNak id=0x1 <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14> <ms-wins
10.11.12.13> <ms-wins 10.11.12.14>]
sent [IPCP ConfReq id=0x2 <compress VJ 0f 01> <addr 0.0.0.0> <ms-dns1 10.11.12.13>
<ms-dns3 10.11.12.14>]
rcvd [IPCP ConfNak id=0x2 <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14> <ms-wins
10.11.12.13> <ms-wins 10.11.12.14>]
sent [IPCP ConfReq id=0x3 <compress VJ 0f 01> <addr 0.0.0.0> <ms-dns1 10.11.12.13>
<ms-dns3 10.11.12.14>]
rcvd [IPCP ConfReq id=0x10]
sent [IPCP ConfNak id=0x10 <addr 0.0.0.0>]
rcvd [IPCP ConfRej id=0x3 <compress VJ 0f 01>]
sent [IPCP ConfReq id=0x4 <addr 0.0.0.0> <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14>]
rcvd [IPCP ConfReq id=0x11]
sent [IPCP ConfAck id=0x11]
rcvd [IPCP ConfNak id=0x4 <addr 172.20.255.208> <ms-dns1 202.99.160.68> <ms-dns3
202.99.166.4>]
sent [IPCP ConfReq id=0x5 <addr 172.20.255.208> <ms-dns1 202.99.160.68> <ms-dns3
202.99.166.4>]
rcvd [IPCP ConfAck id=0x5 <addr 172.20.255.208> <ms-dns1 202.99.160.68> <ms-dns3
202.99.166.4>]
Could not determine remote IP address: defaulting to 10.64.64.64
not replacing existing default route via 192.168.8.254
local IP address 172.20.255.208
remote IP address 10.64.64.64
primary DNS address 202.99.160.68
secondary DNS address 202.99.166.4

$ifconfig 可以看到多出來ppp0

如果出現

Serial connection established.
using channel 3
Using interface ppp0
Connect: ppp0 <--> /dev/ttyUSB2
sent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0x29df6e1f> <pcomp> <accomp>]
sent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0x29df6e1f> <pcomp> <accomp>]
sent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0x29df6e1f> <pcomp> <accomp>]
sent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0x29df6e1f> <pcomp> <accomp>]
sent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0x29df6e1f> <pcomp> <accomp>]
sent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0x29df6e1f> <pcomp> <accomp>]
sent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0x29df6e1f> <pcomp> <accomp>]
sent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0x29df6e1f> <pcomp> <accomp>]
sent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0x29df6e1f> <pcomp> <accomp>]
sent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0x29df6e1f> <pcomp> <accomp>]
LCP: timeout sending Config-Requests
Connection terminated.

或者

send (ATDT*99#^M)
expect (CONNECT)
^M
ATDT*99#^M^M
NO CARRIER
-- failed
Failed (NO CARRIER)

可以試試換換ttyUSB連接埠號碼,預設是虛擬出的第一個連接埠,ttyUSB0

ubantu下手動設定指令碼實現3G模組上網

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.