Add cellular connectivity to your Raspberry Pi

03 Oct, 2022

author avatar
Raspberry Pi to Monogoto

Raspberry Pi to Monogoto

Adding cellular connectivity to your Raspberry Pi can be done in a few simple steps.

Are you planning to deploy single board computers, like the Raspberry Pi? Consider adding a cellular modem to be in control of the connectivity and not be dependent on Wifi or Ethernet. Although this may sound complicated, it is rather easy and can be accomplished in a few simple steps.


Selecting your hardware

The first step is to get ourselves a cellular modem which allows the Raspberry Pi to connect to a mobile operator. There are many modem manufacturers out there, supporting different wireless technologies for different regions.

Start with deciding what cellular technology is required for your use case. LTE comes in different categories, each support different data rates. When you only need to send occasional (sensor) data, consider LTE Cat 1 or the novel cellular standard LTE-M which comes at a relatively low price point. The higher the LTE category, the more data you can send and the more expensive the module becomes.  

LTE Category
Data rate DL
Data rate UL
LTE-M1 Mbit/s1 Mbit/s
LTE Cat 110 Mbit/s5 Mbit/s
LTE Cat 3100 Mbit/s50 Mbit/s
LTE Cat 4150 Mbit/s50 Mbit/s
LTE Cat 6300 Mbit/s50 Mbit/s
LTE Cat 9450 Mbit/s50 Mbit/s
LTE Cat 12600 Mbit/s100 Mbit/s

⚠️ Be careful when choosing your cellular modem. Not all modems support all frequencies used globally. Make sure to double check if the modem supports the radio frequencies in your region (this is usually listed in the modem’s data sheet). When using LTE-M, validate if your operator supports this LTE version in your local area.

When purchasing a cellular modem, make sure to purchase a mini PCIe form factor along with a USB dongle with mini PCIe slot to easily connect the modem to the Raspberry Pi.

Purchase list

In this tutorial, a Raspberry Pi 4 with Sierra Wireless MC7700 and Monogoto SIM is used.


Tutorial

Access the Raspberry Pi by connecting a screen and keyboard (recommended) or connect over SSH.

Install required packages

Open the terminal and validate if the NetworkManager and ModemManager are installed.

NetworkManager -V
ModemManager -V

Make sure that the Raspberry Pi runs NetworkManager version 1.3 or higher and ModemManager version 1.14 or higher. If this is not the case, update or install the NetworkManager and ModemManager using the command:

sudo apt install network-manager modemmanager

In addition, install the libqmi-utils and udhcpc packages.

sudo apt install libqmi-utils udhcpc

Connect the modem to the Raspberry Pi

Add the mini PCle cellular modem to the USB adapter

Add the Monogoto SIM to the USB adapter

Connect the LTE antenna using the UFl connector

Connect the cellular PCle card to the Raspberry Pi, using the USB port


Open the CLI (Command Line Interface) and see of the USB with cellular modem gets detected:

lsusb

Bus 001 Device 004: ID 1199:68a2 Sierra Wireless, Inc. MC7700

The cellular modem requires the driver qmi_wwan. To verify if the driver is compatible with the modem, enter lsusb -t:

lsusb -t

|__ Port 2: Dev 4, If 8, Class=Vendor Specific Class, Driver=qmi_wwan, 480M

Check what USB port the cellular modem is connected to:

dmesg | grep tty

[6.728605] usb 1-1.2: Qualcomm USB modem converter now attached to ttyUSB0
[6.823516] usb 1-1.2: Qualcomm USB modem converter now attached to ttyUSB1
[6.868118] usb 1-1.2: Qualcomm USB modem converter now attached to ttyUSB2

Start and enable the NetworkManager

Start and enable the NetworkManager, when doing so you will be asked to fill out your root password.

systemctl start NetworkManager
systemctl enable NetworkManager

After enabling the NetworkManager, the Wifi connection of your Raspberry Pi breaks.

To activate your Wifi again, enter:

nmcli device wifi connect "<SSID>" password "<PASSWORD>"

Device 'wlan0' successfully activated

Create a new connection interface

Create a new connection with name monogoto and set the APN to data.mono:

nmcli c add type gsm ifname '*' con-name monogoto apn data.mono connection.autoconnect yes

Connection `monogoto` (...) successfully added.

To test if the connection was successfully added, a new file with the name monogoto.nmconnection is created and added to the directory system-connections

