14  NB-IoT Labs and Implementation

In 60 Seconds

This hands-on chapter covers configuring NB-IoT modules (SIM7020, BC66) using AT commands to establish cellular connectivity, configure PSM and eDRX power modes, transmit sensor data via UDP/CoAP, and debug connectivity issues using diagnostic commands for signal strength and network status.

Key Concepts
  • SARA-N211: u-blox NB-IoT module (standalone NB-IoT only); UART AT command interface; used in lab exercises for basic NB-IoT connectivity
  • Quectel BC660K-GL: Global NB-IoT module with 3GPP Release 14 features; ultra-low power (1.6 µA PSM); commonly used in production NB-IoT designs
  • nRF9161 / nRF9160: Nordic Semiconductor LTE-M/NB-IoT SiP (System-in-Package); integrates ARM Cortex-M33 application processor + modem; eliminates need for external MCU
  • SARA-R412M: u-blox multi-technology module (LTE-M + NB-IoT + 2G fallback); used for global deployments requiring technology fallback
  • Lab Bench Setup: AT development requires: terminal emulator (Tera Term, minicom), USB-UART adapter (CP2102, CH340), 3.3V power supply (NB-IoT modules are NOT 5V tolerant)
  • CoAP Client Library: libcoap (C), aiocoap (Python async), microcoap (embedded C); used for lab CoAP-over-NB-IoT data transmission exercises
  • LwM2M Client: Eclipse Wakaama (C), Anjay (C), Eclipse Leshan (Java server); standard device management stack for production NB-IoT deployments
  • Network Simulator: Software tools like NS-3 with NB-IoT module, or hardware RF attenuators to simulate different coverage conditions in lab environments

14.1 Learning Objectives

By the end of this chapter, you will be able to:

  • Configure NB-IoT modules: Issue AT command sequences to initialize SIM7020, BC66, and other modules for network operation
  • Establish network connectivity: Execute the attach procedure and diagnose registration failures using AT+CEREG and AT+COPS responses
  • Implement power modes: Set T3412 and T3324 timer values via AT+CPSMS to optimize PSM and eDRX for target battery life
  • Transmit sensor data: Construct and send UDP/CoAP payloads to cloud endpoints from NB-IoT devices
  • Debug connectivity issues: Interpret AT+CSQ signal strength, AT+NUESTATS radio statistics, and AT+CGDCONT APN diagnostics
  • Evaluate module selection: Compare NB-IoT modules by band support, power profile, and total cost of ownership for a given deployment scenario

14.2 Prerequisites

Before diving into this chapter, you should be familiar with:

  • NB-IoT Fundamentals: Understanding NB-IoT technology basics, deployment modes, and architectural components is essential before implementing practical solutions
  • NB-IoT Power and Channel: Knowledge of PSM, eDRX, and channel access mechanisms is required to properly configure power-saving modes in lab exercises
  • Cellular IoT Fundamentals: Familiarity with cellular network concepts helps you understand SIM card activation, network registration, and carrier requirements
  • Networking Basics: Basic networking knowledge including IP addressing and data transmission concepts is needed for cloud integration exercises

Deep Dives:

Comparisons:

Application Protocols:

Related Labs:

Design:

“Time to connect to a real cellular network!” said Max the Microcontroller, wiring up a SIM7020 module. “Well, almost real – we are using a simulator. But the AT commands and procedures are identical to what you would use with actual hardware.”

Sammy the Sensor asked, “What is the first thing we do?” Max walked through the checklist. “Step one: send AT and wait for OK – that confirms the modem is alive. Step two: AT+CPIN? to check the SIM card. Step three: AT+CSQ for signal strength. Step four: AT+CEREG? to see if we are registered on the network. Only after all four pass do we try sending data.”

“Configuring PSM is the most impactful part,” said Bella the Battery excitedly. “With AT+CPSMS=1, you tell the network you want Power Saving Mode. Then you set the TAU timer – that is how long I can sleep – and the Active Timer – how long to stay awake after transmitting. Set TAU to 1 hour and Active to 10 seconds, and I draw only 5 microamps for 99.7 percent of the time!”

Lila the LED offered debugging advice. “If registration fails, check the APN with AT+CGDCONT. If signal is weak, try AT+NCONFIG to enable coverage enhancement with extra repetitions. And always monitor AT+NUESTATS for detailed radio statistics – it tells you things like the number of retransmissions, which reveals hidden connectivity problems.”

