Have you ever wished you could plug a SIM card directly into your Raspberry Pi (Raspberry Pi)?
On commercially available Raspberry Pi, a 4G (LTE) module can be realized with an extended HAT or with a USB-connected communication modem.
On the other hand, did you know that there are Raspberry Pi products specialized for industrial applications that allow SIM cards to be inserted without modification?
An industrial Raspberry Pi, housed in a rugged enclosure, can adapt to harsh environments such as factories. If possible, you want to keep both the SIM card and the 4G (LTE) module in it.
PiLink offers a model that supports 4G (LTE) communication, so we borrowed one to try it out.
Mobile Communications on the Industrial Raspberry Pi
This article is recommended for those who have the following problems
- I want to use Raspberry Pi for industrial applications, but do I have to get a separate 4G (LTE) module?
- You want to send data from a remote location, but you don’t have a network environment.
- I want to reduce running costs with a low-cost SIM, but is the SIM specified?
- You want to set it up outdoors in the hot sun, but the Raspberry Pi wouldn’t survive it in the first place, would it?
There are products that are not cellular models like tablets, but can be operated all in one housing.
I can operate both the communication module and SIM card more safely because of the robust housing that can withstand harsh installation environments.
Environment of this time
The following devices, OS versions, and environments were used to test 4G (LTE) communications.
- Industrial Raspberry Pi “PL-R4”
- Communication module + communication antenna built into chassis
- DoCoMo SIM card (DoCoMo is Japan’s telecommunications company.)
- OS boot with eMMC
- Raspberry Pi OS (bullseye)
- Connect to a monitor to check
The communication module in the photo is Sierra Wireless’ EM7431.
The supported bands are wide and the speed is perfect.
Not only the three major carriers are available for SIM cards, but also MVNOs, so called “low-cost SIMs.
Supported band ranges:
4G(LTE) | B1, B3, B5, B8, B18, B19, B39, B41, B42, B43 |
---|---|
3G | B1, B5, B6, B19 |
- Peak download speed: 300 Mbps
- Peak upload speed: 150 Mbps
EM7431 Industrial-grade IoT Module
https://www.sierrawireless.com/iot-modules/4g-modules/em7431/
SIM card can be inserted without modification
The device we tested can accommodate a 4G (LTE) communication module behind the internal carry board. (Exclusive use with NVMe-connected SSD drive)
SIM card is provided with an insertion slot below the microSD card.
Both are integrated into the chassis, eliminating the need to connect a separate device (expansion HAT or USB).
Easy setup with NetworkManager
As many of you may know, the Raspberry Pi OS (hereafter referred to as RPi OS) has replaced NetWorkManager as the tool software for network management configuration since the bookworm version.
Some people may be confused by the change in the way to set up the Wi-Fi connection settings, including the fixed IP address.
Although the configuration method has changed, the impression is that it has become simpler, as it can be set by executing a single line of command.
What I felt after trying this time was that it was very easy to set up 4G (LTE) with NetworkManager, even with bullseye.
To begin with, the 4G (LTE) communication module is recognized from the beginning as a device.
After inserting the SIM and completing the connection settings, you will be given a global IP and connected to the Internet.
At the same time, if a firewall (using UFW) is set up as a security measure, it can be immediately utilized and tested on site.
Bullseye is dhcpcd
The Raspberry Pi OS is still default (standard) with dhcpcd in the bullseye version. I am trying to get connection information out, but nmcli is not running.
nmcli con show
Error: NetworkManager is not running.
I have not yet switched to NetworkManager, but if you check with the ip command, you will see wwan0 in the 5th position. This is the 4G (LTE) communication module connected. It is already recognized as a device.
ip a
5: wwan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 1000
[The rest is omitted]
Switch to NetworkManager since it is still dhcpcd.
The reason for the switch is that NetworkManager is standard on the latest version of the Raspberry Pi OS, and it is very easy to set up 4G (LTE) communication with NetworkManager. With NetworkManager, it is a single command line, so it is very easy.
The changes are simply selected with the raspi-config command.
sudo raspi-config
Note: Wi-Fi and network communication settings will have to be redone.
From the raspi-config menu, follow “6 Advanced Option -> AA Network Config” to configure the settings.
If you select NetworkManager and accept, you will be prompted to reboot, and the change will take effect after the reboot.
nmcli command for connection settings
NetworkManager connection settings can be configured with the nmcli command. If you are connected to a monitor, you can also configure the settings on the desktop screen.
Since commands are rather easier than GUI, we are showing you how to configure the settings with commands in this article.
Now, let’s hit the nmcli command as before.
If the modified NewworkMnager is running, cdc-wdm0 can be confirmed.
nmcli device status
DEVICE TYPE STATE CONNECTION
eth0 ethernet connected Wired connection 1
wlan0 wifi disconnected --
p2p-dev-wlan0 wifi-p2p disconnected --
eth1 ethernet unavailable --
cdc-wdm0 gsm unavailable --
lo loopback unmanaged --
In this status, it is connected to the net with wired connection 1 (eth0).
The 4G (LTE) communication module is cdc-wdm0, gsm type and has a status of unavailable. This is because I have not inserted the SIM card yet.
The SIM card will be inserted later, but continue to use the nmcli con show command to check the name of the device currently connected.
Wi-Fi and 4G (LTE) are not shown because the connection has not yet been set up.
Once the connection is set up, it will be displayed here as well. Please check after setting up.
nmcli con show
NAME UUID TYPE DEVICE
Wired connection 1 b27d80c1-XXXX-XXXX-XXXX-XXXXXXXXXXXX ethernet eth0
Wired connection 2 3XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX ethernet --
The desktop screen will appear as follows and can be configured from here.
However, we recommend command execution because a command in the CUI requires only one command execution.
UFW – Firewall
We would like to insert the SIM card and set up the connection information with nmcli as soon as possible, but let’s set up the UFW, the firewall, first.
These are dangerous times. We should set up UFW in advance to prevent intrusion even for a short time.
UFW stands for “Uncomplicated Firewall” and is a very simple firewall.
Installation Method:
sudo apt update
sudo apt install -y ufw
First, let’s check the status of UFW.
At first, it is marked as inactive and is not moving.
sudo ufw status
Status: inactive
Next, we will allow ports.
First, set the default to deny before proceeding.
sudo ufw default deny
If you are using the “PL-R4” you are trying, you should also allow nodered ports.
Ports should be changed or added depending on the environment.
- web Port 80
- nodered Port 1880
- ssh port 22
- vnc port 5900
sudo ufw allow 80
sudo ufw allow 1880
ssh and vnc were allowed only from local addresses.
sudo ufw allow from 192.168.0.0/24 to any port 22
sudo ufw allow from 192.168.0.0/24 to any port 5900
sudo ufw allow from 192.168.1.0/24 to any port 22
sudo ufw allow from 192.168.1.0/24 to any port 5900
Enable at the end.
This will remain in effect after rebooting.
sudo ufw enable
Conversely, if you want to stop UFW, the disable command. Leave it enabled for now.
sudo ufw disable
The ufw numbered command is used to check the list of settings.
The status is now active and each configured port is shown.
sudo ufw numbered
Status: active
To Action From
-- ------ ----
80 ALLOW Anywhere
1880 ALLOW Anywhere
22 ALLOW 192.168.0.0/24
5900 ALLOW 192.168.0.0/24
80 (v6) ALLOW Anywhere (v6)
1880 (v6) ALLOW Anywhere (v6)
Firewall settings should be adjusted in a timely manner according to the environment in which they are used.
In this case, we will allow the ports used above to proceed.
Connection setup with 4G (LTE) communication module
Before setting up the connection, insert the SIM card and connect the antenna as well.
They have several types of antennas for LTE to choose from. This time it is a flat antenna.
This type has 3M tape on the back and can be flipped onto a plastic or glass surface.
Once shut down, each was installed and booted.
Configure connection settings
The format of the command to set the connection is as follows
sudo nmcli con add type gsm ifname "*" \
con-name Connection name \
apn Access point name \
user User name \
password Password
Your SIM card contract documents should have the APN, ID, and PWD listed. We will apply them.
The connection name is arbitrary and is named after the company with which you have a contract (e.g., ocn-net for OCN). (For OCN, it would be ocn-net, etc.)
nmcli add to add a connection destination, connection type is gsm that was in status.
*Wi-Fi settings and detailed nmcli commands are also available on the Raspida page. Please refer to them as well.
“Added successfully.” is displayed, you are good to go.
Look at the status as before.
nmcli device status
DEVICE TYPE STATE CONNECTION
eth0 ethernet connected Wired connection 1
cdc-wdm0 gsm connecting ocn-net
wlan0 wifi disconnected --
p2p-dev-wlan0 wifi-p2p disconnected --
eth1 ethernet unavailable --
lo loopback unmanaged --
I see that cdc-wdm0, TYPE is now connecting with gsm, and the CONNECTION is now ocn-net, which I arbitrarily set to CONNECTION.
By rebooting from here, the 4G (LTE) communication module will get a global IP address and connect to the Internet.
I wanted to check only mobile communication, not via my home router, so I unplugged the LAN cable for wired connection 1 and disconnected Wi-Fi as well to try it.
You can see that only cdc-wdm0 is now connected.
nmcli device status
DEVICE TYPE STATE CONNECTION
cdc-wdm0 gsm connected ocn-net
wlan0 wifi disconnected --
p2p-dev-wlan0 wifi-p2p disconnected --
eth0 ethernet unavailable --
eth1 ethernet unavailable --
lo loopback unmanaged --
Confirmation of global IP address
Check the global IP address while in mobile communication.
You can check it with the curl command.
curl inet-ip.info
Ping command to test communication to the Internet
If you just want to test the communication, use the ping command to specify a URL or IP address.
If you turn off the LAN cable and Wi-Fi, only the 4G (LTE) module is already connected, so if there are no execution errors, you have confirmed mobile communication.
ping www.yahoo.co.jp
ping www.google.co.jp
Communication Modem Details
The following command will give you the details of the modem and the 4G (LTE) communication module that was used in this trial.
It is the mmcli (MMCLI) command, not the nmcli that was used earlier.
mmcli -m 0
(omission)
--------------------------------
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: 89% (recent)
(omission)
The Status item here also confirmed the connection (CONNECTED).
With the above, mobile communication is now available on the industrial Raspberry Pi.
*The current Raspberry Pi OS has been changed to NetworkManager; you do not need to switch to NetworkManager unless you are bullseye.
Greater flexibility in system operation
The 4G (LTE) communication module enables stand-alone mobile communication and eases the installation location in sending and receiving data.
It is especially difficult to connect to Wi-Fi or LAN cables outdoors.
In addition, the robust construction of the enclosure helps alleviate conditions in locations where temperature control is difficult.
The product we tried out would be a relatively small enclosure and could be handled as an addition to an existing system.
If you have given up on introducing IoT terminals because of the challenges of where to install them, support for mobile communications would be one factor you could consider.
Both communication speed and signal strength require only small amounts of data when limited to the transfer of acquired numerical data.
With the Raspberry Pi, a small computer, it is possible to process the data before sending it.
So there are products that meet the demand for Raspberry Pi, especially for industrial applications, as well as the realization of mobile communications such as 4G (LTE) communication.
In particular, the “PL-R4” we tested is integrated into the carry board, and a SIM card insertion slot is also provided. The integrated type, which does not require connection to another device, was easy to understand in terms of setting up the connection.
Article contributed by Raspida
Raspberry Pi information site that even non-engineers can enjoy using raspida.com a Raspberry Pi information site that even non-engineers can enjoy and handle. He also contributes technical blog articles to the PiLink site on the Raspberry Pi for industrial use.