skip to content

Setting up Raspberry Pi for Automatic USB Modem Connection

/ 2 min read

Prerequisites

  • Raspberry Pi with Raspbian OS installed.
  • USB modem (e.g., Quectel 200UCN).
  • NetworkManager and ModemManager packages installed:

Install Required Packages

sudo apt update
sudo apt install network-manager modemmanager

Enable and Start Services

sudo systemctl enable NetworkManager
sudo systemctl start NetworkManager

Identifying the Modem

  1. Connect the USB modem to the Raspberry Pi.
  2. Run the following command to identify the modem:
mmcli -L

This command lists all modems detected by ModemManager. Note the modem’s path (e.g., /org/freedesktop/ModemManager1/Modem/0).

Configure the Modem

  1. Create a new connection profile for the modem:
nmcli c add type gsm ifname '*' con-name MyModem apn your_apn_here connection.autoconnect yes

for example, for using airtel:

nmcli c add type gsm ifname '*' con-name airtel apn airtelgprs.com connection.autoconnect yes

Reset Raspberry Pi

  1. Reboot the Raspberry Pi to ensure all changes take effect:
sudo reboot

Activate the Connection

  1. Activate the connection:
nmcli c up airtel # Replace 'airtel' with your connection name

Verifying the Connection

  1. Check the connection status:
nmcli c show --active

This command should show the active connection with the modem.

Ping using the Modem

  1. Test the internet connection by pinging a website:
ping -I wwan0 google.com # Replace 'wwan0' with the interface name of your modem

Troubleshooting

  • If the modem does not connect, check the logs for errors:
journalctl -u ModemManager
  • Ensure that the APN settings are correct for your mobile network provider.
  • Make sure the SIM card is properly inserted and activated.
  • Check the signal strength:
mmcli -m 0 # Replace '0' with the modem index from mmcli -L
  • If you encounter issues with the connection, try restarting the modem:`

Disconnecting the Modem

  1. To disconnect the modem, use:
nmcli c down airtel # Replace 'airtel' with your connection name

Conslidated Commands

sudo apt update
sudo apt install network-manager modemmanager
sudo systemctl enable NetworkManager
sudo systemctl start NetworkManager

mmcli -L
nmcli c add type gsm ifname '*' con-name airtel apn airtelgprs.com connection.autoconnect yes
nmcli c up airtel
ping -I wwan0 google.com