Sixfab_PPP_Installer/src/reconnect_scripts/reconnect_tracker

104 lines
2.4 KiB
Plaintext
Raw Normal View History

2020-11-18 18:24:15 +00:00
#!/bin/bash
2019-10-09 10:55:31 +00:00
2020-11-18 13:52:12 +00:00
source functions.sh
source configs.sh
2020-11-17 10:08:25 +00:00
# Pinout for cellulariot app shield
STATUS=23
POWERKEY=24
DISABLE=17
2019-10-09 10:55:31 +00:00
2020-11-17 10:08:25 +00:00
# Configure pins
gpio -g mode $STATUS in
gpio -g mode $POWERKEY out
gpio -g mode $DISABLE out
2019-10-09 10:55:31 +00:00
2020-11-17 10:08:25 +00:00
function power_up_module()
{
for i in {1..20}; do
if [[ $(gpio -g read $STATUS) -eq 1 ]]; then
debug "Module is powering up..."
2019-10-09 10:55:31 +00:00
2020-11-17 10:08:25 +00:00
gpio -g write $POWERKEY 0
gpio -g write $POWERKEY 1
sleep 2
gpio -g write $POWERKEY 0
sleep 5
2019-10-09 10:55:31 +00:00
2020-11-17 10:08:25 +00:00
if [[ $(gpio -g read $STATUS) -eq 0 ]]; then
debug "Module is powered up."
return 0
break
else
debug "Module couldn't be powered up!"
sleep 2
fi
2020-11-17 10:08:25 +00:00
else
debug "Module is just powered up."
return 0
break
2019-10-09 10:55:31 +00:00
fi
2020-11-17 10:08:25 +00:00
done
return 1
}
2019-10-09 10:55:31 +00:00
2020-11-17 10:08:25 +00:00
function restart_power()
{
debug "Power of the module is restarting..."
# Restart power
gpio -g write $DISABLE 0 # power is disabled
sleep 2
gpio -g write $DISABLE 1 # power is enabled
}
#restart_power
2020-11-17 10:08:25 +00:00
# Modem power up
if power_up_module -eq 0 ; then sleep 0.1; else debug "Module couldn't be powered up! Check the hardware setup!"; fi
if check_network -eq 0; then
debug "PPP chatscript is starting...";
sudo pon;
# check default interface
route | grep ppp | grep default > /dev/null
PPP_IS_DEFAULT=$?
2020-11-26 14:02:00 +00:00
if [[ $PPP_IS_DEFAULT -ne 0 ]]; then sudo route add default ppp0; debug "ppp0 is added as default interface manually."; fi
2020-11-17 10:08:25 +00:00
else
2021-01-28 14:18:53 +00:00
debug "Network registration is failed!";
2020-11-17 10:08:25 +00:00
fi
while true; do
# Checking cellular internet connection
ping -q -c 1 -s 0 -w $PING_TIMEOUT -I ppp0 8.8.8.8 > /dev/null 2>&1
PINGG=$?
if [[ $PINGG -eq 0 ]]; then
printf "."
else
printf "/"
sleep $DOUBLE_CHECK_WAIT
# Checking cellular internet connection
ping -q -c 1 -s 0 -w $PING_TIMEOUT -I ppp0 8.8.8.8 > /dev/null 2>&1
PINGG=$?
if [[ $PINGG -eq 0 ]]; then
printf "+"
else
debug "Connection is down, reconnecting..."
restart_power
if power_up_module -eq 0 ; then sleep 0.1; else debug "Module couldn't be powered up! Check the hardware setup!"; fi
2021-01-28 14:18:53 +00:00
if check_network -eq 0; then sleep 0.1; else debug "Network registration is failed!"; fi
2020-11-17 10:08:25 +00:00
sudo pon
# check default interface
route | grep ppp | grep default > /dev/null
PPP_IS_DEFAULT=$?
2020-11-26 14:02:00 +00:00
if [[ $PPP_IS_DEFAULT -ne 0 ]]; then sudo route add default ppp0; debug "ppp0 is added as default interface manually."; fi
2020-11-17 10:08:25 +00:00
fi
fi
sleep $INTERVAL
2019-10-09 10:55:31 +00:00
done
2020-11-17 10:08:25 +00:00