Evaluating NB-IoT and LTE-M with Raspberry Pi


LPWAN (Low Power Wide Area Network) technologies are key enablers for IoT applications and Cellular IoT (“CIoT)” is considered one of the most attractive approaches. CIoT works in the licensed frequency spectrum and current main streams are based on LTE technology and tailored to the needs of IoT. In particular, NB-IoT ("Narrowband – IoT") and LTE-M ("Long Term Evolution for Machines") are good choices for mission-critical monitoring or object tracking applications which are infrequently transmitting small data packages and also can be used for wearable devices with an extremely low power budget. In this post, we will explain an approach to evaluate an NB-IoT or LTE-M network with a Raspberry Pi - Installation and User Interface.

Cellular LPWAN technologies inspire the industry to create new IoT business cases and new IoT products. Related 3GPP standardization work aims at inexpensive low-power devices, but also offers enhanced network coverage for difficult-to-reach IoT devices, e.g. in rural areas or under ground level or for high-density deployment scenarios in urban areas.

NB-IoT key objectives

One of the most compelling reasons to work with LTE-M and NB-IoT networks is their support for battery-powered IoT devices. In fact, LTE-M and NB-IoT offer several power-saving mechanisms to keep data transmission periods as short as possible and to allow the IoT device to remain in sleep mode most of the time. PSM (“Power Save Mode”) and eDRX (“extended Discontinued Reception”) are two main power savers, but there are other LTE-M and NB-IoT network features which help IoT devices to consume less energy or get better coverage vs. traditional LTE. One of them is called coverage enhancement (CE) level which is assigned to an IoT device by a network base station during initial connection process. For cellular IoT device power consumption, uplink data transfer is most critical because available transmission power is limited to 20 or 23 dBm (i.e. 100mW or 200mW) as specified by 3GPP standard. Instead of increasing transmission power, both LTE-M and NB-IoT are using a sophisticated approach to extend network coverage by using repetitions and error detection for data transmission. This means that an increased CE level will allow an LTE-M or NB-IoT device to connect even if the signal strength is very low, but data transmission will take longer and will consume more battery capacity.

Consequently, achievable cellular IoT performance significantly depends on individual device location and network selection as well as an optimized configuration of the connected network cell. IoT project engineers should have a good knowledge of local network candidates, i.e. how they have been implemented and configured. This kind of information should be available from network operators, but additional technical investigations and tests might be useful.

As a general benefit particularly for cellular IoT projects, CIoT network providers like EMnify offer access to multiple networks (see EMnify Network Coverage) and sometimes even to several different cells at each location. These options allow each CIoT device to connect to the most appropriate cell.

Setting up a CIoT user test system

For those of you who would like to get familiar with LTE-M or NB-IoT networks in detail, to check out a local network cell or to perform some pre-project evaluations, this article introduces a versatile CIoT evaluation system based on popular Raspberry Pi (short: “RasPi”) to you. RasPi works out-of-the box with a standard HDMI display, USB keyboard and mouse. Onboard Linux OS (“Rasbian”) and integrated WiFi allow to setup a fully operational single-board host for embedded applications. We used a RasPi model 4 and added an LTE-M/NB-IoT network interface (“modem”) extension board called “Cellular IoT HAT” by sixfab. It is based on a Quectel BG96 modem module.

The sixfab board is easy to install and comes with a low-level library for hardware control and some sample Python application programs.

harwareSo, here we go! Insert your EMnify SIM card and attach the sixfab board on top of the 40-pin extension connector of the RasPi. Then, install antenna and short USB connection cable between both boards. After power up, you will first have to enable the RasPi serial port (i.e. associated GPIO pins of the extension connector) which is used for interaction with the modem. For this purpose, use the raspi-config utility and reboot the system. Now, you will have to retrieve some software from sixfab github repository and install it:

git clone https://github.com/sixfab/Sixfab_RPi_CellularIoT_App_Shield.git
cd Sixfab_RPi_CellularIoT_App_Shield
sudo python3 setup.py install

**Note: After boot and by default, the Quectel BG96 module is in sleep mode and not reachable. Wake-up is done by pressing the PWRKEY button for two seconds, which is activating the PWRKEY pin of the BG96 (via dedicated GPIO pin of the RasPi extension connector).

Now, our CIoT modem is operational, and Rasbian command lsusb will return “Quectel Wireless Solutions Co., Ltd. BG96 CAT-M1/NB-IoT modem” to confirm that the sixfab board has been identified properly.

AT Command Interface

For modem control a serial UART port is standard as well as a programming interface including command/response syntax and a basic instruction set. This AT command interface is supported by every modem. Standard AT commands are used to configure modem and device functions. But today’s complex cellular network interface modules have implemented a variety of additional features and functions. Consequently, manufacturers have added corresponding (proprietary) AT commands e.g. for network control, handling of communication sessions, security parameters, SIM handling, etc.

