# Raspberry Pi

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

<figure><img src="https://3922449203-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M0mPxGpottOEfcucXOR%2Fuploads%2Fi5JhFaSHI3mknBeIdw9V%2FIMG_0780.jpeg?alt=media&#x26;token=7a1ccfcb-557f-4354-870f-548620a50f6e" alt=""><figcaption></figcaption></figure>

### Quick Navigation

* [Getting Started](#getting-started)
* [Create a new connection interface](#create-a-new-connection-interface)
* [Check the default IP route](#check-the-default-ip-route)
* [Send a Ping](#test-the-connection-by-sending-a-ping)

### Prerequisites

* Monogoto SIM
* Raspberry Pi 3 or 4
* USB adapter with mini PCIe and SIM slot ([example](https://www.amazon.com/dp/B07YY5967K))
* Mini PCIE cellular modem, for example:
  * *Sierra Wireless MC7700 (LTE)*
  * *Telit ME910C1-WW mini PCle (LTE-M & NB-IoT)*
  * *Quectel EC25 mini PCle (LTE)*

## Getting Started

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.

```bash
NetworkManager -V
ModemManager -V
```

{% hint style="info" %}
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:

```bash
sudo apt install network-manager modemmanager
```

{% endhint %}

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

```bash
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 cellular PCle card to the Raspberry Pi, using the USB port

<figure><img src="https://3922449203-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M0mPxGpottOEfcucXOR%2Fuploads%2Fm9picyiJmBgN5pp9uGrO%2FIMG_0795.jpeg?alt=media&#x26;token=d4f91935-aa75-473f-b384-fd28264be5f4" alt=""><figcaption></figcaption></figure>

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

```bash
lsusb
```

Example response:

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

The cellular modem requires the driver <mark style="color:red;">`qmi_wwan`</mark>, to verify if the driver is compatible with the modem, enter <mark style="color:red;">`lsusb -t`</mark>:

```bash
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.

```bash
dmesg | grep tty
```

Example response:

```bash
[    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.

```bash
systemctl start NetworkManager
```

```bash
systemctl enable NetworkManager
```

{% hint style="warning" %}
After enabling the NetworkManager, the Wifi connection of your Raspberry Pi breaks.

To activate your Wifi again, enter:

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

Expected response:

```
Device 'wlan0' successfully activated
```

{% endhint %}

## Create a new connection interface

Create a new connection with name <mark style="color:red;">`monogoto`</mark> and set the **APN** to  <mark style="color:red;">`data.mono`</mark>:

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

Expected response:

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

To test if the connection was successfully added, a new file with the name <mark style="color:red;">`monogoto.nmconnection`</mark> is created and added to the directory <mark style="color:red;">`system-connections`</mark>

```bash
ls /etc/NetworkManager/system-connections
```

When opening this file (using <mark style="color:red;">`sudo vi`</mark>) it should show something like:

```vim
[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:

```bash
nmcli c up monogoto
```

Expected response:

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

### Validate the connection

The connection with name <mark style="color:red;">`monogoto`</mark> should be linked to the device called <mark style="color:red;">`cdc-wdm0`</mark>. If the connection is active, everything is displayed in <mark style="color:green;">**green**</mark>.

```bash
nmcli c
```

Expected response:

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

#### Activate the device

Enter the following command to activate the <mark style="color:green;">**`cdc-wdm0`**</mark> device:

```
sudo nmcli device connect cdc-wdm0
```

Expected response:

```
Device 'cdc-wdm0' successfully activat
```

#### View connection details

List the connected modems:

```bash
mmcli -L
```

Expected response:

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

#### Request information about the connected modem.&#x20;

Replace <mark style="color:red;">`0`</mark> with the value you found when running <mark style="color:red;">`mmcli -L`</mark>

```bash
mmcli -m 0
```

Example response:

```bash
...
  --------------------------------
  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 <mark style="color:red;">`wwan0`</mark>

```bash
ifconfig
```

Expected response:

```bash
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
```

{% hint style="warning" %}
If no <mark style="color:red;">`wwan0`</mark> 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.
{% endhint %}

## Check the default **IP route**:

```bash
ip route
```

Expected response:

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

{% hint style="info" %}
The **lower** the metric number, the **higher** the priority of the connection. In the above example, the <mark style="color:red;">`wlan0`</mark> (wifi) interface has a higher priority than the <mark style="color:red;">`wwan0`</mark> (cellular) interface.&#x20;
{% endhint %}

**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: <mark style="color:red;">`/etc/NetworkManager/system-connections`</mark>

Open the file (using <mark style="color:red;">`sudo vi`</mark>) <mark style="color:red;">`monogoto.nmconnection`</mark>

Add the line <mark style="color:red;">`route-metric=200`</mark> under the section <mark style="color:red;">`[ipv4]`</mark>. The file becomes:

```vim
[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

```bash
systemctl restart NetworkManager
```

Validate the connectivity priorities by entering:

```bash
ip route
```

Expected response:

```
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 <mark style="color:red;">`8.8.8.8`</mark> to validate the data connection:

{% hint style="info" %}
When multiple connections are up and running, specify the use of the <mark style="color:red;">`wwan0`</mark> interface through: <mark style="color:red;">`ping -I wwan0 8.8.8.8`</mark>
{% endhint %}

{% hint style="info" %}
Optionally, you can disable other interfaces (for example the <mark style="color:red;">`wlan0`</mark>) using the command: <mark style="color:red;">`ip link set dev wlan0 down`</mark>
{% endhint %}

```bash
ping 8.8.8.8
```

Example response:

```bash
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
```

{% hint style="warning" %}
If no <mark style="color:red;">`wwan0`</mark> 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.
{% endhint %}

{% hint style="info" %}
To find NetworkManager logs, enter: <mark style="color:red;">`systemctl status NetworkManager`</mark>
{% endhint %}

{% hint style="success" %}
**Did you manage to connect your Raspberry Pi to Monogoto? Great work!** Have a look at the **Things** logs in the [**Monogoto Hub**](https://hub.monogoto.io/) to find more details about the established connection.
{% endhint %}
