<div dir="ltr"><div><div>I have a 4G LTE modem (Sierra Wireless MC7354) on an embedded Linux device. I'm struggling to understand the best way to detect a loss of signal and gracefully reconnect. On power up, I can connect to the Verizon LTE network using this script:<br></div><br></div>### Script Begin ###<br><div><span style="font-family:monospace,monospace">if [ ! -f /etc/qmi-network.conf ]; then<br></span></div><div><span style="font-family:monospace,monospace">    #only needs to run once ever<br></span></div><div><span style="font-family:monospace,monospace">    echo "APN=WE01.VZWSTATIC" > /etc/qmi-network.conf<br>    echo "PROXY=yes" >> /etc/qmi-network.conf<br>fi<br><br>qmicli -p -d /dev/cdc-wdm0 --wda-set-data-format=802-3<br>qmi-network /dev/cdc-wdm0 start<br>ip link set wwan0 up<br>udhcpc -t 2 -n -i wwan0</span><br></div><div>### Script End ###<br><br></div><div>My first issue is just detecting when the signal is lost. I simulate a bad connection by unplugging the LTE antenna. If I run --wds-get-packet-service-status, it just keeps telling me "connected" even when the signal is completely lost for several minutes. I've found I have to ping a server (usually  8.8.8.8) to know the signal is lost.<br><br></div><div>Then, when I plug the antenna back in after several minutes, it continues to think it's connected, but I can't ping anything. I do this:<br><span style="font-family:monospace,monospace">qmi-network /dev/cdc-wdm0 stop<br><span style="font-family:monospace,monospace">qmi-network /dev/cdc-wdm0 start</span><br><span style="font-family:monospace,monospace">udhcpc -t 2 -n -i wwan0</span><br><br></span></div><div><span style="font-family:monospace,monospace"><font face="arial,helvetica,sans-serif">But I get a "CallFailed" error with reason "generic-no-service". Something seems to be hung up after it losses the signal and it can't recover, even after the antenna is back in place and it should be getting good signal.<br><br></font></span></div><div><span style="font-family:monospace,monospace"><font face="arial,helvetica,sans-serif">So then I tried enabling autoconnect. When it's enabled on bootup, I run the following commands at the prompt:<br><span style="font-family:monospace,monospace">ip link set wwan0 up<br>udhcpc -t 2 -n -i wwan0</span><br><br></font></span></div><div><span style="font-family:monospace,monospace"><font face="arial,helvetica,sans-serif">But the udhcpc call fails. So I figured out I have to disable autoconnect on bootup, run the original script above, then re-enable autoconnect. Under those conditions, I can run udhcpc after the signal is lost and recovered and <i>usually</i> it will re-obtain the IP address and let me back on the network. Even if that usually works, my script would fail if the LTE signal is not present at the beginning on power-up.<br><br></font></span></div><div><span style="font-family:monospace,monospace"><font face="arial,helvetica,sans-serif">I feel like I'm approaching this wrong. It seems like dealing with finicky signal strength is par for the course in any wireless device. I'd appreciate any pointers on best practices for gracefully handling lost connections and reconnects. Thank you.<br></font></span></div></div>