Learning:

14.3 🌱 Getting Started (For Beginners)

If you’re ready to get hands-on with NB-IoT development, this section will guide you through practical implementation using common development boards and modules.

14.3.1 What Will You Learn?

Practical skills:

  • Configure NB-IoT modules using AT commands
  • Connect to carrier networks (Vodafone, T-Mobile, AT&T, etc.)
  • Send/receive data to cloud platforms
  • Implement PSM and eDRX power modes
  • Debug connectivity issues

Analogy: Think of this chapter as moving from “reading about driving” (previous chapters) to “getting behind the wheel” – you’ll write real code and see data flowing to the cloud.

14.3.2 Hardware You’ll Need

Option 1: Low-cost starter (< $30)

  • ESP32 DevKit ($8-12)
  • SIM7020E NB-IoT module ($15-20)
  • Breadboard + jumper wires
  • USB cable
  • NB-IoT SIM card (from carrier)

Option 2: All-in-one board ($40-60)

  • LilyGO T-SIM7000G (ESP32 + SIM7000G NB-IoT + GPS)
  • USB cable
  • NB-IoT SIM card

Recommended for beginners: LilyGO T-SIM7000G – everything integrated, no wiring needed.

14.3.3 Getting an NB-IoT SIM Card

Carrier options (United States):

  • T-Mobile: IoT SIM cards (1 MB/month free tier available)
  • AT&T: IoT Data plans (starting $2/month)
  • Hologram.io: Global IoT SIM (pay-as-you-go, works in 200+ countries)

Carrier options (Europe):

  • Vodafone: IoT SIM cards (various plans)
  • Deutsche Telekom: NB-IoT connectivity
  • 1NCE: €10 for 10 years (500 MB total, popular for testing!)

Important: Make sure your SIM card supports NB-IoT specifically (not just LTE-M or regular LTE).

14.3.4 Quick Start: Send Your First NB-IoT Message (30 minutes)

Step 1: Connect hardware

ESP32 → SIM7020E Module
TX (GPIO17) → RX
RX (GPIO16) → TX
3.3V → VCC
GND → GND

Step 2: Test AT commands (Arduino Serial Monitor)

AT              → OK (basic connectivity test)
AT+CPIN?        → +CPIN: READY (SIM card detected)
AT+CGATT=1      → OK (attach to network - may take 30-60 seconds)
AT+CGATT?       → +CGATT: 1 (attached successfully!)

Step 3: Send data to cloud (UDP example)

// Simple sketch to send "Hello NB-IoT!" every 60 seconds
#include <HardwareSerial.h>

HardwareSerial nb(1);  // Use UART1

void setup() {
  Serial.begin(115200);
  nb.begin(9600, SERIAL_8N1, 16, 17);  // RX=16, TX=17

  delay(3000);
  sendAT("AT");
  sendAT("AT+CGATT=1");  // Attach to network
  delay(30000);  // Wait for attachment
}

void loop() {
  // Send UDP packet to test server
  sendAT("AT+CSOC=1,2,1");  // Create UDP socket
  sendAT("AT+CSOSEND=0,12,\"Hello NB-IoT!\"");  // Send data

  Serial.println("Data sent!");
  delay(60000);  // Wait 60 seconds
}

void sendAT(String cmd) {
  nb.println(cmd);
  delay(1000);
  while (nb.available()) {
    Serial.write(nb.read());
  }
}

Expected result: After ~60 seconds (network attachment), you’ll see messages sent every minute. Battery life in this basic example: ~2-3 days (no PSM enabled yet).

Objective: Simulate NB-IoT Power Saving Mode (PSM) to understand how TAU and Active timers affect battery life.

Paste this code into the Wokwi editor. The simulation compares four PSM configurations and calculates battery life for each:

Configuration TAU Timer Active Timer TX/Day Result
Aggressive PSM 60 min 10 s 24 Years of battery
Moderate PSM 30 min 20 s 48 Months-years
Conservative 10 min 30 s 144 Weeks-months
No PSM 24 Days only
#include <Arduino.h>

// NB-IoT PSM simulation parameters
float activeCurrent_mA = 120.0;    // During TX/RX
float idleCurrent_mA = 6.0;       // Radio on, no traffic
float psmCurrent_uA = 3.0;        // PSM sleep (microamps)
float batteryCapacity_mAh = 2400;  // AA lithium battery

