From 0db047c03ce4699bd2ef393cda4021bd4c118bff Mon Sep 17 00:00:00 2001 From: Yasin Kaya Date: Wed, 18 Nov 2020 05:47:30 -0800 Subject: [PATCH] Functions and config is seperated from reconnect scripts --- ppp_installer/configs.sh | 5 ++++ ppp_installer/functions.sh | 43 ++++++++++++++++++++++++++++ ppp_installer/reconnect_baseshield | 45 ++---------------------------- ppp_installer/test.sh | 10 +++++++ 4 files changed, 60 insertions(+), 43 deletions(-) create mode 100644 ppp_installer/configs.sh create mode 100644 ppp_installer/functions.sh create mode 100644 ppp_installer/test.sh diff --git a/ppp_installer/configs.sh b/ppp_installer/configs.sh new file mode 100644 index 0000000..4d731e5 --- /dev/null +++ b/ppp_installer/configs.sh @@ -0,0 +1,5 @@ +#!/binenv bash + +INTERVAL=60 +DOUBLE_CHECK_WAIT=10 +PING_TIMEOUT=9 \ No newline at end of file diff --git a/ppp_installer/functions.sh b/ppp_installer/functions.sh new file mode 100644 index 0000000..9d66796 --- /dev/null +++ b/ppp_installer/functions.sh @@ -0,0 +1,43 @@ +#!/bin/env bash + +function debug() +{ + echo $(date "+%Y/%m/%d - %H:%M:%S :") "$1" +} + +function check_network() +{ + NETWORK_TIMEOUT=300 # Check network for ($NETWORK_TIMEOUT x 2 Seconds) + + # Check the network is ready + debug "Checking the network is ready..." + + for i in {1..$NETWORK_TIMEOUT}; do + NETWORK_OK=0 + + debug "SIM Status:" + atcom AT+CPIN? OK ERROR 10 | grep "CPIN: READY" + SIM_READY=$? + + debug "Network Registeration Status:" + # For super SIM + atcom AT+CREG? OK ERROR 10 | grep "CREG: 0,5" + NETWORK_REG=$? + # For native SIM + atcom AT+CREG? OK ERROR 10 | grep "CREG: 0,1" + NETWORK_REG_2=$? + # Combined network registeration status + NETWORK_REG=$((NETWORK_REG+NETWORK_REG_2)) + + if [[ $SIM_READY -eq 0 ]] && [[ $NETWORK_REG -le 1 ]]; then + debug "Network is ready." + NETWORK_OK=1 + return 0 + break + else + printf "?" + fi + sleep 2 + done + return 1 +} diff --git a/ppp_installer/reconnect_baseshield b/ppp_installer/reconnect_baseshield index b35d7b1..8e74cc1 100644 --- a/ppp_installer/reconnect_baseshield +++ b/ppp_installer/reconnect_baseshield @@ -1,48 +1,7 @@ #!/bin/env bash -INTERVAL=60 -DOUBLE_CHECK_WAIT=10 -PING_TIMEOUT=9 - -function debug() -{ - echo $(date "+%Y/%m/%d - %H:%M:%S :") "$1" -} - -function check_network() -{ - # Check the network is ready - debug "Checking the network is ready..." - - for i in {1..600}; do - NETWORK_OK=0 - - debug "SIM Status:" - atcom AT+CPIN? OK ERROR 10 | grep "CPIN: READY" - SIM_READY=$? - - debug "Network Registeration Status:" - # For super SIM - atcom AT+CREG? OK ERROR 10 | grep "CREG: 0,5" - NETWORK_REG=$? - # For native SIM - atcom AT+CREG? OK ERROR 10 | grep "CREG: 0,1" - NETWORK_REG_2=$? - # Combined network registeration status - NETWORK_REG=$((NETWORK_REG+NETWORK_REG_2)) - - if [[ $SIM_READY -eq 0 ]] && [[ $NETWORK_REG -le 1 ]]; then - debug "Network is ready." - NETWORK_OK=1 - return 0 - break - else - printf "?" - fi - sleep 2 - done - return 1 -} +source functions.sh +source configs.sh if check_network -eq 0; then debug "PPP chatscript is starting..."; diff --git a/ppp_installer/test.sh b/ppp_installer/test.sh new file mode 100644 index 0000000..b46f5ec --- /dev/null +++ b/ppp_installer/test.sh @@ -0,0 +1,10 @@ +#!/bin/env bash + +source functions.sh +source config.sh + +echo "PING TIMEOUT: " $PING_TIMEOUT +echo "DOUBLE CHECK WAIT: " $DOUBLE_CHECK_WAIT +echo "INTERVAL: " $INTERVAL + +check_network \ No newline at end of file