For most CIoT application developers, AT modem commands are the only way to control network selection and to adjust configurable parameters of a connected network cell. For LTE-M and NB-IoT networks, this task is particularly important because IoT device performance (e.g. power consumption, data rate, latency) is significantly impacted by local network implementation. While all network interface modules support the standard AT Commands Set, manufacturers like Telit, u-blox or Nordic Semiconductors offer additional vendor specific AT command sets. These commands can be used by IoT application developers as a powerful toolbox for evaluating CIoT implementations.

In our case, Quectel’s “BG96 AT Commands Manual” will be the starting point for own network tests and evaluations. You can download it from www.quectel.com or mentioned sixfab github repository. In general, an AT command can be sent to a modem using a serial port communications program, e.g. Minicom which is available for Linux-based RasPi boards and allows to submit AT commands one- by-one at RasPi OS command-line interface (“CLI”), see recent EMnify post AT Commands Cheat Sheet for Cellular IoT Communication.

On top of this approach, our proposal is based on a versatile Python template. Python is a simple interpreted programming language which comes pre-installed with Rasbian. As a start, our code template allows you to create simple test programs based on a sequence of selected AT commands. These commands will be submitted to the BG96 modem, results will be displayed on RasPi screen. For this, no Python programming will be required, just a basic understanding of RasPi user interface and tools. Then, you can extend your evaluation activities, re-use your initial test code and create and test complex routines you can incorporate into the target IoT device software later. For example, you can elaborate an installation module to be executed during CIoT device deployment in order to prepare a suitable data channel for each device. Such (Python) module would have to identify available networks, verify implemented features, select the most appropriate network, set parameters as needed and perform a test connection. CIoT connection diagram

Template for own LTE-M and  NB-IoT Trials

Key software component is library cellulariot.py provided by sixfab. It uses standard RasPi Python modules serial and RPi.GPIO which manage RasPi hardware interfaces, i.e. UART serial port and GPIOs. Module sleep() delays program execution by specified value (in seconds). Library functions setupGPIO(), enable(), disable() and powerup() are used to control some RasPi GPIO pins which are used to control PWRKEY pin and to enable the BG96 module.

**Note: For in-depth information about low-level programming and RasPi GPIO hardware interface you can download cellulariot.py source code as well as the schematics of Cellular IoT HAT board from here: https://github.com/sixfab/Sixfab_RPi_CellularIoT_HAT

Key library function is sendATComm()which is used to submit an AT command to the BG96 module. The following sample program BG96sample.py can be used for initial verification of a successful installation of the sixfab modem board. At the same time it demonstrates how to use sendATComm() function call for any BG96 AT command:

#name: BG96sample.py
from time import sleep
from cellulariot import cellulariot
node = cellulariot.CellularIoT()

#reset and enable BG96 module
node.disable() #GPIO pin BG96_ENABLE
sleep(1) #wait 1 sec
node.enable() #GPIO pin BG96_ENABLE
sleep(1) #wait 1 sec
node.powerUp() #GPIO pin BG96_PWRKEY

#submit 1st sample AT command
#AT+CGMR ”Request TA Revision Identification of Software Release”
#i.e. Modem Firmware Revision
#will return, e.g. BG96MAR02A07M1G
#submit 2nd sample AT command
# AT+CIMI ”Request International Mobile Subscriber Identity (IMSI) ”
#retrieved from EMnify SIM card
#will return, e.g. 295050901196243

#submit 3rd sample AT command
#+QICSGP ”Configure Parameters of a TCP/IP Context”
#in this example, specified APN is “em”, username is “kersten”, no password
#original BG96 command: AT+QICSGP=1,1,”em","kersten","",1

*Note: For use with Python function sendATComm(), each semicolon included in original command (") must be marked as no-Python-code and replaced by a (\"), otherwise the Python interpreter would get confused.

Execution of a Python program at Rasbian command-line (CLI) level is done using

sudo python3 BG96sample.py

As soon as BG96sample.py execution returns expected results, you can use it as a template to submit any BG96 command for extended evaluation and CIoT tests according to your needs. Use built-in CLI editor nano or Rasbian GUI editor to modify it for this purpose.

In part 2 of this post, we will demonstrate real-world CIoT network evaluation with described RasPi test system and show

  • how to scan locally available CIoT networks (i.e. NB-IoT or LTE-M)
  • how connect to a network and check relevant parameters, e.g. signal quality, applied coverage extension (CE) level
  • how to verify and configure LTE-M or NB-IoT specific network parameters and timers (e.g. for eDRX or PSM features)
  • ping a partner IP address, setup a sample transport-layer (UDP or TCP/IP) communication session and transmit a data package

Stay tuned !

Related Posts