From 8bc05af94b04697161c5cc56c4f196e2eaeeae1a Mon Sep 17 00:00:00 2001 From: Yasin Kaya Date: Mon, 15 Oct 2018 17:58:48 +0300 Subject: [PATCH] added ppp_installer --- ppp_installer/chat-connect | 14 +++ ppp_installer/chat-disconnect | 8 ++ ppp_installer/install.sh | 135 ++++++++++++++++++++++++++++ ppp_installer/provider | 35 ++++++++ ppp_installer/reconnect_baseshield | 15 ++++ ppp_installer/reconnect_cellulariot | 33 +++++++ ppp_installer/reconnect_gprsshield | 28 ++++++ ppp_installer/reconnect_service | 14 +++ 8 files changed, 282 insertions(+) create mode 100644 ppp_installer/chat-connect create mode 100644 ppp_installer/chat-disconnect create mode 100644 ppp_installer/install.sh create mode 100644 ppp_installer/provider create mode 100644 ppp_installer/reconnect_baseshield create mode 100644 ppp_installer/reconnect_cellulariot create mode 100644 ppp_installer/reconnect_gprsshield create mode 100644 ppp_installer/reconnect_service diff --git a/ppp_installer/chat-connect b/ppp_installer/chat-connect new file mode 100644 index 0000000..12e205d --- /dev/null +++ b/ppp_installer/chat-connect @@ -0,0 +1,14 @@ +# /etc/chatscripts/chat-connect +ABORT "BUSY" +ABORT "NO CARRIER" +ABORT "NO DIALTONE" +ABORT "ERROR" +ABORT "NO ANSWER" +TIMEOUT 30 +"" AT +OK ATE0 +OK ATI;+CSUB;+CSQ;+COPS?;+CGREG?;&D2 +OK AT+CGDCONT=1,"IP","\T",,0,0 +#EXTRA +OK ATD*99# +CONNECT diff --git a/ppp_installer/chat-disconnect b/ppp_installer/chat-disconnect new file mode 100644 index 0000000..21447d1 --- /dev/null +++ b/ppp_installer/chat-disconnect @@ -0,0 +1,8 @@ +# /etc/chatscripts/quectel-chat-disconnect +ABORT "ERROR" +ABORT "NO DIALTONE" +SAY "\nSending break to the modem\n" +"" +++ +"" +++ +"" +++ +SAY "\nGoodbye\n" diff --git a/ppp_installer/install.sh b/ppp_installer/install.sh new file mode 100644 index 0000000..fcd872b --- /dev/null +++ b/ppp_installer/install.sh @@ -0,0 +1,135 @@ +#!/bin/sh +# How to use case-esac + +YELLOW='\033[1;33m' +RED='\033[0;31m' +SET='\033[0m' + +echo "${YELLOW}Please choose your Sixfab Shield:${SET}" +echo "${YELLOW}1: GSM/GPRS Shield${SET}" +echo "${YELLOW}2: 3G, 4G/LTE Base Shield${SET}" +echo "${YELLOW}3: Cellular IoT Shield${SET}" + +read answer +case $answer in + 1) echo "${YELLOW}You chose GSM/GPRS Shield${SET}";; + 2) echo "${YELLOW}You chose Base Shield${SET}";; + 3) echo "${YELLOW}You chose Cellular Iot Shield${SET}";; + *) echo "${YELLOW}You did not chose 1, 2 or 3${SET}"; exit 1; +esac + +echo "${YELLOW}Downloading setup files${SET}" +wget --no-check-certificate https://raw.githubusercontent.com/sixfab/rpiShields/master/ppp_installer/chat-connect -O chat-connect + +if [ $? -ne 0 ]; then + echo "${RED}Download failed${SET}" + exit 1; +fi + +wget --no-check-certificate https://raw.githubusercontent.com/sixfab/rpiShields/master/ppp_installer/chat-disconnect -O chat-disconnect + +if [ $? -ne 0 ]; then + echo "${RED}Download failed${SET}" + exit 1; +fi + +wget --no-check-certificate https://raw.githubusercontent.com/sixfab/rpiShields/master/ppp_installer/provider -O provider + +if [ $? -ne 0 ]; then + echo "${RED}Download failed${SET}" + exit 1; +fi + +while [ 1 ] +do + echo "${YELLOW}Do you have updated kernel ? [Y/n] ${SET}" + read answer2 + + case $answer2 in + Y) break;; + + n) echo "${YELLOW}rpi-update${SET}" + rpi-update + break;; + *) echo "${YELLOW}You did not choose y, N${SET}";; + esac +done + +echo "${YELLOW}ppp install${SET}" +apt-get install ppp + +echo "${YELLOW}What is your carrier APN?${SET}" +read carrierapn + +echo "${YELLOW}What is your device communication PORT? (ttyS0/ttyUSB3/etc.)${SET}" +read devicename + +EXTRA='OK AT+QCFG="nwscanseq",01,1\nOK AT+QCFG="nwscanmode",1,1\nOK AT+QCFG="iotopmode",2,1' + +mkdir -p /etc/chatscripts +if [ $answer -eq 3 ]; then + sed -i "s/#EXTRA/$EXTRA/" chat-connect +else + sed -i "/#EXTRA/d" chat-connect +fi + +mv chat-connect /etc/chatscripts/ +mv chat-disconnect /etc/chatscripts/ + +mkdir -p /etc/ppp/peers +sed -i "s/#APN/$carrierapn/" provider +sed -i "s/#DEVICE/$devicename/" provider +mv provider /etc/ppp/peers/provider + +if ! (grep -q 'route' /etc/ppp/ip-up ); then + echo "sudo route del default" >> /etc/ppp/ip-up + echo "sudo route add default ppp0" >> /etc/ppp/ip-up +fi + +if [ $answer -eq 2 ]; then + if ! (grep -q 'max_usb_current' /boot/config.txt ); then + echo "max_usb_current=1" >> /boot/config.txt + fi +fi + +while [ 1 ] +do + echo "${YELLOW}Do you want to activate auto connect/reconnect service at R.Pi boot up? [Y/n] ${SET}" + read answer3 + + case $answer3 in + Y) echo "${YELLOW}Downloading setup file${SET}" + + wget --no-check-certificate https://raw.githubusercontent.com/sixfab/rpiShields/master/ppp_installer/reconnect_service -O reconnect.service + + if [ $answer -eq 1 ]; then + + wget --no-check-certificate https://raw.githubusercontent.com/sixfab/rpiShields/master/ppp_installer/reconnect_gprsshield -O reconnect.sh + + elif [ $answer -eq 2 ]; then + + wget --no-check-certificate https://raw.githubusercontent.com/sixfab/rpiShields/master/ppp_installer/reconnect_baseshield -O reconnect.sh + + elif [ $answer -eq 3 ]; then + + wget --no-check-certificate https://raw.githubusercontent.com/sixfab/rpiShields/master/ppp_installer/reconnect_cellulariot -O reconnect.sh + + fi + + mv reconnect.sh /usr/src/ + mv reconnect.service /etc/systemd/system/ + + + systemctl daemon-reload + systemctl enable reconnect.service + + break;; + + n) echo "${YELLOW}To connect to internet run \"sudo pon\" and to disconnect run \"sudo poff\" " + break;; + *) echo "${YELLOW}You did not chose Y, N${SET}";; + esac +done + +reboot + diff --git a/ppp_installer/provider b/ppp_installer/provider new file mode 100644 index 0000000..6c9af13 --- /dev/null +++ b/ppp_installer/provider @@ -0,0 +1,35 @@ +# /etc/ppp/peers/provider +/dev/#DEVICE 115200 +# The chat script, customize your APN in this file +connect 'chat -s -v -f /etc/chatscripts/chat-connect -T #APN' +# The close script +disconnect 'chat -s -v -f /etc/chatscripts/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 HSDPA 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 +# For sanity, keep a lock on the serial line +lock +modem +dump +updetach +# Hardware flow control +nocrtscts +remotename 3gppp +ipparam 3gppp +ipcp-max-failure 30 +# Ask the peer for up to 2 DNS server addresses +usepeerdns diff --git a/ppp_installer/reconnect_baseshield b/ppp_installer/reconnect_baseshield new file mode 100644 index 0000000..1e81ffd --- /dev/null +++ b/ppp_installer/reconnect_baseshield @@ -0,0 +1,15 @@ +#!/bin/sh + + while true; do + + ping -c 1 8.8.8.8 + + if [ $? -eq 0 ]; then + echo "Connection up, reconnect not required..." + else + echo "Connection down, reconnecting..." + sudo pon + fi + + sleep 1 +done diff --git a/ppp_installer/reconnect_cellulariot b/ppp_installer/reconnect_cellulariot new file mode 100644 index 0000000..cee4094 --- /dev/null +++ b/ppp_installer/reconnect_cellulariot @@ -0,0 +1,33 @@ +#!/bin/sh + +gpio -g mode 20 in +gpio -g mode 11 out +gpio -g mode 26 out + +gpio -g write 26 0 +sleep 1 +gpio -g write 26 1 + +while true; do + + if [ $(gpio -g read 20) = "1" ]; then + echo "Power up" + + gpio -g write 11 0 + gpio -g write 11 1 + sleep 2 + gpio -g write 11 0 + sleep 2 + else + ping -c 1 8.8.8.8 + + if [ $? -eq 0 ]; then + echo "Connection up, reconnect not required..." + else + echo "Connection down, reconnecting..." + sudo pon + fi + fi + + sleep 1 +done diff --git a/ppp_installer/reconnect_gprsshield b/ppp_installer/reconnect_gprsshield new file mode 100644 index 0000000..d6ae6cf --- /dev/null +++ b/ppp_installer/reconnect_gprsshield @@ -0,0 +1,28 @@ +#!/bin/sh + +gpio -g mode 19 in +gpio -g mode 26 out + +while true; do + + if [ $(gpio -g read 19) = "0" ]; then + echo "Power up" + + gpio -g write 26 0 + gpio -g write 26 1 + sleep 2 + gpio -g write 26 0 + sleep 2 + else + ping -c 1 8.8.8.8 + + if [ $? -eq 0 ]; then + echo "Connection up, reconnect not required..." + else + echo "Connection down, reconnecting..." + sudo pon + fi + fi + + sleep 1 +done diff --git a/ppp_installer/reconnect_service b/ppp_installer/reconnect_service new file mode 100644 index 0000000..c3a9d65 --- /dev/null +++ b/ppp_installer/reconnect_service @@ -0,0 +1,14 @@ +[Unit] +Description=PPP Auto Connection +After=network.target + +[Service] +ExecStart=/bin/sh /usr/src/reconnect.sh +WorkingDirectory=/usr/src/ +StandardOutput=inherit +StandardError=inherit +Restart=always +User=pi + +[Install] +WantedBy=multi-user.target