1. 程式人生 > 其它 >SIM 7000X NB-loT HAT 樹莓派PPP撥號上網教程

SIM 7000X NB-loT HAT 樹莓派PPP撥號上網教程

技術標籤:樹莓派NB-IOTlinux

一.準備

硬體準備

軟體準備

  • 安裝minicom
apt-get install minicom
  • 檢視dev下面有沒有ttyS0,如果沒有需要配置下串列埠
ls /dev/ttyUSB*

在這裡插入圖片描述

二.AT指令除錯(可選)

  • 進入minicom
sudo minicom -D /dev/ttyS0
  • 檢查sim卡是否接觸良好:
AT+CPIN?

  • 檢查網路模式設定是否正確:
AT+CNMP?

  • 檢查當前環境的訊號質量:
AT+CSQ

  • 檢查運營商接入情況:
AT+COPS?

  • 檢查聯網情況:
AT+CPSI?

  • 檢查是否成功註冊到網路:
AT+CREG?

三.PPP撥號

  • 切換到root賬號
sudo su
  • 安裝ppp
  sudo apt-get install ppp
  • 進入/etc/ppp/peers目錄,
cd /etc/ppp/peers
  • 建立gprs檔案
sudo nano gprs
  • 將下面文字複製到 gprs
    (如果需要USB撥號,把ttyS0改位ttyUSB2)內容如下:
# example configuration for a dialup connection authenticated with PAP or CHAP
# This is the default configuration used by pon(1) and poff(1).
# See the manual page pppd(8) for information on all the options.
# MUST CHANGE: replace 
[email protected]
with the PPP login name given to # your by your provider. # There should be a matching entry with the password in /etc/ppp/pap-secrets # and/or /etc/ppp/chap-secrets. user "[email protected]" # MUST CHANGE: replace ******** with the phone number of your provider. # The /etc/chatscripts/pap chat script may be modified to change the # modem initialization string. #connect "/usr/sbin/chat -v -f /etc/chatscripts/pap -T ********" connect "/usr/sbin/chat -v -f /etc/chatscripts/gprs" # Serial device to which the modem is connected. #/dev/modem /dev/ttyUSB2 # Speed of the serial line. 115200 nocrtscts debug nodetach ipcp-accept-local ipcp-accept-remote # Assumes that your IP address is allocated dynamically by the ISP. noipdefault # Try to get the name server addresses from the ISP. usepeerdns # Use this connection as the default route. defaultroute # Makes pppd "dial again" when the connection is lost. persist # Do not ask the remote to authenticate. noauth
  • PPP撥號
pppd call gprs &
  • 檢視ppp0網路
ifconfig
  • 測試上網
ping -I ppp0 www.baidu.com

四.開機自啟動PPP撥號(可選)

  • 編輯test.sh檔案
sudo nano test.sh
  • 複製以下文字到 tesh.sh
sudo su
# sleep 1m
cd /etc/ppp/peers
pppd call gprs &
  • 賦予指令碼檔案(例:test.sh,路徑:./home/pi/test.sh)可執行許可權
sudo chmod 777 test.sh
  • 開啟/etc/rc.local檔案
sudo nano /etc/rc.local
  • 在/etc/rc.local檔案中(語句exit 0 之上一行)新增執行指令碼命令
bash ./home/pi/test.sh
  • 然後執行重啟指令碼
./test.sh