This interactive lab uses an ESP32 in Wokwi to simulate NB-IoT behaviors including the network attach procedure, PSM and eDRX timer configurations, coverage enhancement repetitions, and uplink data transmission, letting you observe state transitions and calculate battery life projections without requiring actual cellular hardware.
Trace the NB-IoT attach procedure: Map each step of cell search, RRC connection, and authentication in simulation output
Configure PSM timers: Set T3412 and T3324 timer values and predict their effect on sleep/wake behavior
Differentiate PSM vs eDRX trade-offs: Evaluate how each power mode affects current draw, downlink latency, and battery longevity
Assess Coverage Enhancement impact: Quantify how CE level repetitions trade power consumption for signal reliability
Calculate battery life projections: Derive real-world battery consumption estimates from simulation power profiles
For Beginners: NB-IoT Lab Simulation
This lab simulates NB-IoT device behavior using an ESP32 microcontroller. You will experience the connection process, power saving modes, and data transmission patterns that real NB-IoT devices use. It is a hands-on way to understand cellular IoT without needing an actual cellular network or SIM card.
Sensor Squad: Simulating NB-IoT on ESP32
“You do not need a real cellular network to learn NB-IoT!” announced Max the Microcontroller, loading the Wokwi simulator. “This ESP32 simulation mimics exactly what a real NB-IoT modem does – cell search, authentication, PSM timers, coverage enhancement, and data transmission. Same state machines, same timing, same power calculations.”
Sammy the Sensor leaned in. “What will I see?” Max explained, “You will watch the attach procedure step by step: the device searches for a cell, establishes a radio connection, authenticates with the network, and activates a data bearer. Then you can toggle between PSM and eDRX to see how sleep patterns change.”
“The power calculation is the most eye-opening part,” said Bella the Battery. “The simulation shows exact current draw in each state: 220 milliamps during transmission, 46 milliamps while receiving, and just 3 microamps in PSM sleep. When you see those numbers multiplied by time, you understand why PSM configuration makes the difference between a few months and 10 years of battery life.”
Lila the LED encouraged experimentation. “Try changing the TAU timer and see how battery life projections change. Try enabling Coverage Enhancement mode and watch how repetitions improve reliability but increase power draw. The simulator lets you explore trade-offs that would take weeks to test on real hardware.”
13.2 Lab Overview
This interactive lab provides a hands-on simulation of NB-IoT concepts using an ESP32 microcontroller in Wokwi. While actual NB-IoT communication requires specialized cellular modules and carrier connectivity, this simulation demonstrates the key concepts and procedures that real NB-IoT devices perform.
What You Will Explore:
Network Attach Procedure: Trace each step of the multi-step process devices use to connect to cellular networks
PSM (Power Saving Mode): Demonstrate how devices achieve 10+ year battery life through deep sleep states
eDRX (Extended Discontinuous Reception): Evaluate the trade-offs between power saving and downlink responsiveness
Coverage Extension Modes: Measure how signal repetition enables deep indoor penetration at the cost of energy
Uplink Data Transmission: Examine the overhead involved in sending small IoT payloads
Network Status Monitoring: Interpret signal quality, network registration, and connection state indicators
Prerequisites: Basic understanding of C/C++ programming and familiarity with microcontroller concepts.
13.3 Lab Environment
The simulation below runs on an ESP32 in Wokwi’s browser-based environment. The code simulates NB-IoT modem behavior, including realistic timing, state machines, and power calculations.
How to Use This Lab
Copy the code from the section below into the Wokwi editor
Click “Start Simulation” to run the NB-IoT simulation
Open the Serial Monitor (115200 baud) to see detailed output
Observe the state transitions as the simulated device attaches to the network
Try the challenge exercises to deepen your understanding
13.4 Complete NB-IoT Simulation Code
Copy this code into the Wokwi editor to run the simulation:
This simulation demonstrates NB-IoT concepts but differs from real deployments:
What this simulation shows accurately:
State machine progression and timing relationships
Power consumption ratios between states
Coverage Enhancement level selection logic
PSM and eDRX timer behavior
What requires real hardware/network:
Actual RF signal measurement (RSRP, RSRQ, SINR)
Real carrier authentication and SIM provisioning
True power consumption measurements
Network-negotiated timer values (carriers may override requests)
SCEF integration for Control Plane optimization
For hands-on NB-IoT development:
Use modules like Quectel BC95, u-blox SARA-N2, or Nordic nRF9160
Obtain NB-IoT SIM cards from carriers (AT&T, Verizon, T-Mobile in US)
Consider IoT platforms like Soracom, Hologram, or 1NCE for connectivity
Worked Example: Calculating Battery Life from Simulation Data
Scenario: You ran the NB-IoT simulation for 2 hours and observed the following power consumption profile. Use this data to project battery life for a real deployment with a 5000 mAh battery.
Simulation Output (2-hour window):
Total Transmissions: 8 uplink messages
Total Active Time: 304 seconds
Average interval: 15 minutes between transmissions
Coverage Enhancement: Level 1 (moderate, 32 repetitions)
Power breakdown:
- Cell search: 3 sec @ 80 mA = 240 mAs = 0.067 mAh (1×)
- Authentication: 6 sec @ 50 mA = 300 mAs = 0.083 mAh (1×)
- Transmission: 8 sec @ 220 mA = 1,760 mAs = 0.489 mAh (8×)
- Active window: 30 sec @ 15 mA = 450 mAs = 0.125 mAh (8×)
- PSM sleep: 7,171 sec @ 0.003 mA = 21.5 mAs = 0.006 mAh
Total consumed: 0.067 + 0.083 + (8 × 0.489) + (8 × 0.125) + 0.006 = 5.062 mAh
Step 1: Extract daily energy consumption
Simulation shows 8 transmissions in 2 hours (120 minutes). Scale to 24 hours: - Transmissions per day: 8 × (24/2) = 96 transmissions - This represents a sensor reporting every 15 minutes
Energy per transmission cycle (from simulation): - TX: 0.489 mAh - Active window: 0.125 mAh - PSM sleep (between transmissions): 15 min × 0.003 mA × (1/60) = 0.00075 mAh
Energy per day: - Transmission energy: 96 × 0.489 = 46.94 mAh - Active window energy: 96 × 0.125 = 12.00 mAh - Sleep energy: (24 hours - 96 × 38 sec/3600) × 0.003 = (24 - 1.01) × 0.003 = 0.069 mAh - Daily total: 46.94 + 12.00 + 0.069 = 59.01 mAh/day
Battery life: 5000 mAh / 59.01 mAh/day = 84.7 days = 2.8 months
Step 2: Compare to more realistic reporting frequency
The simulation defaults to frequent transmissions for demonstration. Real sensors typically report less often:
The simulation used CE Level 1 (32 repetitions). If sensors are in deep coverage (CE Level 2, 128 repetitions), transmission energy increases 4×:
Daily reporting with CE Level 2:
TX energy: 1 × (0.489 × 4) = 1.956 mAh
Active: 1 × 0.125 = 0.125 mAh
Sleep: 0.072 mAh
Daily: 1.956 + 0.125 + 0.072 = 2.153 mAh/day
Battery life: 5000 / 2.153 = **2,322 days = 6.4 years**
Putting Numbers to It
Coverage Enhancement Level 2 uses 128 repetitions vs 1 at CE0, increasing transmission time by \(128\times\). For daily transmission at 0.489 mAh in CE0:
(The \(\frac{1}{32}\) factor accounts for CE1 baseline with 32 repetitions.) With total daily consumption 2.153 mAh, battery life = \(\frac{5000}{2.153} \approx 2,322\) days. This shows CE2 reduces battery life from 20 years (CE0) to 6.4 years – a 3.1× penalty for deep indoor coverage.
Step 4: Create deployment table
Reporting Interval
CE Level 0 (Normal)
CE Level 1 (Extended)
CE Level 2 (Extreme)
15 minutes (96/day)
3.5 months
2.8 months
0.7 months
1 hour (24/day)
14 months
11 months
2.8 months
6 hours (4/day)
7 years
5.5 years
1.4 years
Daily (1/day)
25 years
20 years
6.4 years
Key Insights:
PSM sleep current dominates only when transmissions are infrequent. At 96 TX/day, transmission energy is 796× larger than sleep energy.
Coverage Enhancement has massive impact: CE Level 2 reduces battery life by 75% compared to normal coverage due to 128× repetitions.
Optimal configuration for 10-year battery life:
Target: Daily reporting in normal coverage (CE Level 0)
Acceptable: 6-hour reporting in extended coverage (CE Level 1)
Not viable: Hourly reporting in extreme coverage (CE Level 2)
Design trade-offs:
If 10-year battery life is non-negotiable → deploy indoor small cells to improve coverage to CE Level 0
If frequent updates are non-negotiable → accept 1-2 year battery life and plan replacement logistics
Most deployments: Balance at daily/6-hour reporting with CE Level 0-1 coverage
Lesson: The simulation’s 2-hour dataset accurately models power consumption mechanics. Extrapolate to real deployment by scaling transmission frequency and accounting for coverage enhancement levels observed during site surveys. Always validate projections with 1-week field test before committing to 10+ year battery claims.
PSM (Power Saving Mode) achieves 3 uA sleep current by completely disabling the radio
T3324 controls active time before entering PSM; shorter values save power but reduce downlink opportunity
Coverage Enhancement uses repetitions to improve reliability in poor signal conditions
Battery life projection depends on sleep current, TX duration, message frequency, and CE level
This simulation provides conceptual understanding; real deployments require certified modules and carrier connectivity
13.11 Knowledge Check
Quiz: NB-IoT Lab Simulation
Matching Quiz: NB-IoT Simulation States and Power Characteristics
Ordering Quiz: NB-IoT Network Attach Procedure
13.12 Concept Relationships
This simulation lab brings together multiple NB-IoT concepts in executable form:
Network attach procedure (cell search, RRC, authentication) demonstrates the signaling overhead that dominates initial power consumption - often 10-20x the actual data transmission cost
PSM timers (T3412, T3324) directly control state transitions in the simulation, showing how timer configuration translates to specific wake-sleep patterns and battery consumption
Coverage enhancement (CE levels, repetitions) is modeled through transmission time multiplication, illustrating why a sensor in CE2 consumes 64-128x more energy than CE0
Power calculations integrate across all states (active, idle, PSM sleep) to produce realistic battery life projections that match field deployment data
State machine logic captures the event-driven nature of NB-IoT operation - devices react to timers, network events, and application triggers rather than maintaining continuous connections
Running the simulation with different parameter sets builds intuition for the multi-way trade-offs between coverage, power, latency, and downlink reachability.
1. Running NB-IoT Lab Without a Hardware Current Measurement
NB-IoT lab simulations that only verify data transmission success (packet received on server) without measuring current consumption miss the primary objective: validating power optimization. A simulated NB-IoT lab must include a current measurement phase: configure PSM parameters, transmit test data, measure the current waveform (active peak, registration current, PSM sleep current), and calculate energy per transmission. Without current measurement, the lab validates connectivity but not the IoT-critical power optimization behavior.
2. Not Testing PSM Timer Recovery After Unexpected Disconnection
NB-IoT lab simulations often test only the nominal PSM flow: transmit → enter PSM → wake → transmit. They miss the failure recovery path: if the device loses registration while in PSM (due to network reboot or signal loss), it must re-register on the next wakeup. Lab exercises must include a network disconnect simulation: power off the NB-IoT modem during PSM, restart it, and verify the device re-registers, re-activates the PDP context, and resumes normal operation. Firmware that cannot recover from this scenario will be stuck offline in production.
3. Using Simulators That Do Not Model NB-IoT Coverage Classes
NB-IoT simulators that only model CE Level 0 (good coverage, no repetitions) do not prepare students for real deployments where 30–50% of devices operate in CE Level 1 or 2. Lab simulations should include coverage-impaired scenarios: use a signal attenuator to reduce RSRP below -100 dBm, observe the modem automatically switching to CE Level 1/2, measure the increased current consumption due to HARQ repetitions, and compare transmission time and energy at CE Level 0 vs CE Level 2.
4. Not Verifying PSM Activation After AT Command Configuration
AT+CPSMS=1,,,, requests PSM from the network but does not guarantee activation. The network may reject PSM or grant different timer values. Lab exercises that send AT+CPSMS=1 and immediately proceed without reading AT+CPSMS? to verify the granted values are testing an unconfigured system. Always verify PSM is actually active: send AT+CPSMS? and confirm the +CPSMS: 1,,, response shows “1” (active) before proceeding to PSM energy measurement steps.