2018年3月6日 星期二

Raspberry Pi 使用PPP撥接Script連線透過Quectel EC25 LTE Modem行動上網

本篇教學Raspberry Pi Model B使用PPP撥接Script連線透過Quectel EC25 4G/LTE Modem行動上網

1. 將Quectel EC25 USB LTE Modem接入Raspberry Pi

2. 輸入 sudo apt-get update 做更新

3. 輸入 sudo apt-get install rpi-update 做安裝更新

4. 輸入 sudo rpi-update 更新kernel

5. 輸入 sudo reboot 重新開機

6. 重新開機後輸入 ls /dev 檢查是否有ttyUSB3出現(註解: Data Port: ttyUSB3, AT Command Port: ttyUSB2)

7. 如有ttyUSB3出現,ppp-creator.sh內容放到你的Raspberry pi
#!/bin/sh

echo "install ppp"
apt-get install ppp

echo "creating directories"
mkdir -p /etc/ppp/peers

echo "creating script file : /etc/ppp/peers/quectel-chat-connect"
echo "
ABORT \"BUSY\"
ABORT \"NO CARRIER\"
ABORT \"NO DIALTONE\"
ABORT \"ERROR\"
ABORT \"NO ANSWER\"
TIMEOUT 30
\"\" AT
OK ATE0
OK ATI;+CSUB;+CSQ;+CPIN?;+COPS?;+CGREG?;&D2
# Insert the APN provided by your network operator, default apn is $1
OK AT+CGDCONT=1,\"IP\",\"\\T\",,0,0
OK ATD*99#
CONNECT" > /etc/ppp/peers/quectel-chat-connect


echo "creating script file : /etc/ppp/peers/quectel-chat-disconnect"
echo "
ABORT \"ERROR\"
ABORT \"NO DIALTONE\"
SAY \"\nSending break to the modem\n\"
\"\"  +++
\"\"  +++
\"\"  +++
SAY \"\nGoodbay\n\"" > /etc/ppp/peers/quectel-chat-disconnect


echo "creating script file : /etc/ppp/peers/quectel-ppp"
echo "
/dev/$2 115200
user \"\"
password \"\"
# The chat script, customize your APN in this file
connect 'chat -s -v -f /etc/ppp/peers/quectel-chat-connect -T $1'
# The close script
disconnect 'chat -s -v -f /etc/ppp/peers/quectel-chat-disconnect'
# Hide password in debug messages
hide-password
# The phone is not required to authenticate
noauth
# Debug info from pppd
debug
# If you want to use the LTE link as your gateway
defaultroute
# pppd must not propose any IP address to the peer
noipdefault
# No ppp compression
novj
novjccomp
noccp
ipcp-accept-local
ipcp-accept-remote
local
# Hardware flow control
nocrtscts
remotename 3gppp
ipparam 3gppp
ipcp-max-failure 30
# Ask the peer for up to 2 DNS server addresses
usepeerdns" > /etc/ppp/peers/quectel-ppp

echo "\n\nUse \"sudo pppd call quectel-ppp\" command and go internet"

8. 輸入 chmod +x ./ppp-creator.sh

9. 輸入 sudo ./ppp-creator.sh INTERNET ttyUSB3 (註解: INTERNET為你的APN)


10. 輸入sudo pppd call quectel-ppp persist 使用PPP連線上網且設定為持續連線,從ifconfig就可以看到ppp0起來,此時再輸入 sudo ip route add 0.0.0.0/0 dev ppp0 代表著所有封包都走ppp0出去


11. 如果你想斷線PPP,可以輸入 killall pppd