reconnect.sh files revision

This commit is contained in:
Yasin Kaya 2020-11-17 02:08:25 -08:00
parent 763eca71b3
commit 72d1e615d8
7 changed files with 714 additions and 114 deletions

View File

@ -1,21 +1,89 @@
#!/bin/sh #!/bin/env bash
# /usr/src/reconnect
# for Base HAT
gpio -g mode 26 out #HAT_POWER_OFF # Pinout for base hat
gpio -g mode 19 out #W_DISABLE POWER_OFF=26
W_DISABLE=19
gpio -g write 26 0 # General variables
gpio -g write 19 0 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
}
# Control pins
gpio -g mode $POWER_OFF out #HAT_POWER_OFF
gpio -g mode $W_DISABLE out #W_DISABLE
gpio -g write $POWER_OFF 0
gpio -g write $W_DISABLE 0
if check_network -eq 0; then
debug "PPP chatscript is starting...";
sudo pon;
else
debug "Network registeration is failed!";
fi
while true; do 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=$?
ping -q -I ppp0 -c 1 8.8.8.8 -s 0 >/dev/null 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 [ $? -ne 0 ]; then if [[ $PINGG -eq 0 ]]; then
echo "Connection down, reconnecting..." printf "+"
sudo pon else
fi debug "Connection is down, reconnecting..."
if check_network -eq 0; then sleep 0.1; else debug "Network registeration is failed!"; fi
sleep 10 sudo pon
fi
fi
sleep $INTERVAL
done done

View File

@ -1,13 +1,77 @@
#!/bin/sh #!/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
}
if check_network -eq 0; then
debug "PPP chatscript is starting...";
sudo pon;
else
debug "Network registeration is failed!";
fi
while true; do 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=$?
ping -q -I ppp0 -c 1 8.8.8.8 -s 0 >/dev/null 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 [ $? -ne 0 ]; then if [[ $PINGG -eq 0 ]]; then
echo "Connection down, reconnecting..." printf "+"
sudo pon else
fi debug "Connection is down, reconnecting..."
if check_network -eq 0; then sleep 0.1; else debug "Network registeration is failed!"; fi
sleep 10 sudo pon
fi
fi
sleep $INTERVAL
done done

View File

@ -1,31 +1,129 @@
#!/bin/sh #!/bin/env bash
gpio -g mode 23 in #status # Pinout for cellulariot hat
gpio -g mode 24 out #powerkey STATUS=23
gpio -g mode 17 out #enable POWERKEY=24
ENABLE=17
gpio -g write 17 1 # General variables
sleep 1 INTERVAL=60
gpio -g write 17 0 DOUBLE_CHECK_WAIT=10
PING_TIMEOUT=9
# Configure pins
gpio -g mode $STATUS in
gpio -g mode $POWERKEY out
gpio -g mode $ENABLE out
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
}
function power_up_module()
{
for i in {1..20}; do
if [[ $(gpio -g read $STATUS) -eq 1 ]]; then
debug "Module is powering up..."
gpio -g write $POWERKEY 1
sleep 2
gpio -g write $POWERKEY 0
sleep 2
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
else
debug "Module is just powered up."
return 0
break
fi
done
return 1
}
function restart_power()
{
debug "Power of the module is restarting..."
# Restart power
gpio -g write $ENABLE 1 # power is disabled
sleep 2
gpio -g write $ENABLE 0 # power is enabled
}
restart_power # Restart power
# 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;
else
debug "Network registeration is failed!";
fi
while true; do 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 [ $(gpio -g read 23) = "1" ]; then if [[ $PINGG -eq 0 ]]; then
echo "Power up" 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=$?
#gpio -g write 24 0 if [[ $PINGG -eq 0 ]]; then
gpio -g write 24 1 printf "+"
sleep 2 else
gpio -g write 24 0 debug "Connection is down, reconnecting..."
sleep 2 if check_network -eq 0; then sleep 0.1; else debug "Network registeration is failed!"; fi
else sudo pon
ping -q -I ppp0 -c 1 8.8.8.8 -s 0 >/dev/null fi
fi
if [ $? -ne 0 ]; then sleep $INTERVAL
echo "Connection down, reconnecting..."
sudo pon
fi
fi
sleep 10
done done

View File

