Rickster
Published

IoT Cellular Connectivity on Raspberry Pi and Linux Devices

A quick guide to adding cellular connectivity to Raspberry Pi with Huawei MS2131 Dongle
  • Difficulty: Beginner
  • Type: tutorial
  • Views: 739
IoT Cellular Connectivity on Raspberry Pi and Linux Devices

Things used in this project

Hardware components

SORACOM Air Global IoT SIM SORACOM Air Global IoT SIM × 1

Software apps and online services

SORACOM Air IoT Connectivity Platform SORACOM Air IoT Connectivity Platform × 1

Story

When getting started with IoT, a lot of people begin with a look into Raspberry Pi or a Linux-capable device such as, for example, Orange Pi, BeagleBone, or Intel Edison.

Raspberry Pi using Cellular Dongles

After the initial prototyping phase, it can be very good to add an un-tethered connection to your Linux-capable device. However, configuring these devices to use Cellular connectivity can be challenging.

Secure IoT SIM cards such as the ones we have at Soracom (FRUKDEITUSJP) can be a great solution. Thanks to advancements in OpenSource software and the good collaborative work I had the chance to do with the teams at Enerbrain,resin.ioand Soracom, we now have good and straightforward solutions to make it all work nicely.Testing different Cellular Dongles with Soracom Air

A second type of Dongle, such as th Huawei HiLink, incorporates its own network functionality. This type of dongle may seem as though it should be easier to set up, but can present couple of new challenges:

  • Dongle configuration is manual and therefore susceptible to mistakes and difficult to scale for more than couple of devices
  • As these Dongles run small MCUs, they aren’t designed to run 24/7 and tend to require regular power reset
  • A lot of these do not have NAT functionality which means they do not allow you to connect back to your device
  • Today we’ll focus on setting up a “modem-mode” USB Dongle. Throughout our testing, the Huawei MS2131 Dongle (this is not an endorsement) has been the most reliable one we’ve experienced so far and it has thus become our current reference dongle. The steps below are demonstrated on MS2131 but will also work with other modem type of Dongles.

    These step-by-step instructions use a Raspberry Pi but will work on most Linux distributions and devices that support network-manager:

    1. If you haven’t done so already, download and install Raspbian OS, we recommend Jessie Lite version as it’s stable and well supported2. Log into your Raspberry Pi and install network-manager packagepi@raspberrypi:~ $ sudo apt-get update && sudo apt-get install network-manager 3. Once Network Manager has been installed, create the 3G Dongle connectionpi@raspberrypi:~ $ sudo nmcli con add type gsm ifname "*" con-name soracom apn soracom.io user sora password sora 4. Reboot the Pipi@raspberrypi:~ $ sudo reboot 5. Once the Pi has rebooted, plug in your USB Dongle and you should get a ppp0 interface. (This is your Cellular connection)pi@raspberrypi:~ $ ifconfig ppp0ppp0 Link encap:Point-to-Point Protocolinet addr:10.237.184.147 P-t-P:10.64.64.64 Mask:255.255.255.255UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1RX packets:7 errors:0 dropped:0 overruns:0 frame:0TX packets:9 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:3RX bytes:106 (106.0 B) TX bytes:171 (171.0 B)

    Your Pi is now connected to the cellular network and will automatically connect each time a Dongle is plugged in or Linux restarted. It will also automatically reconnect in case the connection drops for any reason (for example, if a device moves temporarily out of range of a mobile network).

    One thing to note is that by default, Cellular connection has lower priority than WiFi or Ethernet. This could potentially affect your ability to access your device remotely. To solve this we update the default route metric by creating a Network Manager script:

    6. Download and install Soracom ppp route metric scriptpi@raspberrypi:~ $ sudo curl -o /etc/NetworkManager/dispatcher.d/90.set_ppp_route_metric https://soracom-files.s3.amazonaws.com/handson/90.set_ppp_route_metric 7. Make sure it is executablepi@raspberrypi:~ $ sudo chmod +x /etc/NetworkManager/dispatcher.d/90.set_ppp_route_metric 8. This new script will run everytime you reconnect a Dongle or reboot your pi, with it, you’ll be able to connect to it via Ethernet or Wifi while at the same time use Cellular as your default connectivity. Run it manually or otherwise reboot to activate itpi@raspberrypi:~ $ sudo /etc/NetworkManager/dispatcher.d/90.set_ppp_route_metric ppp0 up Should you wish to connect a ResinOS based device, you can head over to the following blog poston resin.io blog.