ls /etc/NetworkManager/system-connections

When opening this file (using sudo vi) it should show something like:

[connection]
id=monogoto
uuid=XXXXX
type=gsm
permissions=
autoconnect=true

[gsm]
apn=data.mono

[ipv4]
dns-search=
method=auto

[ipv6]
addr-gen-mode=stable-privacy
dns-search=
method=auto

Start the connection

Manually start the connection using the command:

nmcli c up monogoto

Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/0)

Validate the connection

The connection with name monogoto should be linked to the device called cdc-wdm0. If the connection is active, everything is displayed in green.

nmcli c

NAME         UUID         TYPE      DEVICE      
monogoto     .....        gsm       cdc-wdm0
wifi-name    .....        wifi      wlan0

View connection details

List the connected modems:

mmcli -L

/org/freedesktop/ModemManager1/Modem/0 […]

Request information about the connected modem.
Replace 0 with the value you found when running mmcli -L

mmcli -m 0

  Status   |       unlock retries: sim-pin (3), sim-puk (10), sim-pin2 (3), sim-puk2 (10)
           |                state: connected
           |          power state: on
           |          access tech: lte
           |       signal quality: 86% (recent)

Check if the cellular interface is added, and if an IP address was derived. Look for the interface with name wwan0

ifconfig

wwan0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST>  mtu 1500
        inet 10.XXX.XXX.XX  netmask 255.255.255.252  destination 10.XXX.XXX.XX
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 1000  (UNSPEC)
        RX packets 7  bytes 1050 (1.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 52  bytes 8118 (7.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ℹ️ If no wwan0 interface is visible, disconnect the USB with PCIe and reboot the Raspberry Pi. Connect the USB dongle again after the Raspberry Pi has fully booted.

Check the default IP route:

ip route

default via 10.xxx.xxx.xx dev wlan0 proto static metric 600
default via 10.xxx.xxx.xx dev wwan0 proto static metric 700

The lower the metric number, the higher the priority of the connection. In the above example, the wlan0 (wifi) interface has a higher priority than the wwan0 (cellular) interface. 

Change priority of the connections (optional)

To change the priorities of the connections, the metric numbers needs to be adapted. To do so, go to the directory: /etc/NetworkManager/system-connections

Open the file (using sudo vi) monogoto.nmconnection

Add the line route-metric=200 under the section [ipv4]. The file becomes:

[connection]
id=monogoto
uuid=.........
type=gsm
permissions=
autoconnect=true

[gsm]
apn=data.mono

[ipv4]
dns-search=
method=auto
route-metric=200

[ipv6]
addr-gen-mode=stable-privacy
dns-search=
method=auto

Restart the NetworkManager

systemctl restart NetworkManager

Validate the connectivity priorities:

ip route

default via 10.xxx.xxx.xx dev wwan0 proto static metric 200
default via 10.xxx.xxx.xx dev wlan0 proto static metric 600

Test the connection by sending a PING

Ping IP address 8.8.8.8 to validate the data connection:

ℹ️ When multiple connections are up and running, specify the use of the wwan0 interface through: ping -I wwan0 8.8.8.8

ℹ️ Optionally, you can disable other interfaces (for example the wlan0) using the command: ip link set dev wlan0 down

ping 8.8.8.8

PING 8.8.8.8 (8.8.8.8): 56(84) bytes of data
64 bytes from 8.8.8.8: icmp_seq=1 ttl=112 time=72.3 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=112 time=70.8 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=112 time=82.9 ms
64 bytes from 8.8.8.8: icmp_seq=4 ttl=112 time=78.7 ms

ℹ️ If no wwan0 interface is visible, or the pings result in errors, disconnect the USB with PCIe and reboot the Raspberry Pi. Connect the USB dongle again after the Raspberry Pi has fully booted.

ℹ️ To find NetworkManager logs, enter: systemctl status NetworkManager

Did you manage to connect your Raspberry Pi to Monogoto? Great work! 👏 Have a look at the Things logs in the Monogoto Hub to find more details about the established connection.

More by Monogoto

Monogoto is a cloud-based cellular network, providing IoT, Private LTE, and 5G connectivity in 180+ countries. Its API-driven Infrastructure-as-a-Service was designed from the ground up with simplicity in mind to enable cellular connectivity with existing enterprise IT infrastructure.