Filter results by

Incorporating a Cellular Modem

This project provides an example of how to use a cellular modem module with ARTIK Linux boards. With it, you can:

  • Connect to the Internet
  • Send and receive texts
  • Make and receive voice and video calls (using additional A/V devices).

Here we will use the MultiTech Dragonfly USB-connected cellular system-on-module solution, available from the ARTIK Marketplace. This procedure may also be applicable to other USB cellular modem types.

Preparation

You must use the Advanced Developers approach to create your Ubuntu image with a modified Linux kernel. While doing this may take about an hour including compile time, it is pretty straightforward and not technically difficult.

  1. The software solution requires inclusion of the Point-to-Point Protocol (PPP) module in your Linux kernel. Rebuild your Linux kernel to include PPP and the USB GSM modem modules.
    » Use Kconfig to build in modules
    The procedure includes loading the new images to your ARTIK module either as a full image using a microSD card, or by module using scp.

  2. Update the ARTIK board Ubuntu packages as always, skipping the update of the image itself since you now use a custom one.

  3. Obtain and register a SIM card, and insert it in the cellular module slot. We used Twilio and T-Mobile SIMs in the examples below; replace the apn with the one for your SIM provider.

  4. Connect the cellular module to the ARTIK board with a standard-to-micro USB cable. For a MultiTech system, use the USB receptacle on the cellular module; leave the module detached from the optional development kit board.

  5. Open a terminal console to your ARTIK board and power up the board as always.

One-Time Setup

You'll need to install a package to manage modem power-up and configuration, one to establish a point-to-point communication path, and one to send serial commands to the modem. The result will be a wireless serial communications interface that acts much like an Ethernet connection.

Install Modem Manager and Policy Kit

Modem Manager installation is optional, but is convenient for checking status of modem operation. The Policy Kit is additional, needed only if you plan to use certain "bearer" authentication tasks performed by Modem Manager. You may be able to skip both of these packages for your final application.

  1. Install the Modem Manager software on the ARTIK board.
    apt install modemmanager
    systemctl enable ModemManager
  2. Install the Policy Kit package.
    apt install mate-polkit
  3. Reboot and confirm that Modem Manager is running and has detected the modem.
    reboot
    mmcli -L
    Found 1 modems:
            /org/freedesktop/ModemManager1/Modem/0 [Telit] LE910-NA1
  4. Note the modem number (shown as 0 in this example). You'll see a higher number if you unplug and reattach the modem, or if you have multiple modems.
  5. Check the modem status
    mmcli -m 0
    replacing 0 with your modem number. Click to see sample output.
    root@artik:~# mmcli -m 0
    /org/freedesktop/ModemManager1/Modem/0 (device id '9d78edab2849b884a3270e1c3b263617ef8059b5')
      -------------------------
      Hardware |   manufacturer: 'Telit'
               |          model: 'LE910-NA1'
               |       revision: '20.00.522'
               |      supported: 'gsm-umts, lte'
               |        current: 'gsm-umts, lte'
               |   equipment id: '356961072263885'
      -------------------------
      System   |         device: '/sys/devices/platform/c0000000.soc/c0030000.ehci/usb2/2-1'
               |        drivers: 'cdc_acm, cdc_ncm'
               |         plugin: 'Telit'
               |   primary port: 'ttyACM0'
               |          ports: 'ttyACM3 (at), ttyACM4 (unknown), ttyACM5 (unknown), ttyACM0 (at), ttyACM1 (unknown), ttyACM2 (unknown)'
      -------------------------
      Numbers  |           own : 'unknown'
      -------------------------
      Status   |           lock: 'none'
               | unlock retries: 'sim-pin (3), sim-pin2 (10), sim-puk (10), sim-puk2 (10)'
               |          state: 'disabled'
               |    power state: 'on'
               |    access tech: 'unknown'
               | signal quality: '0' (cached)
      -------------------------
      Modes    |      supported: 'allowed: 3g; preferred: none
               |                  allowed: 4g; preferred: none
               |                  allowed: 3g, 4g; preferred: none'
               |        current: 'allowed: 3g, 4g; preferred: none'
      -------------------------
      Bands    |      supported: 'u1900, u850, eutran-ii, eutran-iv, eutran-v, eutran-xii, eutran-xiii, eutran-xvii'
               |        current: 'u1900, eutran-ii'
      -------------------------
      IP       |      supported: 'ipv4, ipv6, ipv4v6'
      -------------------------
      3GPP     |           imei: '356961072263885'
               |  enabled locks: 'none'
               |    operator id: 'unknown'
               |  operator name: 'unknown'
               |   subscription: 'unknown'
               |   registration: 'unknown'
      -------------------------
      SIM      |           path: '/org/freedesktop/ModemManager1/SIM/0'
    
      -------------------------
      Bearers  |          paths: 'none'
    
  6. Make a note of the USB primary port where your modem was found (/dev/ttyACM0 in our example).