@ -1,31 +1,130 @@
#!/bin/sh #!/bin/env bash
gpio -g mode 20 in # Pinout for cellulariot app shield
gpio -g mode 11 out STATUS=20
gpio -g mode 26 out POWERKEY=11
DISABLE=26
gpio -g write 26 0 # General variables
sleep 1 INTERVAL=60
gpio -g write 26 1 DOUBLE_CHECK_WAIT=10
PING_TIMEOUT=9
# Configure pins
gpio -g mode $STATUS in
gpio -g mode $POWERKEY out
gpio -g mode $DISABLE out
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
}
function power_up_module()
{
for i in {1..20}; do
if [[ $(gpio -g read $STATUS) -eq 1 ]]; then
debug "Module is powering up..."
gpio -g write $POWERKEY 0
gpio -g write $POWERKEY 1
sleep 2
gpio -g write $POWERKEY 0
sleep 2
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
else
debug "Module is just powered up."
return 0
break
fi
done
return 1
}
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 # Restart power
# 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;
else
debug "Network registeration is failed!";
fi
while true; do 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 [ $(gpio -g read 20) = "1" ]; then if [[ $PINGG -eq 0 ]]; then
echo "Power up" 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=$?
gpio -g write 11 0 if [[ $PINGG -eq 0 ]]; then
gpio -g write 11 1 printf "+"
sleep 2 else
gpio -g write 11 0 debug "Connection is down, reconnecting..."
sleep 2 if check_network -eq 0; then sleep 0.1; else debug "Network registeration is failed!"; fi
else sudo pon
ping -q -I ppp0 -c 1 8.8.8.8 -s 0 >/dev/null fi
fi
if [ $? -ne 0 ]; then sleep $INTERVAL
echo "Connection down, reconnecting..."
sudo pon
fi
fi
sleep 10
done done

View File

@ -1,26 +1,119 @@
#!/bin/sh #!/bin/env bash
gpio -g mode 19 in # Pinout for cellulariot hat
gpio -g mode 26 out STATUS=19
POWERKEY=26
# General variables
INTERVAL=60
DOUBLE_CHECK_WAIT=10
PING_TIMEOUT=9
# Configure pins
gpio -g mode $STATUS in
gpio -g mode $POWERKEY out
gpio -g mode $ENABLE out
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
}
function power_up_module()
{
for i in {1..20}; do
if [[ $(gpio -g read $STATUS) -eq 1 ]]; then
debug "Module is powering up..."
gpio -g write $POWERKEY 0
gpio -g write $POWERKEY 1
sleep 2
gpio -g write $POWERKEY 0
sleep 2
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
else
debug "Module is just powered up."
return 0
break
fi
done
return 1
}
# 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;
else
debug "Network registeration is failed!";
fi
while true; do 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 [ $(gpio -g read 19) = "0" ]; then if [[ $PINGG -eq 0 ]]; then
echo "Power up" 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=$?
gpio -g write 26 0 if [[ $PINGG -eq 0 ]]; then
gpio -g write 26 1 printf "+"
sleep 2 else
gpio -g write 26 0 debug "Connection is down, reconnecting..."
sleep 2 if check_network -eq 0; then sleep 0.1; else debug "Network registeration is failed!"; fi
else sudo pon
ping -q -I ppp0 -c 1 8.8.8.8 -s 0 >/dev/null fi
fi
if [ $? -ne 0 ]; then sleep $INTERVAL
echo "Connection down, reconnecting..."
sudo pon
fi
fi
sleep 10
done done

View File

@ -0,0 +1,77 @@
#!/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
}
if check_network -eq 0; then
debug "PPP chatscript is starting...";
sudo pon;
else
debug "Network registeration is failed!";
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..."
if check_network -eq 0; then sleep 0.1; else debug "Network registeration is failed!"; fi
sudo pon
fi
fi
sleep $INTERVAL
done

View File

@ -1,30 +1,131 @@
#!/bin/sh #!/bin/env bash
gpio -g mode 23 in #status # Pinout for cellulariot app shield
gpio -g mode 24 out #powerkey STATUS=23
gpio -g mode 17 out #disable POWERKEY=24
# enabling the power of the HAT DISABLE=17
gpio -g write 17 1
sleep 1 # General variables
gpio -g write 17 0 INTERVAL=60
DOUBLE_CHECK_WAIT=10
PING_TIMEOUT=9
# Configure pins
gpio -g mode $STATUS in
gpio -g mode $POWERKEY out
gpio -g mode $DISABLE out
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
}
function power_up_module()
{
for i in {1..20}; do
if [[ $(gpio -g read $STATUS) -eq 1 ]]; then
debug "Module is powering up..."
gpio -g write $POWERKEY 0
gpio -g write $POWERKEY 1
sleep 2
gpio -g write $POWERKEY 0
sleep 2
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
else
debug "Module is just powered up."
return 0
break
fi
done
return 1
}
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 # Restart power
# 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;
else
debug "Network registeration is failed!";
fi
while true; do 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 [ $(gpio -g read 23) = "0" ]; then if [[ $PINGG -eq 0 ]]; then
echo "Power up" 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=$?
gpio -g write 24 1 if [[ $PINGG -eq 0 ]]; then
sleep 2 printf "+"
gpio -g write 24 0 else
sleep 2 debug "Connection is down, reconnecting..."
else if check_network -eq 0; then sleep 0.1; else debug "Network registeration is failed!"; fi
ping -q -I ppp0 -c 1 8.8.8.8 -s 0 >/dev/null sudo pon
fi
if [ $? -ne 0 ]; then fi
echo "Connection down, reconnecting..." sleep $INTERVAL
sudo pon
fi
fi
sleep 10
done done