struct PSMConfig {
  const char* name;
  int tauMinutes;       // TAU timer (periodic TAU update)
  int activeSeconds;    // Active timer
  int txPerDay;         // Transmissions per day
  float txDuration_s;   // Time per transmission
};

PSMConfig configs[] = {
  {"Aggressive PSM",  60,  10, 24, 2.0},
  {"Moderate PSM",    30,  20, 48, 2.0},
  {"Conservative",    10,  30, 144, 2.0},
  {"No PSM",           0,   0, 24, 2.0}
};

void setup() {
  Serial.begin(115200);
  for (int c = 0; c < 4; c++) {
    PSMConfig& cfg = configs[c];
    float txH = (cfg.txPerDay * cfg.txDuration_s) / 3600.0;
    float txE = txH * activeCurrent_mA;
    float daily;
    if (cfg.tauMinutes > 0) {
      float actH = (cfg.txPerDay * cfg.activeSeconds) / 3600.0;
      float slpH = 24.0 - txH - actH;
      daily = txE + actH * idleCurrent_mA + slpH * (psmCurrent_uA / 1000.0);
    } else {
      daily = txE + (24.0 - txH) * idleCurrent_mA;
    }
    Serial.printf("%s: %.4f mAh/day -> %.0f days (%.1f yr)\n",
      cfg.name, daily, batteryCapacity_mAh / daily,
      batteryCapacity_mAh / daily / 365.25);
  }
}

void loop() { delay(30000); }

What to Observe:

  1. PSM dramatically extends battery life from days (no PSM) to years (aggressive PSM)
  2. The TAU timer controls how long the device sleeps between network check-ins
  3. Active timer determines how long the radio stays on after each transmission
  4. The energy breakdown shows that sleep current (3 uA) dominates in PSM mode

14.3.5 Common Beginner Mistakes

1. “AT commands not responding”

  • ✅ Check baud rate (usually 9600 or 115200)
  • ✅ Verify TX/RX not swapped
  • ✅ Ensure 3.3V power (NOT 5V - will damage module!)
  • ✅ Add delay after power-on (3-5 seconds for module boot)

2. “Can’t attach to network” (AT+CGATT? returns 0)

  • ✅ SIM card inserted correctly (chip facing down usually)
  • ✅ SIM activated with carrier (check online portal)
  • ✅ NB-IoT coverage exists in your area (check carrier coverage map)
  • ✅ Wait longer (first attach can take 2-3 minutes in poor coverage)

3. “Battery drains in hours, not years!”

  • ✅ You haven’t enabled PSM mode yet (radio stays on)
  • ✅ Solution: Configure AT+CPSMS=1 (see labs below)

14.4 Videos

Cellular IoT Fundamentals
Cellular IoT Fundamentals
Layering concepts and networking behavior relevant to NB‑IoT/LTE‑M.
Diagram showing Cellular IoT optimization features including control plane optimization, user plane optimization, power saving modes, and extended coverage enhancements for NB-IoT
Figure 14.1: Cellular IoT (CIoT) optimization features
Illustration of NB-IoT channel access mechanisms showing single-tone and multi-tone transmission modes, NPRACH random access procedure, and resource allocation strategies
Figure 14.2: NB-IoT channel access mechanisms

Key drivers for NB-IoT:

  • Existing 2G/3G networks being sunset
  • Need for low-cost, low-power IoT connectivity
  • Leverage existing cellular infrastructure
  • Provide carrier-grade reliability
  • Support massive device deployments

14.4.1 NB-IoT Characteristics

NB-IoT key characteristics diagram showing 180 kHz bandwidth, 250 kbps peak data rate, 164 dB maximum coupling loss, PSM and eDRX power saving modes, three deployment modes (in-band, guard-band, standalone), and target applications including smart metering, asset tracking, smart city, agriculture, and industrial IoT.
Figure 14.3: NB-IoT key characteristics, features, and target applications

NB-IoT coverage enhancement modes diagram showing three levels: CE Level 0 (normal coverage, no repetitions, RSRP above -110 dBm), CE Level 1 (extended coverage, up to 32 repetitions, RSRP -110 to -130 dBm), and CE Level 2 (extreme coverage, up to 2048 repetitions, RSRP below -130 dBm), with trade-offs between coverage depth and transmission time.

NB-IoT key characteristics diagram

Target applications:

  • Smart metering (electricity, water, gas)
  • Smart cities (lighting, parking, waste)
  • Asset tracking and logistics
  • Agricultural monitoring
  • Industrial IoT
  • eHealth devices

