LTE for IoT


The other day I was trying to connect an RPM based IoT device to a 4G network using this USB dongle from a company called NCXX.

Although successful, the process was not that straight forward, so I decided to make a blog about it, in case anyone else goes through the same hardships.

Contents:

  1. Download the necessary RPMs
  2. Configure USB
  3. Startup modules
  4. Service daemon
  5. AT commands
  6. Dial-up
  7. Optional

1. Download the necessary RPMs

Since my device doesn't not have Internet connection yet, I had to download the necessary RPM packages locally, transfer it on the target machine and install it there.

The following RPMs are required:

  • usb_modeswitch
  • wvdial (for dial-up)
  • tcl
  • usbutils
  • libusb1-devel
  • atinout (for AT commands)
yum install --downloadonly --downloaddir=/path/to/Downloads/folder/ usb_modeswitch wvdial tcl usbutils libusb1-devel atinout

NOTE: some dependencies may be also downloaded.

Top ↑

2. Configure USB

Assuming the installation went well, now it's time to set up the UX302NC USB dongle.

Add to /etc/usb_modeswitch.conf the following contents:

DisableSwitching=0
DisableMBIMGlobal=0
EnableLogging=1

# special settings for NCXX device
DefaultVendor= 0x11f6
DefaultProduct= 0x1035
TargetVendor= 0x11f6
TargetProduct= 0x1034
MessageEndpoint= not set
MessageContent="55534243123456780000000080000606f50402527000000000000000000000"
NeedResponse=0
ResponseEndpoint= not set
Interface=0x00

Top ↑

3. Startup modules

Whenever our dervice (re)starts, we need to load the option kernel module automatically. For that we do:

echo option > /etc/modules-load.d/option.conf

Top ↑

4. Service daemon

The following two scripts need to be placed in /usr/local/bin with 755 permissions:

  • lte_device - this script is checking if the physical device is inserted or not, checks for signal and if the dongle is attached to the network
  • lte_service - this script is being used in the service daemon

Next step is to create the daemon service configuration file, /usr/lib/systemd/system/lte.service with the following contents:

[Unit]
Description=LTE connectivity

[Service]
Type=simple
ExecStart=/usr/local/bin/lte_service
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=always
RestartSec=55s

[Install]
WantedBy=multi-user.target

For the daemon changes to take effect and to automatically start on reboot, run the following three commands:

systemctl daemon-reload
systemctl start lte
systemctl enable lte

Top ↑

5. AT commands

Some AT commands are needed for this USB dongle.
By default, when inserted, the USB is a storage device, but we are not interested in that, so we will modify it to boot directly into modem mode.
This is where we use the AT commands and the atinout package that we downloaded.

echo 'AT!AUTOINS=0' | atinout - /dev/ttyUSB2 -

Now every time you plug the USB, it will go directly into modem mode.

Depending on your service provider, you are required to authenticate with either PAP and/or CHAP. Here is how to set the USB to use one or the other methods.
The format of the command is as follows:

AT$QCPDPP=<cid>,<auth_type>,<password>,<username>
  • <cid> it is the number of the profile you want to set
  • <auth_type> is:
    • 0 no authentication
    • 1 PAP authentication
    • 2 CHAP authentication
  • <password> can be anything, we will set this up during the Dial-up phase
  • <username> anything

So, here are some examples

For PAP you can do something like:

echo 'AT$QCPDPP=1,1,1,1' | atinout - /dev/ttyUSB2 -

For CHAP you can do something like:

echo 'AT$QCPDPP=1,2,1,1' | atinout - /dev/ttyUSB2 -

Top ↑

6. Dial-up

And the last step is to setup the dial-up which should bring up the ppp0 interface. We will use here wvdial package.
The /etc/wvdial.conf should look something like this:

[Dialer Defaults]
Init1 = ATZ
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
Modem Type = USB
ISDN = 0
Modem = /dev/ttyUSB1
Baud = 460800

[Dialer net]
Phone = *99#
Username = ""
Password = ""
Stupid Mode = 1
Init3 = AT+CGDCONT?

Remote Name = "*"

Replace Username, and Password with the credentials received from your ISP.

In case you know the APN name where you have to connect, you could replace Init3 with something like:

Init3 = AT+CGDCONT=1,"IP","APN.name.goes.here"

To bring up your new connection, all you have to do is run:

wvdial net

and check if your ppp0 interface receives an IP address.

For troubleshooting check the next chapter.

Top ↑

7. Optional

This is mostly for debugging purposes, in case the connection doesn't go through smoothly.

Modify the following two files to look like:

  • /etc/ppp/options
	name lte-for-iot
	/dev/ttyUSB1
	lock
	login
	usepeerdns

	debug dump
	logfd 6
  • /etc/ppp/peers/wvdial
	name lte-for-iot
	nobsdcomp
	nodeflate
	noipdefault
	modem /dev/ttyUSB1
	crtscts

	debug dump
	nodetach
	logfd 6

Now you can do a tail -f /var/log/messages to check the debug messages.

I would like to thank to the technical support of NCXX which were very helpful in making this happen.

Top ↑