IoT Cellular Connectivity on Raspberry Pi and Linux Devices
Things used in this project
|SORACOM Air Global IoT SIM||× 1|
Software apps and online services
|SORACOM Air IoT Connectivity Platform||× 1|
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.
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.
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:
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.