Auto reconnect scrip for QMI interface using libqmi

how to get my Lte modem to auto connect on boot up using QMI interface using libqmi

Hi @bazil747,

Try to use these qmicli commands to get/set the settings:
--wds-get-autoconnect-settings : Get autoconnect settings
and:
--wds-set-autoconnect-settings=[(enabled|disabled|paused)[,(roaming-allowed|home-only)]] : Set autoconnect settings (roaming settings optional)

Examples:
qmicli -d /dev-cdc-wdm0 --wds-get-autoconnect-settings
qmicli -d /dev-cdc-wdm0 --wds-set-autoconnect-settings=enabled,home-only

QMICLI man page

or create your own service using systemd.

Thank you.

Hi @ensar,
Thank you for your answer, regarding this, when my raspi boots it runs the script which initializes wwan0 with a 10.111.100.X ip address. Once the system is working fine, if the equipment where the raspi is mounted goes through a zone where there is not good GMS signal wwan0 loses the configuration and returns to a 192.X.X.X ip address, result: zero internet connection after that. I’ve noticed in the script the –wds-set-autoconnect-settings=disabled, if I change it as you recommend, when the raspi gets again to a zone with signal, will it recover the wwan0 initial configuration or do I have to run a systemd script that identifies the “problem” and re-run the initial script in order to get my configuration back? Thank you in advance. Here is the script run at boot in case it help you understand, thank you in advance.

#!/bin/bash
LOG_PATH=“/home/pi/SIM7600-Start.log”
MAX_TRIES=10

N_TRY=0
TRY=“”

echo “Logs go to: $LOG_PATH”
rm $LOG_PATH

echo “---------------------------------” > “$LOG_PATH”
echo “Connecting 4G-LTE” >> “$LOG_PATH”
echo “$LOG_PATH”

while [ “$TRY” != “done” ]
do
N_TRY=$((N_TRY + 1))

echo “–try $N_TRY --” >> “$LOG_PATH”
echo “–try $N_TRY --”

echo “–dms SET operating mode–” >> “$LOG_PATH”
echo “–dms SET operating mode–”

sudo qmicli -d /dev/cdc-wdm0 --dms-set-operating-mode=‘online’ >> “$LOG_PATH”

echo “–dms GET operating mode–” >> “$LOG_PATH”
echo “–dms GET operating mode–”

sudo qmicli -d /dev/cdc-wdm0 --dms-get-operating-mode >> “$LOG_PATH”

if [ “$N_TRY” = “$MAX_TRIES” ]
then

  echo "reached MAX_TRIES = $MAX_TRIES" >> "$LOG_PATH"
  echo "reached MAX_TRIES = $MAX_TRIES"

  TRY="done"

fi
temp=“$(grep -c “online” “$LOG_PATH”)”

if [ $temp -eq 1 ]
then
echo “Success! <0.0>” >> “$LOG_PATH”
grep “online” “$LOG_PATH” >> “$LOG_PATH”

  echo "Success! <0.0>"
  grep "online" "$LOG_PATH"

  TRY="done"

fi
done

echo “Needed $N_TRY tries to connect” >> “$LOG_PATH”
echo “-get-signal-strength-------------” >> “$LOG_PATH”

echo “Needed $N_TRY tries to connect”
echo “-get-signal-strength-------------”

sudo qmicli -d /dev/cdc-wdm0 --nas-get-signal-strength >> “$LOG_PATH”

tail -14 “$LOG_PATH”

echo “-get-home-network----------------” >> “$LOG_PATH”

echo “-get-home-network----------------”

sudo qmicli -d /dev/cdc-wdm0 --nas-get-home-network >> “$LOG_PATH”

echo “- -w ----------------------------” >> “$LOG_PATH”

echo “- -w ----------------------------”

sudo qmicli -d /dev/cdc-wdm0 -w >> “$LOG_PATH”

echo “-wwan0 down----------------------” >> “$LOG_PATH”

echo “-wwan0 down----------------------”

sudo ip link set wwan0 down >> “$LOG_PATH”

echo “-raw_ip → Y---------------------” >> “$LOG_PATH”

echo “-raw_ip → Y---------------------”

echo ‘Y’ | sudo tee /sys/class/net/wwan0/qmi/raw_ip >> “$LOG_PATH”

echo “-wwan0 up------------------------” >> “$LOG_PATH”

echo “-wwan0 up------------------------”

sudo ip link set wwan0 up >> “$LOG_PATH”

