diff --git a/install.sh b/install.sh index 3b7e98d..566b75b 100755 --- a/install.sh +++ b/install.sh @@ -17,6 +17,20 @@ BLUE='\033[1;34m' GREEN='\033[0;32m' SET='\033[0m' +# Global Varibales +POWERUP_REQ=1 +POWERUP_NOT_REQ=0 + +STATUS_GPRS=19 +STATUS_CELL_IOT_APP=20 +STATUS_CELL_IOT=23 +STATUS_TRACKER=23 + +POWERKEY_GPRS=26 +POWERKEY_CELL_IOT_APP=11 +POWERKEY_CELL_IOT=24 +POWERKEY_TRACKER=24 + function colored_echo { @@ -197,32 +211,52 @@ do wget --no-check-certificate $SCRIPT_PATH/reconnect_gprsshield -O $RECONNECT_SCRIPT_NAME if [[ $? -ne 0 ]]; then colored_echo "Download failed" ${RED}; exit 1; fi + + sed -i "s/STATUS_PIN/$STATUS_GPRS/" configure_modem.sh + sed -i "s/POWERKEY_PIN/$POWERKEY_GPRS/" configure_modem.sh + sed -i "s/POWERUP_FLAG/$POWERUP_REQ/" configure_modem.sh elif [ $shield_hat -eq 2 ]; then wget --no-check-certificate $SCRIPT_PATH/reconnect_baseshield -O $RECONNECT_SCRIPT_NAME if [[ $? -ne 0 ]]; then colored_echo "Download failed" ${RED}; exit 1; fi + + sed -i "s/POWERUP_FLAG/$POWERUP_NOT_REQ/" configure_modem.sh elif [ $shield_hat -eq 3 ]; then wget --no-check-certificate $SCRIPT_PATH/reconnect_cellulariot_app -O $RECONNECT_SCRIPT_NAME if [[ $? -ne 0 ]]; then colored_echo "Download failed" ${RED}; exit 1; fi + + sed -i "s/STATUS_PIN/$STATUS_CELL_IOT_APP/" configure_modem.sh + sed -i "s/POWERKEY_PIN/$POWERKEY_CELL_IOT_APP/" configure_modem.sh + sed -i "s/POWERUP_FLAG/$POWERUP_REQ/" configure_modem.sh elif [ $shield_hat -eq 4 ]; then wget --no-check-certificate $SCRIPT_PATH/reconnect_cellulariot -O $RECONNECT_SCRIPT_NAME if [[ $? -ne 0 ]]; then colored_echo "Download failed" ${RED}; exit 1; fi + + sed -i "s/STATUS_PIN/$STATUS_CELL_IOT/" configure_modem.sh + sed -i "s/POWERKEY_PIN/$POWERKEY_CELL_IOT/" configure_modem.sh + sed -i "s/POWERUP_FLAG/$POWERUP_REQ/" configure_modem.sh elif [ $shield_hat -eq 5 ]; then wget --no-check-certificate $SCRIPT_PATH/reconnect_tracker -O $RECONNECT_SCRIPT_NAME if [[ $? -ne 0 ]]; then colored_echo "Download failed" ${RED}; exit 1; fi + sed -i "s/STATUS_PIN/$STATUS_TRACKER/" configure_modem.sh + sed -i "s/POWERKEY_PIN/$POWERKEY_TRACKER/" configure_modem.sh + sed -i "s/POWERUP_FLAG/$POWERUP_REQ/" configure_modem.sh + elif [ $shield_hat -eq 6 ]; then wget --no-check-certificate $SCRIPT_PATH/reconnect_basehat -O $RECONNECT_SCRIPT_NAME if [[ $? -ne 0 ]]; then colored_echo "Download failed" ${RED}; exit 1; fi + sed -i "s/POWERUP_FLAG/$POWERUP_NOT_REQ/" configure_modem.sh + fi mv functions.sh $PPP_PATH diff --git a/src/configure_modem.sh b/src/configure_modem.sh index 2196842..bc72afd 100644 --- a/src/configure_modem.sh +++ b/src/configure_modem.sh @@ -2,6 +2,46 @@ source functions.sh +# default pins set for cellulariot hat +STATUS=${STATUS_PIN:-23} +POWERKEY=${POWERKEY_PIN:-24} +POWER_UP_REQUIRED=${POWERUP_FLAG:-1} + +# 1 : STATUS +# 2 : POWERKEY +function power_up_module +{ + # Configure pins + gpio -g mode $STATUS in + gpio -g mode $POWERKEY out + + 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 + fi + else + debug "Module is just powered up." + return 0 + break + fi + done + return 1 +} + # Check the vendor lsusb | grep Quectel >> /dev/null IS_QUECTEL=$? @@ -10,6 +50,12 @@ lsusb | grep Telit >> /dev/null IS_TELIT=$? +if [[ $POWER_UP_REQUIRED -eq 1 ]]; then + if power_up_module -eq 0 ; then sleep 0.1; else debug "Module couldn't be powered up! Check the hardware setup!"; fi +else + debug "Power up is not required." +fi + ### Modem configuration for RMNET/PPP mode ################################## debug "Checking APN and Modem Mode..." diff --git a/src/reconnect_scripts/reconnect_cellulariot b/src/reconnect_scripts/reconnect_cellulariot index 52c9789..300d4ff 100644 --- a/src/reconnect_scripts/reconnect_cellulariot +++ b/src/reconnect_scripts/reconnect_cellulariot @@ -32,6 +32,7 @@ function power_up_module() else debug "Module couldn't be powered up!" sleep 2 + fi else debug "Module is just powered up." return 0 diff --git a/src/reconnect_scripts/reconnect_cellulariot_app b/src/reconnect_scripts/reconnect_cellulariot_app index 69c4d6a..f2391f5 100644 --- a/src/reconnect_scripts/reconnect_cellulariot_app +++ b/src/reconnect_scripts/reconnect_cellulariot_app @@ -33,6 +33,7 @@ function power_up_module() else debug "Module couldn't be powered up!" sleep 2 + fi else debug "Module is just powered up." return 0 diff --git a/src/reconnect_scripts/reconnect_gprsshield b/src/reconnect_scripts/reconnect_gprsshield index 926d44a..ca12a04 100644 --- a/src/reconnect_scripts/reconnect_gprsshield +++ b/src/reconnect_scripts/reconnect_gprsshield @@ -33,6 +33,7 @@ function power_up_module() else debug "Module couldn't be powered up!" sleep 2 + fi else debug "Module is just powered up." return 0 diff --git a/src/reconnect_scripts/reconnect_tracker b/src/reconnect_scripts/reconnect_tracker index 33b8e32..cb78212 100644 --- a/src/reconnect_scripts/reconnect_tracker +++ b/src/reconnect_scripts/reconnect_tracker @@ -33,6 +33,7 @@ function power_up_module() else debug "Module couldn't be powered up!" sleep 2 + fi else debug "Module is just powered up." return 0