Best way to detect the modem

I have a few cameras on the field, some of them have the modems and some don’t.

What’s the most reliable way to detect if the modem is present before trying to enable it? I tried looking for the presence of /dev/ttyUSB0 but that only shows up after the modem is enabled.

I detect modems by looking at the output of the lsusb command.

One thing to watch out for is at boot time your script might start before the USB subsystem is all the way up (I typically start things from /etc/rc.local). You can mitigate that by going all-in with systemd or with some guard code in your startup script like this:


# this is here because usb comes up in parallel with rc.local and might not be ready yet
# usually ten seconds is more than sufficient for usb to come up properly
while [ $found -le 1 ]
  if lsusb | egrep Telit; then
      echo "[start] Found Telit"
      echo "[start] Telit not found"
      found=`expr $found + 1`
      sleep 10

if [ $found -eq 99 ]; then
  python3 ./ --verbose --init --retries 6
  python3 ./ --verbose --start --setclock