echo “-get-autoconnect-settings--------” >> “$LOG_PATH”

echo “-get-autoconnect-settings--------”

sudo qmicli -d /dev/cdc-wdm0 --wds-get-autoconnect-settings >> “$LOG_PATH”

echo “-set-autoconnect-settings--------” >> “$LOG_PATH”

echo “-set-autoconnect-settings--------”

sudo qmicli -d /dev/cdc-wdm0 --wds-set-autoconnect-settings=disabled >> “$LOG_PATH”

tail -2 “$LOG_PATH”

echo “if error 26 → its ok. It means that autoconnect was already disabled” >> “$LOG_PATH”
echo “-start network-------------------” >> “$LOG_PATH”

echo “if error 26 → its ok. It means that autoconnect was already disabled”
echo “-start network-------------------”

N_TRY=0
TRY=“”
while [ “$TRY” != “done” ]
do
N_TRY=$((N_TRY + 1))

echo “–try $N_TRY --” >> “$LOG_PATH”
echo “–try $N_TRY --”

sudo qmicli -p -d /dev/cdc-wdm0 --device-open-net=‘net-raw-ip|net-no-qos-header’ --wds-start-network=“apn=‘orange’,username=‘orange’,password=‘orange’,ip-type=4” --client-no-release-cid >> “$LOG_PATH”

if [ “$N_TRY” = “$MAX_TRIES” ]
then

  echo "reached MAX_TRIES = $MAX_TRIES" >> "$LOG_PATH"
  echo "reached MAX_TRIES = $MAX_TRIES"

  TRY="done"

else
echo “…$N_TRY of $MAX_TRIES: unable to start network. Trying again in 5s.”
sleep 5
fi
temp=“$(grep -c “[/dev/cdc-wdm0] Network started” “$LOG_PATH”)”

if [ $temp -eq 1 ]
then
echo “…$N_TRY of $MAX_TRIES: Success!” >> “$LOG_PATH”
grep “[/dev/cdc-wdm0] Network started” “$LOG_PATH” >> “$LOG_PATH”

  echo "...$N_TRY of $MAX_TRIES: Success!"
  grep "\[/dev/cdc-wdm0\] Network started" "$LOG_PATH"

  TRY="done"

fi
done

echo “network started ?”
echo “network started ?” >> “$LOG_PATH”

echo “-start---------------------------” >> “$LOG_PATH”

echo “-start---------------------------”

sudo qmi-network /dev/cdc-wdm0 start >> “$LOG_PATH”

echo “-udhcpc--------------------------” >> “$LOG_PATH”

echo “-udhcpc--------------------------”

sudo udhcpc -t 10 -i wwan0 >> “$LOG_PATH”

echo “-ip a s--------------------------” >> “$LOG_PATH”

echo “-ip a s--------------------------”

ip a s wwan0 >> “$LOG_PATH”

echo “-ip r s--------------------------” >> “$LOG_PATH”

echo “-ip r s--------------------------”

ip r s >> “$LOG_PATH”

echo “-ifconfig------------------------” >> “$LOG_PATH”
echo “ifconfig” >> “$LOG_PATH”
echo “---------------------------------” >> “$LOG_PATH”
ifconfig wwan0

ifconfig >> “$LOG_PATH”

echo “-manufacturer--------------------” >> “$LOG_PATH”
sudo qmicli --device=/dev/cdc-wdm0 --device-open-proxy --dms-get-manufacturer >> “$LOG_PATH”

echo “-model---------------------------” >> “$LOG_PATH”
sudo qmicli --device=/dev/cdc-wdm0 --device-open-proxy --dms-get-model >> “$LOG_PATH”

echo “-firmware------------------------” >> “$LOG_PATH”
sudo qmicli --device=/dev/cdc-wdm0 --device-open-proxy --dms-get-revision >> “$LOG_PATH”

echo “-IMEI----------------------------” >> “$LOG_PATH”
sudo qmicli --device=/dev/cdc-wdm0 --device-open-proxy --dms-get-ids >> “$LOG_PATH”

echo “-qmicli version------------------” >> “$LOG_PATH”
sudo qmicli --version >> “$LOG_PATH”

echo “-final-testing-------------------” >> “$LOG_PATH”
sudo ping -c 1 -I wwan0 8.8.8.8 >> “$LOG_PATH”

echo “-final-testing-------------------”
#sudo ping -c 1 -I wwan0 8.8.8.8
tail -7 “$LOG_PATH”