diff --git a/ppp_install_jetson.sh b/ppp_install_jetson.sh index f1a8d9f..dd4511d 100755 --- a/ppp_install_jetson.sh +++ b/ppp_install_jetson.sh @@ -3,16 +3,19 @@ # Created on July 12, 2019 by Saeed Johar (saeedjohar) # Revised on November 19, 2020 by Yasin Kaya (selengalp) +source src/functions.sh + SIXFAB_PATH="/opt/sixfab" PPP_PATH="/opt/sixfab/ppp_connection_manager" -REPO_PATH="https://raw.githubusercontent.com/sixfab/Sixfab_PPP_Installer" +# NEEDS TO BE CHANGED TO SIXFAB IF PULLED +REPO_PATH="https://raw.githubusercontent.com/bzt/Sixfab_PPP_Installer" BRANCH=master SOURCE_PATH="$REPO_PATH/$BRANCH/src" SCRIPT_PATH="$REPO_PATH/$BRANCH/src/reconnect_scripts" -RECONNECT_SCRIPT_NAME="ppp_reconnect.sh" -MANAGER_SCRIPT_NAME="ppp_connection_manager.sh" -SERVICE_NAME="ppp_connection_manager.service" +MANAGER_SCRIPT_NAME="jetson_ppp_connection_manager.sh" +SERVICE_NAME="jetson_ppp_connection_manager.service" +UDEV_RULE_NAME="20-usb-bus.rules" YELLOW='\033[1;33m' RED='\033[0;31m' @@ -139,5 +142,58 @@ if ! (grep -q 'sudo route' /etc/ppp/ip-up ); then echo "sudo route add default ppp0" >> /etc/ppp/ip-up fi +while [ 1 ] +do + colored_echo "Do you want to activate auto connect service at boot up? [Y/n]" + read auto_reconnect + + colored_echo "You chose $auto_connect" ${GREEN} + + case $auto_reconnect in + [Yy]* ) colored_echo "Copying setup file..." + + wget --no-check-certificate $SOURCE_PATH/$SERVICE_NAME -O $SERVICE_NAME + if [[ $? -ne 0 ]]; then colored_echo "Download failed" ${RED}; exit 1; fi + + wget --no-check-certificate $SOURCE_PATH/functions.sh -O functions.sh + if [[ $? -ne 0 ]]; then colored_echo "Download failed" ${RED}; exit 1; fi + + wget --no-check-certificate $SOURCE_PATH/configs.sh -O configs.sh + if [[ $? -ne 0 ]]; then colored_echo "Download failed" ${RED}; exit 1; fi + + wget --no-check-certificate $SOURCE_PATH/jetson_configure_modem.sh -O jetson_configure_modem.sh + if [[ $? -ne 0 ]]; then colored_echo "Download failed" ${RED}; exit 1; fi + + wget --no-check-certificate $SOURCE_PATH/$MANAGER_SCRIPT_NAME -O $MANAGER_SCRIPT_NAME + if [[ $? -ne 0 ]]; then colored_echo "Download failed" ${RED}; exit 1; fi + + wget --no-check-certificate $SOURCE_PATH/$UDEV_RULE_NAME -O $UDEV_RULE_NAME + if [[ $? -ne 0 ]]; then colored_echo "Download failed" ${RED}; exit 1; fi + + # APN Configuration + sed -i "s/SIM_APN/$carrierapn/" jetson_configure_modem.sh + + # Devicename + sed -i "s/DEVICE/$devicename/" jetson_configure_modem.sh + sed -i "s/DEVICE/$devicename/" functions.sh + + mv functions.sh $PPP_PATH + mv configs.sh $PPP_PATH + mv jetson_configure_modem.sh $PPP_PATH + mv $MANAGER_SCRIPT_NAME $PPP_PATH + mv $SERVICE_NAME /etc/systemd/system/ + mv $UDEV_RULE_NAME /etc/udev/rules.d/ + + systemctl daemon-reload + systemctl enable $SERVICE_NAME + + break;; + + [Nn]* ) echo -e "${YELLOW}To connect to internet run ${BLUE}\"sudo pon\"${YELLOW} and to disconnect run ${BLUE}\"sudo poff\" ${SET}" + break;; + *) colored_echo "Wrong Selection, Select among Y or n" ${RED};; + esac +done + read -p "Press ENTER key to reboot" ENTER reboot diff --git a/src/20-usb-bus.rules b/src/20-usb-bus.rules new file mode 100644 index 0000000..2f4de32 --- /dev/null +++ b/src/20-usb-bus.rules @@ -0,0 +1,3 @@ +# UDEV RULE FOR SIXFAB WITH EC-25-E +SUBSYSTEMS=="usb", ENV{ID_USB_INTERFACE_NUM}="$attr{bInterfaceNumber}" +SUBSYSTEMS=="usb", KERNEL=="ttyUSB[0-9]*", ATTRS{idVendor}=="2c7c", ATTRS{idProduct}=="0125", SYMLINK+="sixfab$env{ID_USB_INTERFACE_NUM}", TAG+="systemd" diff --git a/src/functions.sh b/src/functions.sh index d3e28c7..fb22d49 100644 --- a/src/functions.sh +++ b/src/functions.sh @@ -10,6 +10,9 @@ CYAN='\033[0;36m' PURPLE='\033[0;35m' SET='\033[0m' +# default arguments +PORT=/dev/DEVICE + function debug { ECHO_PARAM=${2:-''} @@ -25,14 +28,14 @@ function check_network() NETWORK_OK=0 debug "SIM Status: " "-n" # no line break - atcom AT+CPIN? | grep "CPIN: READY" + atcom -p $PORT AT+CPIN? | grep "CPIN: READY" SIM_READY=$? - if [[ $SIM_READY -ne 0 ]]; then atcom AT+CPIN? | grep "CPIN:"; fi + if [[ $SIM_READY -ne 0 ]]; then atcom -p $PORT AT+CPIN? | grep "CPIN:"; fi debug "Network Registration Status: " "-n" # no line break - NR_TEXT=`atcom AT+CREG? | grep "CREG:"` + NR_TEXT=`atcom -p $PORT AT+CREG? | grep "CREG:"` echo $NR_TEXT # For super SIM diff --git a/src/jetson_configure_modem.sh b/src/jetson_configure_modem.sh new file mode 100644 index 0000000..29ab887 --- /dev/null +++ b/src/jetson_configure_modem.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +source functions.sh + +# only for "2: 3G, 4G/LTE Base Shield" + +# default arguments +APN=SIM_APN +PORT=/dev/DEVICE + +### Modem configuration for RMNET/PPP mode ################################## +debug "Checking APN and Modem Modem..." + +# APN Configuration +# ----------------- +atcom -p $PORT "AT+CGDCONT?" | grep $APN > /dev/null + +if [[ $? -ne 0 ]]; then + atcom -p $PORT "AT+CGDCONT=1,\"IPV4V6\",\"$APN\"" + debug "APN is updated." +fi + +# Check the vendor +# ON JETSON ONLY THE vendor:product ID is SHOWN +lsusb | grep 2c7c >> /dev/null +IS_QUECTEL=$? + + +# Modem Mode Configuration +# ------------------------ +# For Quectel +if [[ $IS_QUECTEL -eq 0 ]]; then + + # Quectel EC25-E + lsusb | grep 0125 > /dev/null + MODEL_EC25E=$? + + if [[ $MODEL_EC25E -eq 0 ]]; then + + # EC25 or derives. + sudo pon + + fi + +# Unknown +else + debug "The cellular module couldn't be detected!" + exit 1 +fi +### End of Modem configuration for RMNET/PPP mode ############################ + + +# Check the network is ready +# -------------------------- +if check_network -eq 0; then exit 0; else debug "Network registration is failed!. Modem configuration is unsuccesfully ended!"; exit 1; fi + diff --git a/src/jetson_ppp_connection_manager.service b/src/jetson_ppp_connection_manager.service new file mode 100644 index 0000000..1d7134e --- /dev/null +++ b/src/jetson_ppp_connection_manager.service @@ -0,0 +1,19 @@ +[Unit] +Description=Jetson PPP Connection Manager +# NEEDS TO BE CHANGED TO YOUR DEVICE +After=dev-sixfab03.device +# OR +# After=network.target + +[Service] +Type=simple +ExecStart=/bin/bash jetson_ppp_connection_manager.sh +WorkingDirectory=/opt/sixfab/ppp_connection_manager +StandardOutput=inherit +StandardError=inherit +RemainAfterExit=true +Restart=on-failure +RestartSec=5s + +[Install] +WantedBy=multi-user.target diff --git a/src/jetson_ppp_connection_manager.sh b/src/jetson_ppp_connection_manager.sh new file mode 100644 index 0000000..f31d5b0 --- /dev/null +++ b/src/jetson_ppp_connection_manager.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +source functions.sh + +for i in {1..4}; do + bash jetson_configure_modem.sh + WAS_SUCCESSFUL=$? + + + if [[ $WAS_SUCCESSFUL -eq 0 ]]; then + debug "Jetson configure modem successful" + else + debug "Jetson configure modem failed: Exit code = $WAS_SUCCESSFUL" + exit 1 + fi + + if [[ $MODEM_CONFIG -eq 0 ]]; then + break + fi + sleep 1 +done