Pi Day @ Aeris, Part 3: Set Up a Cellular Connection

Posted by on April 21, 2017 at 5:00 AM Drew Johnson  
Share This Post   

Set Up Cellular Connection

Authors: Drew Johnson and Yixiang Chen


OS for Raspberry Pi comes with usb_modeswitch, which enables most of the USB modems to work out-of-the-box with the Pi by plug-n-play.


Disable Wi-Fi

You can disable Wi-fi either from the GUI or from the command line. In this project, we will use the command line utility 'nmcli' to manage Wi-fi so we can script it. In order to do so, we first need to remove 'wlan0' from /etc/network/interfaces:

$ sudo vi /etc/network/interfaces

Then comment out 'wlan0" like the following:

# Comment out for the Pi Day

# allow-hotplug wlan0

# iface wlan0 inet manual

# wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

Next, add the "usb0" interface to the same file:

# Added for ZTE modem MF691auto usb0iface usb0 inet dhcp

Our cellular modem will use this new interface later to automatically acquire an IP address from the Aeris network.

Reboot the Pi after all is done.

Then disable Wi-fi using nmcli:

$ nmcli radio wifi off

Now we are ready to proceed to set up the cellular connection.

Activate Aeris SIM

Follow the SIM activation process from Aeris to complete the SIM activation. Then note down the ICCID of your SIM card. You will need this ICCID later in other steps in this tutorial.

When you are still in the Aeris portal, note down the APN assigned for your SIM. It is "neo.iot.net" for this project:


blog 3, 1.png

Finally, install the SIM card into the modem after your SIM is successfully activated in the Aeris portal.

Connect the USB Modem

Plug in the USB modem. Wait for the light indicator to turn blue. Then check if the USB device has been switched to the modem mode:

$ sudo lsusb

Bus 001 Device 005: ID 413c:2003 Dell Computer Corp. Keyboard

Bus 001 Device 004: ID 046d:c00e Logitech, Inc. M-BJ58/M-BJ69 Optical Wheel Mouse

Bus 001 Device 017: ID 19d2:1203 ZTE WCDMA Technologies MSM MF691 [T-Mobile webConnect Rocket 2.0]

Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter

Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.

Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Note the line containing "ID 19d2:1203 ZTE WCDMA Technologies MSM MF691" in the output. The number "1203" indicates that the USB is now in the modem mode. It is also confirmed by the modem model "MF691" in the output. If the output doesn't have a modem model but rather displays "USB mass storage", then the USB device has not been switched to the modem mode. In that case, unplug the modem and plug it back in again. This will usually fix the problem. If not, follow the troubleshooting guide here.

Once the USB modem is actually switched to the modem mode, we can find the device file connected to the modem using 'dmesg':

$ dmesg | grep tty

[25534.967721] cdc_acm 1-1.2:1.1: ttyACM10: USB ACM device

[25534.974510] cdc_acm 1-1.2:1.3: ttyACM11: USB ACM device

It is not unusual for the modem to be connected with 2 tty devices. Any one will work if you want to open an AT terminal to the modem. But we will use a Modem Manger utility called "mmcli" instead because it is much simpler to use than raw AT commands.

Connect to the Aeris Cellular Network

Among many cellular setup utilities, Modem Manager is one of those simpler ones that make the entire process a snap. First, let the Modem Manager auto detect the modem:

$ sudo mmcli -

Found 1 modems:       

/org/freedesktop/ModemManager1/Modem/5 [T-Mobile] MF691

This output shows that the Modem Manager has found the modem at interface "5". You will use that interface number in the next command to connect to the cellular network.

Locate the APN, e.g. "neo.iot.net", from the Aeris portal and use that APN to connect to the Aeris network:

$ sudo mmcli -m 5 --simple-connect="apn=neo.iot.net"

successfully connected the modem

Now you can check that the modem has acquired an IP from the Aeris network:

$ ifconfig 


Link encap:Ethernet  HWaddr 02:9e:70:78:07:9c         

inet addr:  Bcast:  Mask:         

inet6 addr: fe80::e828:46ce:a99d:13b2/64 Scope:Link         

UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1          RX packets:34 errors:0 dropped:0 overruns:0 frame:0         

TX packets:70 errors:0 dropped:0 overruns:0 carrier:0          collisions:0 txqueuelen:1000         

RX bytes:3698 (3.6 KiB)  TX bytes:11400 (11.1 KiB)

Note the IP address next to "inet addr:" in the output. It should match the IP address in the Aeris portal:

blog 3,  2.png

That's all for setting up the cellular connection!


Publishing Data to Cloud

Create a PubNub Account

Go to the PubNub home page to setup an account.

Once you own your login credential, create a new app for your project:

blog 3,  3.png

Note down the "Publish Key" and the "Subscribe Key". You will use them in the next step.


Bootstrap API Keys on the Pi

Go to Aeris AerPort. Find the SIM card using its ICCID in the portal, then use the "Send SMS" menu to send a SMS to the Pi.

blog 3,  4.png

The SMS text should be in the following format:

<device id>,<PubNub Publish Key>,<PubNub Subscribe Key>


This SMS text will be stored in the cellular modem connected to the Pi and later be retrieved by our data connector for publishing sensor data to PubNub.

For a production system, the SMS can be sent using the AerFrame API.

Streaming Sensor Data to PubNub

In a Pi terminal window, go to the directory under which you downloaded "securePubNub.js" file. Then, run the command like the following:

$ node securePubNub.js

publishing: [object Object]

Listening to channel events.

publish success:  { error: false, 

        operation: 'PNPublishOperation'

        statusCode: 200 } { timetoken: '14895339257055227' }

publish success:  { error: false, 

          operation: 'PNPublishOperation'

          statusCode: 200 } { timetoken: '14895339258473040' }


You can see the data sent from the Pi in PubNub's debug console. Go to the debug console, enter PiCpu in the channel name field. Alternatively, you can enter PiFi in the channel name field.

Next, enter the publish and subscribe key generated by the step above.

Finally, go back to your Pi and run the securePubNub.js on your terminal. Then you should see the message from the PiCpu or PiWi in the messages section:

blog 3,  5.png

 For more information, visit our self-serve IoT marketplace NEO.

Topics: IoT platform, IoT Developer, IoT connectivity