14.5 Knowledge Check

Test your understanding of these networking concepts.

14.6 Hands-On Exercise: NB-IoT Power Budget Analysis

⏱️ ~25 min | ⭐⭐⭐ Advanced | 📋 P09.C15.U01

14.6.1 Exercise Objective

Calculate the battery life for an NB-IoT smart meter application.

14.6.2 Scenario

Smart electricity meter with the following requirements: - Reporting frequency: 4 readings per day (every 6 hours) - Payload size: 100 bytes (meter reading, power quality, diagnostics) - Power configuration: PSM enabled, T3412 = 6 hours - Battery: 3.6V, 5000 mAh (18 Wh) - Coverage: Normal (no extended repetitions needed)

14.6.3 Task 1: Current Consumption Profile

Typical NB-IoT module current consumption:

State Current Duration per Cycle
PSM (deep sleep) 5 µA 6 hours - (active time)
Wake-up 50 mA 3 seconds
Network attach 200 mA 5 seconds
Data transmission 220 mA 10 seconds (100 bytes)
RRC Idle (after TX) 15 mA 20 seconds (T3324)

For the smart meter scenario with 4 transmissions per day, average current consumption is:

\[I_{avg} = \frac{4 \times [(50 \times 3) + (200 \times 5) + (220 \times 10) + (15 \times 20)]}{86400} + 0.005 \approx 0.052 \text{ mA}\]

With 5000 mAh battery, theoretical life = \(\frac{5000}{0.052} \approx 96,154\) hours (≈11 years). Accounting for 80% aging efficiency, practical life = \(96,154 \times 0.8 \div 8760 \approx 8.8\) years. Reducing to 1 transmission/day extends this beyond 10 years.

14.6.4 Task 2: Energy Calculation per Day

Energy per transmission cycle:

Wake-up: \[E_{wake} = 0.050 \text{ A} \times 3 \text{ s} \times 3.6 \text{ V} = 0.54 \text{ Ws}\]

Network attach: \[E_{attach} = 0.200 \times 5 \times 3.6 = 3.6 \text{ Ws}\]

Transmission: \[E_{tx} = 0.220 \times 10 \times 3.6 = 7.92 \text{ Ws}\]

RRC Idle: \[E_{idle} = 0.015 \times 20 \times 3.6 = 1.08 \text{ Ws}\]

Active time per cycle: 3 + 5 + 10 + 20 = 38 seconds PSM time per cycle: 6 hours - 38s = 21,562 seconds

PSM energy: \[E_{psm} = 0.000005 \times 21,562 \times 3.6 = 0.388 \text{ Ws}\]

Total energy per cycle: \[E_{cycle} = 0.54 + 3.6 + 7.92 + 1.08 + 0.388 = 13.528 \text{ Ws}\]

Daily energy (4 cycles): \[E_{day} = 13.528 \times 4 = 54.112 \text{ Ws} = 0.015 \text{ Wh/day}\]

14.6.5 Task 3: Battery Life Calculation

\[\text{Battery life} = \frac{18 \text{ Wh}}{0.015 \text{ Wh/day}} = 1,200 \text{ days} \approx 3.3 \text{ years}\]

With battery aging and self-discharge (assume 80% efficiency): \[\text{Practical battery life} = 1,200 \times 0.8 = 960 \text{ days} \approx 2.6 \text{ years}\]

14.6.6 Task 4: Optimization for 10-Year Life

To achieve 10-year battery life (3,650 days), we need:

\[E_{day\_required} = \frac{18 \text{ Wh} \times 0.8}{3,650 \text{ days}} = 0.00395 \text{ Wh/day}\]

Options:

  1. Reduce reporting frequency to 1/day:
    • \(E_{day} = 13.528 \text{ Ws} = 0.00376 \text{ Wh/day}\) ✓ Achieves 10 years!
  2. Increase battery size to 19 Ah (3.6V × 19 Ah = 68.4 Wh):
    • With 4 readings/day: \(\frac{68.4 \times 0.8}{0.015} = 3,648 \text{ days} \approx 10 \text{ years}\)
  3. Use external power (e.g., current transformer on power line):
    • Harvest energy from measured circuit
    • No battery limitations

Recommendation: For 10-year battery life, either reduce reporting to once daily OR use larger battery (19 Ah D-cell).