You'll need both the modem number and the primary port name in the steps that follow.

It takes 20-30 seconds after boot before mmcli -L succeeds.

Install PPP

The Point-to-Point Protocol (PPP) program will be called to set up an IP connection across the cellular modem.

  1. Install the PPP package.

    apt install ppp

  2. Create the ppp configuration file for the gprs service you are setting up.

    vi /etc/ppp/peers/gprs

  3. Paste in the contents below, then replace the apn (wireless.twilio.com in our example here) and USB port (ttyACM0) with the correct ones for your application.

/etc/ppp/peers/gprs

1
2
3
4
5
6
7
8
connect "/usr/sbin/chat -v -f /etc/chatscripts/gprs -T wireless.twilio.com"
/dev/ttyACM0
noipdefault
defaultroute
replacedefaultroute
noauth
persist
usepeerdns

Associate a Chat script

PPP calls Chat and a generic setup script to initialize the modem.

  1. Open the Chat script.

    vi /etc/chatscripts/gprs

  2. The file should already exist; paste in the default contents if not. You can add a SIM card pin here if you use one.

# You can use this script unmodified to connect to cellular networks.
# The APN is specified in the peers file as the argument of the -T command
# line option of chat(8).

# For details about the AT commands involved please consult the relevant
# standard: 3GPP TS 27.007 - AT command set for User Equipment (UE).
# (http://www.3gpp.org/ftp/Specs/html-info/27007.htm)

ABORT           BUSY
ABORT           VOICE
ABORT           "NO CARRIER"
ABORT           "NO DIALTONE"
ABORT           "NO DIAL TONE"
ABORT           "NO ANSWER"
ABORT           "DELAYED"
ABORT           "ERROR"

# cease if the modem is not attached to the network yet
ABORT           "+CGATT: 0"

""              AT
TIMEOUT         12
OK              ATH
OK              ATE1

# +CPIN provides the SIM card PIN
#OK             "AT+CPIN=1234"

# +CFUN may allow to configure the handset to limit operations to
# GPRS/EDGE/UMTS/etc to save power, but the arguments are not standard
# except for 1 which means "full functionality".
#OK             AT+CFUN=1

OK              AT+CGDCONT=1,"IP","\T","",0,0
OK              ATD*99#
TIMEOUT         22
CONNECT         ""

Install WvDial

WvDial sends the commands to request IP addresses.

  1. Create the wvdial configuration file for the service you will be setting up.

    vi /etc/wvdial.conf

  2. Paste in the wvdial.conf contents below, then replace the USB port (ttyACM0) with the correct one for your application.

  3. Install the WvDial package. Make sure you have the configuration file in place before doing the install.

    apt install wvdial

/etc/wvdial.conf

1
2
3
4
5
6
7
8
9
10
11
[Dialer Defaults]  
Modem = /dev/ttyACM0  
Baud = 3600000  
Init1 = ATZ  
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0  
Phone = *99#  
Username = ppp  
Password = ppp  
Dial Command = ATDT  
Stupid Mode = 1  
Auto DNS = 1

Operating Procedure

