From 3d966989014229833b85a21ff69aba0658c41609 Mon Sep 17 00:00:00 2001 From: Yasin Kaya Date: Mon, 23 Nov 2020 16:44:06 +0300 Subject: [PATCH] Added BG9X modules to configure_modem.sh Added rpi max power settings for base hat --- install.sh | 2 +- src/configure_modem.sh | 137 ++++++++++++++++++++++++++++++++++------- 2 files changed, 117 insertions(+), 22 deletions(-) diff --git a/install.sh b/install.sh index ab75856..8f67bd1 100755 --- a/install.sh +++ b/install.sh @@ -136,7 +136,7 @@ if ! (grep -q 'sudo route' /etc/ppp/ip-up ); then echo "sudo route add default ppp0" >> /etc/ppp/ip-up fi -if [ $shield_hat -eq 2 ]; then +if [[ $shield_hat -eq 2 ]] || [[ $shield_hat -eq 6 ]]; then if ! (grep -q 'max_usb_current' /boot/config.txt ); then echo "max_usb_current=1" >> /boot/config.txt fi diff --git a/src/configure_modem.sh b/src/configure_modem.sh index 3c21282..7b272a0 100644 --- a/src/configure_modem.sh +++ b/src/configure_modem.sh @@ -2,37 +2,132 @@ source functions.sh +# Check the vendor +lsusb | grep Quectel >> /dev/null +IS_QUECTEL=$? + +lsusb | grep Telit >> /dev/null +IS_TELIT=$? + + ### Modem configuration for RMNET/PPP mode ################################## debug "Checking APN and Modem Mode..." -# APN +# APN Configuration +# ----------------- atcom "AT+CGDCONT?" | grep super >> /dev/null if [[ $? -ne 0 ]]; then - atcom "AT+CGDCONT=1,\"IP\",\"super\"" + atcom "AT+CGDCONT=1,\"IPV4V6\",\"super\"" debug "APN is updated." fi -atcom "AT#USBCFG?" | grep 0 >> /dev/null +# Modem Mode Configuration +# ------------------------ +# For Quectel +if [[ $IS_QUECTEL -eq 0 ]]; then -if [[ $? -ne 0 ]]; then - atcom "AT#USBCFG=0" - debug "RMNET/PPP mode is activated." - debug "Modem restarting..." + lsusb | grep BG9 > /dev/null + MODEL_BG9X=$? - sleep 20 - - # Check modem is started! - for i in {1..120}; do - route -n | grep wwan0 >> /dev/null - if [[ $? -eq 0 ]]; then - echo - debug "Modem is restarted." - break + if [[ $MODEL_BG9X -eq 0 ]]; then + # BG95 and BG96 + + # RAT Searching Sequence + atcom "AT+QCFG=\"nwscanseq\"" | grep 000201 >> /dev/null + + if [[ $? -ne 0 ]]; then + atcom "AT+QCFG=\"nwscanseq\",00" + debug "Configure RAT Searching Sequence is updated." fi - sleep 1 - printf "*" - done - sleep 5 # wait until modem is ready + + # RAT(s) to be Searched + atcom "AT+QCFG=\"nwscanmode\"" | grep 0 >> /dev/null + + if [[ $? -ne 0 ]]; then + atcom "AT+QCFG=\"nwscanmode\",0" + debug "RAT(s) to be Searched is updated." + fi + + # Network Category to be Searched under LTE RAT + atcom "AT+QCFG=\"iotopmode\"" | grep 0 >> /dev/null + + if [[ $? -ne 0 ]]; then + atcom "AT+QCFG=\"iotopmode\",0" + debug "Network Category to be Searched under LTE RAT is updated." + fi + + # end of configuraiton for BG95/6 + else + # EC25 or derives. + atcom "AT+QCFG=\"usbnet\"" | grep 0 >> /dev/null + + if [[ $? -ne 0 ]]; then + atcom "AT+QCFG=\"usbnet\",0" + debug "PPP mode is activated." + debug "Modem restarting..." + + sleep 20 + + # Check modem is started + route -n | grep wwan0 >> /dev/null + if [[ $? -eq 0 ]]; then + echo + else + # If modem don't reboot automatically, reset manually + atcom "AT+CFUN=1,1" # rebooting modem + sleep 20 + fi + + # Check modem is started! + for i in {1..120}; do + route -n | grep wwan0 >> /dev/null + if [[ $? -eq 0 ]]; then + echo + debug "Modem is restarted." + break + fi + sleep 1 + printf "*" + done + sleep 5 # wait until modem is ready + fi + fi + +# For Telit +elif [[ $IS_TELIT -eq 0 ]]; then + atcom "AT#USBCFG?" | grep 4 >> /dev/null + + if [[ $? -ne 0 ]]; then + atcom "AT#USBCFG=4" + debug "ECM mode is activated." + debug "Modem restarting..." + + sleep 20 + + # Check modem is started! + for i in {1..120}; do + route -n | grep wwan0 >> /dev/null + if [[ $? -eq 0 ]]; then + echo + debug "Modem is restarted." + break + fi + sleep 1 + printf "*" + done + sleep 5 # wait until modem is ready + fi + +# Unknown +else + debug "The cellular module couldn't be detected!" + exit 1 fi -### End of Modem configuration for RMNET/PPP mode ############################ \ No newline at end of file +### End of Modem configuration for ECM mode ############################ + + +# Check the network is ready +# -------------------------- +if check_network -eq 0; then exit 0; else debug "Network registeration is failed!"; exit 1; fi +