14.8 Summary

  • AT command configuration provides low-level control of NB-IoT modules (SIM7020, BC66, SIM7000) for network attachment, power mode configuration, and data transmission
  • Network attachment process involves SIM card detection (AT+CPIN), network registration (AT+COPS), and GPRS attach (AT+CGATT) with typical connection times of 30-90 seconds
  • PSM and eDRX configuration uses T3412 and T3324 timers to balance battery life and reachability, with proper settings enabling 10-15 year device lifetime on 5-10 Ah batteries
  • UDP and CoAP protocols are preferred for NB-IoT due to low overhead compared to TCP, with CoAP providing RESTful semantics optimized for constrained devices
  • Signal diagnostics (AT+CSQ, AT+COPS, AT+CEREG) are essential for troubleshooting connectivity issues, with RSSI > -100 dBm generally required for reliable operation
  • Coverage enhancement modes (CE0, CE1, CE2) automatically adapt based on signal conditions, trading latency for deep coverage penetration in challenging RF environments
  • Real-world deployment requires consideration of carrier selection, SIM provisioning, power budget analysis, coverage mapping, and field testing before large-scale rollout

14.9 Concept Relationships

This hands-on chapter connects theoretical NB-IoT concepts to practical implementation:

  • AT command sequences translate abstract concepts like PSM, eDRX, and coverage enhancement into actual module configuration strings - understanding the theory enables proper parameter selection
  • Power mode configuration (T3412, T3324 timers) directly impacts battery life calculations from earlier chapters - misconfiguration can reduce a 10-year design to 6 months
  • Signal diagnostics (AT+CSQ, AT+CEREG) provide the real-world feedback loop that validates link budget calculations and coverage predictions
  • Module selection depends on understanding band support, power consumption profiles, and feature trade-offs discussed in fundamentals
  • Firmware updates over NB-IoT require careful data plan management and demonstrate the throughput limitations inherent in the 180 kHz bandwidth design

The gap between theory and practice often appears during field deployment - this lab chapter provides the troubleshooting tools to bridge that gap.

14.10 See Also

Theory Foundation:

Hands-On Learning:

Application Protocols:

Related Labs:

Common Pitfalls

Most NB-IoT modules operate at 3.3V and have 3.3V-only UART pins. Connecting a 5V Arduino or USB-UART adapter directly to a 3.3V NB-IoT module will permanently damage the UART input pins and potentially the modem IC. Always use a 3.3V-compatible USB-UART adapter (FTDI FT232R with VCC set to 3.3V) or a logic level shifter. Verify module VIO voltage specification before connecting any logic-level signals.

NB-IoT lab implementations that only test connectivity without measuring current consumption miss the core optimization objective. A lab that shows “data received on server” without measuring PSM entry current (<5 µA), registration current (10–50 mA), and transmission current (100–200 mA) is incomplete. Include a µA-resolution current measurement tool (Nordic PPK2, Otii Arc, or a 1Ω shunt resistor + oscilloscope) in every NB-IoT lab setup to validate power optimization.

NB-IoT module default UART baud rates vary by vendor: u-blox: 115200; Quectel: 9600 or 115200; Nordic nRF9160: 115200 (logged as CMUX format). A terminal at the wrong baud rate produces only garbage characters with no indication of the problem. Always check module documentation for default UART settings, or use autobaud detection by trying common rates (9600, 19200, 38400, 57600, 115200) with “AT” until you see “OK”.

AT commands have vastly different response times: AT (echo): <100 ms; AT+CEREG? (registration check): <300 ms; AT+CGDCONT (PDP configuration): <1 s; AT+CGACT=1 (PDP activate): 5–60 s; AT+NSOST (data send): 1–30 s in poor coverage. Firmware implementations with a single 1-second timeout for all AT commands will fail on commands requiring longer processing. Implement command-specific timeouts: use 300 ms for status queries, 10 s for connection operations, 60 s for data transmission in CE Mode B.

14.11 What’s Next

Next Topic Description
NB-IoT Comprehensive Review Test your hands-on implementation knowledge with comprehensive quiz scenarios
NB-IoT Lab Simulation Practice NB-IoT state machines and power calculations in a browser-based ESP32 simulator
Cellular IoT Fundamentals Expand to LTE-M, 5G NR-IoT, and other cellular IoT technologies
CoAP Fundamentals Implement lightweight request-response communication optimized for NB-IoT payloads
MQTT Fundamentals Deploy publish-subscribe messaging patterns over NB-IoT cellular links