Perform these steps on each boot, either manually or from a script.

  1. Stop Connection Manager to prevent it from stealing your connections.
      systemctl stop connman
  2. Loop on this command until it successfully finds the attached modem.
      mmcli -L
  3. Determine the port number of your modem on each boot and hot plug, and modify the USB port in the scripts to match.
      mmcli -m 0
    You can check details of your modem setup at any time. Click to see a sample.
    root@artik:~# mmcli -m 0
    /org/freedesktop/ModemManager1/Modem/0 (device id '9d78edab2849b884a3270e1c3b263617ef8059b5')
      -------------------------
      Hardware |   manufacturer: 'Telit'
               |          model: 'LE910-NA1'
               |       revision: '20.00.522'
               |      supported: 'gsm-umts, lte'
               |        current: 'gsm-umts, lte'
               |   equipment id: '356961072263885'
      -------------------------
      System   |         device: '/sys/devices/platform/c0000000.soc/c0030000.ehci/usb2/2-1'
               |        drivers: 'cdc_acm, cdc_ncm'
               |         plugin: 'Telit'
               |   primary port: 'ttyACM0'
               |          ports: 'ttyACM3 (at), ttyACM4 (unknown), ttyACM5 (unknown), ttyACM0 (at), ttyACM1 (unknown), ttyACM2 (unknown)'
      -------------------------
      Numbers  |           own : 'unknown'
      -------------------------
      Status   |           lock: 'none'
               | unlock retries: 'sim-pin (3), sim-pin2 (10), sim-puk (10), sim-puk2 (10)'
               |          state: 'connected'
               |    power state: 'on'
               |    access tech: 'unknown'
               | signal quality: '85' (recent)
      -------------------------
      Modes    |      supported: 'allowed: 3g; preferred: none
               |                  allowed: 4g; preferred: none
               |                  allowed: 3g, 4g; preferred: none'
               |        current: 'allowed: 3g, 4g; preferred: none'
      -------------------------
      Bands    |      supported: 'u1900, u850, eutran-ii, eutran-iv, eutran-v, eutran-xii, eutran-xiii, eutran-xvii'
               |        current: 'u1900, eutran-ii'
      -------------------------
      IP       |      supported: 'ipv4, ipv6, ipv4v6'
      -------------------------
      3GPP     |           imei: '356961072263885'
               |  enabled locks: 'none'
               |    operator id: '310260'
               |  operator name: 'Twilio'
               |   subscription: 'unknown'
               |   registration: 'home'
      -------------------------
      SIM      |           path: '/org/freedesktop/ModemManager1/SIM/0'
    
      -------------------------
      Bearers  |          paths: '/org/freedesktop/ModemManager1/Bearer/0'
    
  4. Start the PPP daemon, optionally requesting debug message logging.
      pppd debug call gprs
  5. Wait. The chat script must run completely. The next step may not execute on the first try if you run it while the chat script is still accessing the modem port.
  6. Run wvdial in the background to send the modem command that gets an IP address (the Init2 line in the wvdial.conf file).
      wvdial &

After you receive an IP address, run
  ifconfig
and you'll see that ppp0 now shows up in the list with that IP address. Try pinging a known-accessible site to verify communication.

Troubleshooting

You can use the 'create bearer' command to see if your provider information is accepted.

mmcli -m 0 --create-bearer='apn=wireless.twilio.com'

You can also enable the modem

mmcli -m 0 -e

and create a test connection

mmcli -b 0 -c

These functions will conflict with PPP and may result in dropped connections, so use them only for troubleshooting.

Click to see sample output of the Bearer status command.

[root@artik ~]# mmcli -b 0
Bearer '/org/freedesktop/ModemManager1/Bearer/0'
  -------------------------
  Status             |   connected: 'no'
                     |   suspended: 'no'
                     |   interface: 'unknown'
                     |  IP timeout: '20'
  -------------------------
  Properties         |         apn: 'wireless.twilio.com'
                     |     roaming: 'allowed'
                     |     IP type: 'none'
                     |        user: 'none'
                     |    password: 'none'
                     |      number: 'none'
                     | Rm protocol: 'unknown'
  -------------------------
  IPv4 configuration |   method: 'unknown'
  -------------------------
  IPv6 configuration |   method: 'unknown'
  -------------------------
  Stats              |          Duration: '0'
                     |    Bytes received: 'N/A'
                     | Bytes transmitted: 'N/A'

Click to see sample output of the command to acquire an IP address followed by Ctrl-C to disconnect. You could instead use Ctrl-Z to keep it running for testing of the connection.



Ubuntu 16.04.4 LTS artik ttySAC3

artik login: root
Password:
Last login: Fri Mar 30 19:39:03 UTC 2018 on ttySAC3
Welcome to Ubuntu 16.04.4 LTS (GNU/Linux 4.4.71-UNRELEASED-00006-g2da254d-dirty aarch64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage
# pppd debug call gprs
# wvdial
--> WvDial: Internet dialer version 1.61
--> Initializing modem.
--> Sending: ATZ
ATZ
OK
--> Sending: ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
OK
--> Modem initialized.
--> Sending: ATDT*99#
--> Waiting for carrier.
ATDT*99#
CONNECT
--> Carrier detected.  Starting PPP immediately.
--> Starting pppd at Fri Mar 30 19:45:23 2018
--> Pid of pppd: 2543
--> pppd: [7f]
--> Using interface ppp0
--> pppd: [7f]
--> pppd: [7f]
--> pppd: [7f]
--> local  IP address 25.38.26.29
--> pppd: [7f]
--> remote IP address 25.38.26.29
--> pppd: [7f]
--> primary   DNS address 10.177.0.34
--> pppd: [7f]
--> secondary DNS address 10.177.0.210
--> pppd: [7f]
^CCaught signal 2:  Attempting to exit gracefully...
--> Terminating on signal 15
--> pppd: [7f]
--> Connect time 1.9 minutes.
--> pppd: [7f]
--> pppd: [7f]
--> pppd: [7f]
--> Disconnecting at Fri Mar 30 19:47:18 2018

Last updated on: