Unlock NB-IoT: ESP32 & Quectel Module Integration Guide

NB-IoTFirmware Updates over NB-IoT: Delta Updates with ESP32’s Dual PartitionFirmware Updates over NB-IoT: Delta Updates with ESP32’s Dual PartitionDiscover how delta firmware updates via NB-IoT optimize ESP32 device performance by minimizing data usage and ensuring secure, swift OTA transitions. (Narrowband IoT) is a low-power wide-area network (LPWAN) technology designed for devices requiring intermittent data transmissionConnecting ESP32 to Cloud Services via Wi-FiConnecting ESP32 to Cloud Services via Wi-FiDiscover how to connect your ESP32 to AWS, Azure, and Google Cloud using secure Wi-Fi. This guide covers setup, error handling, and low power strategies. over long distances. This guide explores integrating Quectel BC66/BG96 modules with the ESP32 to enable NB-IoT connectivity, focusing on hardware setup, AT command workflows, power optimization, and real-world use casesZigbee Green Power: Ultra-Low-Power Energy Harvesting SolutionsZigbee Green Power: Ultra-Low-Power Energy Harvesting SolutionsDiscover how ZGP enables battery-free IoT devices through energy harvesting with ESP32 integrations, supporting smart home and industrial applications..

Table of Contents🔗

1. Introduction to NB-IoTFirmware Updates over NB-IoT: Delta Updates with ESP32’s Dual PartitionFirmware Updates over NB-IoT: Delta Updates with ESP32’s Dual PartitionDiscover how delta firmware updates via NB-IoT optimize ESP32 device performance by minimizing data usage and ensuring secure, swift OTA transitions. and Quectel BC66/BG96 Modules

2. Hardware SetupZigbee Green Power: Ultra-Low-Power Energy Harvesting SolutionsZigbee Green Power: Ultra-Low-Power Energy Harvesting SolutionsDiscover how ZGP enables battery-free IoT devices through energy harvesting with ESP32 integrations, supporting smart home and industrial applications.: Wiring and Power Requirements

3. Configuring AT Commands for Network RegistrationSIM7000G Module with ESP32: Configuring LTE-M and GNSSSIM7000G Module with ESP32: Configuring LTE-M and GNSSMaster ESP32 integration with SIM7000G for reliable LTE-M connectivity and precise GPS tracking, featuring hardware setup, AT commands, and power tips.

4. Sending DataConnecting ESP32 to Cloud Services via Wi-FiConnecting ESP32 to Cloud Services via Wi-FiDiscover how to connect your ESP32 to AWS, Azure, and Google Cloud using secure Wi-Fi. This guide covers setup, error handling, and low power strategies. via UDP/HTTP/MQTT

5. Power-Saving Strategies (PSM, eDRXPower-Saving Strategies for ESP32 NB-IoT Deployments (PSM, eDRX)Power-Saving Strategies for ESP32 NB-IoT Deployments (PSM, eDRX)Explore practical strategies and real-world examples for optimizing power consumption in ESP32-based NB-IoT devices using eDRX and PSM modes.)

6. Establishing NB-IoTFirmware Updates over NB-IoT: Delta Updates with ESP32’s Dual PartitionFirmware Updates over NB-IoT: Delta Updates with ESP32’s Dual PartitionDiscover how delta firmware updates via NB-IoT optimize ESP32 device performance by minimizing data usage and ensuring secure, swift OTA transitions. Connectivity via PPP

7. Practical Example: Sensor Data TransmissionConnecting ESP32 to Cloud Services via Wi-FiConnecting ESP32 to Cloud Services via Wi-FiDiscover how to connect your ESP32 to AWS, Azure, and Google Cloud using secure Wi-Fi. This guide covers setup, error handling, and low power strategies.

8. Troubleshooting Common IssuesZigbee Over-the-Air (OTA) Firmware Updates with ESP32 CoordinatorsZigbee Over-the-Air (OTA) Firmware Updates with ESP32 CoordinatorsSecure your IoT network with OTA firmware upgrades using an ESP32 coordinator. Our guide details firmware setup, packaging, security, and troubleshooting.

9. Case StudyCost Analysis: Total Ownership for ESP32 Connectivity SolutionsCost Analysis: Total Ownership for ESP32 Connectivity SolutionsUnlock cost savings with ESP32 IoT solutions. This guide reveals how to balance hardware, connectivity, power, and maintenance costs to master TCO.: Smart Water Meter with NB-IoT

10. Conclusion and Next Steps

Introduction to NB-IoT and Quectel BC66/BG96 Modules🔗

NB-IoTFirmware Updates over NB-IoT: Delta Updates with ESP32’s Dual PartitionFirmware Updates over NB-IoT: Delta Updates with ESP32’s Dual PartitionDiscover how delta firmware updates via NB-IoT optimize ESP32 device performance by minimizing data usage and ensuring secure, swift OTA transitions. is a Low PowerConnecting ESP32 to Cloud Services via Wi-FiConnecting ESP32 to Cloud Services via Wi-FiDiscover how to connect your ESP32 to AWS, Azure, and Google Cloud using secure Wi-Fi. This guide covers setup, error handling, and low power strategies. Wide Area Network (LPWAN) technology designed for IoT devices that require long-range communication with minimal power consumptionQuick Comparison: Range, power consumption, costs, and complexity of each technologyQuick Comparison: Range, power consumption, costs, and complexity of each technologyDiscover the ideal wireless solution for your ESP32 IoT project by analyzing range, power, cost, and complexity. Optimize connectivity now.. It operates on licensed LTE bands, ensuring reliable connectivity even in challenging environments like urban areas or underground locations.

The Quectel BC66 and BG96 modules are compact, low-power cellular modems that support NB-IoT and LTE-M. They are ideal for IoT applications such as smart meters, asset tracking, and environmental monitoringConnecting ESP32 to Cloud Services via Wi-FiConnecting ESP32 to Cloud Services via Wi-FiDiscover how to connect your ESP32 to AWS, Azure, and Google Cloud using secure Wi-Fi. This guide covers setup, error handling, and low power strategies.. These modules communicate with the ESP32 via AT commandsSIM7000G Module with ESP32: Configuring LTE-M and GNSSSIM7000G Module with ESP32: Configuring LTE-M and GNSSMaster ESP32 integration with SIM7000G for reliable LTE-M connectivity and precise GPS tracking, featuring hardware setup, AT commands, and power tips., making them easy to integrate into existing projects.

Hardware Setup: Wiring and Power Requirements🔗

To connect the Quectel BC66 or BG96 module to the ESP32Setting Up ESP32 as a Wi-Fi Access PointSetting Up ESP32 as a Wi-Fi Access PointMaster ESP32 AP configuration with our step-by-step guide. Set up a secure, local IoT network using practical code examples and optimization tips., you’ll need the following:

Wiring Diagram

The Quectel BC66 (NB-IoT) and BG96 (LTE-M/NB-IoTFirmware Updates over NB-IoT: Delta Updates with ESP32’s Dual PartitionFirmware Updates over NB-IoT: Delta Updates with ESP32’s Dual PartitionDiscover how delta firmware updates via NB-IoT optimize ESP32 device performance by minimizing data usage and ensuring secure, swift OTA transitions.) modules communicate with the ESP32 via UARTInterfacing ESP32 with Zigbee3.0 Devices (Xiaomi, Philips Hue)Interfacing ESP32 with Zigbee3.0 Devices (Xiaomi, Philips Hue)Unlock seamless smart home integration by following our detailed guide on bridging ESP32 with external Zigbee modules for reliable IoT solutions.. Here’s a typical wiringAdding NFC to ESP32: Hardware Options (PN532, RC522) and WiringAdding NFC to ESP32: Hardware Options (PN532, RC522) and WiringDiscover how NFC transforms your ESP32 projects with PN532 or RC522 modules. Follow our guide for secure contactless interactions and proper wiring setups. configuration:

graph LR ESP32[ESP32] -->|UART TX| BC66[BC96/BG96 RX] ESP32 -->|UART RX| BC66[BC96/BG96 TX] ESP32 -->|GND| BC66[GND] BC66 -->|VCC (3.4V-4.2V)| LiPo[LiPo Battery]

Key Considerations:

  • Use a 3.3V logic level shifter if your module operates at 1.8V.
  • Provide a stable 2A power supply during peak transmission.
  • Enable the Power Enable (PWRKEY) pin to control the module’s state.

Example Code: Initializing UART CommunicationInterfacing ESP32 with Zigbee3.0 Devices (Xiaomi, Philips Hue)Interfacing ESP32 with Zigbee3.0 Devices (Xiaomi, Philips Hue)Unlock seamless smart home integration by following our detailed guide on bridging ESP32 with external Zigbee modules for reliable IoT solutions.

#include <HardwareSerial.h>
HardwareSerial BC66Serial(1); // Use UART1
void setup() {
  BC66Serial.begin(9600, SERIAL_8N1, 16, 17); // TX=16, RX=17
  pinMode(4, OUTPUT); // PWRKEY pin
  digitalWrite(4, HIGH);
  delay(1000);
  digitalWrite(4, LOW); // Hold PWRKEY low for 1s to turn on
}

Configuring AT Commands for Network Registration🔗

Use AT commandsSIM7000G Module with ESP32: Configuring LTE-M and GNSSSIM7000G Module with ESP32: Configuring LTE-M and GNSSMaster ESP32 integration with SIM7000G for reliable LTE-M connectivity and precise GPS tracking, featuring hardware setup, AT commands, and power tips. to configure the module and attach to the NB-IoTFirmware Updates over NB-IoT: Delta Updates with ESP32’s Dual PartitionFirmware Updates over NB-IoT: Delta Updates with ESP32’s Dual PartitionDiscover how delta firmware updates via NB-IoT optimize ESP32 device performance by minimizing data usage and ensuring secure, swift OTA transitions. network:

CommandResponsePurpose
AT+CFUN=1OKEnable full functionality
AT+COPS=1,2,"24001"OKRegister to network (MCC/MNC)
AT+CGATT=1OKAttach to Packet Data Network
AT+CEREG?+CEREG: 0,1Check network registration status
AT+CSQ+CSQ: 20,99Signal quality (RSSI)

Example: Automated Network Attachment

bool attachNetwork() {
  BC66Serial.println("AT+CGATT=1");
  delay(1000);
  String response = BC66Serial.readString();
  return response.indexOf("OK") != -1;
}

Sending Data via UDP/HTTP/MQTT🔗

HTTP POST Example

void sendHTTPData(String payload) {
  BC66Serial.println("AT+QHTTPPOST=80,30,1");
  delay(1000);
  BC66Serial.println(payload);
  delay(5000); // Wait for server response
}

MQTT Configuration

AT+QMTOPEN=0,"broker.example.com",1883
AT+QMTCONN=0,"ESP32Client"
AT+QMTPUB=0,0,0,0,"sensors/temperature","25.6"

Power-Saving Strategies (PSM, eDRX)🔗

Configure Power Saving ModeSIM7000G Module with ESP32: Configuring LTE-M and GNSSSIM7000G Module with ESP32: Configuring LTE-M and GNSSMaster ESP32 integration with SIM7000G for reliable LTE-M connectivity and precise GPS tracking, featuring hardware setup, AT commands, and power tips. (PSM) and eDRXPower-Saving Strategies for ESP32 NB-IoT Deployments (PSM, eDRX)Power-Saving Strategies for ESP32 NB-IoT Deployments (PSM, eDRX)Explore practical strategies and real-world examples for optimizing power consumption in ESP32-based NB-IoT devices using eDRX and PSM modes. to minimize energy consumptionQuick Comparison: Range, power consumption, costs, and complexity of each technologyQuick Comparison: Range, power consumption, costs, and complexity of each technologyDiscover the ideal wireless solution for your ESP32 IoT project by analyzing range, power, cost, and complexity. Optimize connectivity now.:

// Set PSM parameters (T3412=24h, T3324=1h)
AT+CPSMS=1,,,"00100001","00100001"
// Enable eDRX with 20.48s cycle
AT+CEDRXS=1,5,"0000"

Integration with ESP32Zigbee Green Power: Ultra-Low-Power Energy Harvesting SolutionsZigbee Green Power: Ultra-Low-Power Energy Harvesting SolutionsDiscover how ZGP enables battery-free IoT devices through energy harvesting with ESP32 integrations, supporting smart home and industrial applications. Deep Sleep:

esp_sleep_enable_timer_wakeup(3600 * 1000000); // Sleep for 1 hour
BC66Serial.println("AT+QPOWD=1"); // Power down module
esp_deep_sleep_start();

Establishing NB-IoT Connectivity via PPP🔗

Once the module is responding correctly, the next challenge is setting up a PPP (Point-to-Point Protocol) connection to handle data transmissionConnecting ESP32 to Cloud Services via Wi-FiConnecting ESP32 to Cloud Services via Wi-FiDiscover how to connect your ESP32 to AWS, Azure, and Google Cloud using secure Wi-Fi. This guide covers setup, error handling, and low power strategies. over the cellular network:

  • PPP Overview:

PPP is used in many embedded systems to encapsulate network traffic over serial links. With the Quectel modules, you’ll configure PPP to tunnel IP packets between your ESP32Setting Up ESP32 as a Wi-Fi Access PointSetting Up ESP32 as a Wi-Fi Access PointMaster ESP32 AP configuration with our step-by-step guide. Set up a secure, local IoT network using practical code examples and optimization tips. and the NB‑IoT network.

  • Required Libraries:

Libraries like TinyGSM or PPP-related libraries (often available in ESP-IDF or Arduino ecosystems) can manage the negotiation and handling of PPP connections. They abstract many complexitiesQuick Comparison: Range, power consumption, costs, and complexity of each technologyQuick Comparison: Range, power consumption, costs, and complexity of each technologyDiscover the ideal wireless solution for your ESP32 IoT project by analyzing range, power, cost, and complexity. Optimize connectivity now. like authentication and error correction.

  • Initialization Flow:

1. Attach to Network: Send AT+CGATT=1 to ensure the module attaches to the cellular network.

2. Activate PDP Context: Configure the Packet Data Protocol (PDP) context with the appropriate APN using, for example, AT+CGDCONT=1,"IP","your_apn_here".

3. Start PPP Session: Engage a PPP daemon or library to take over the connection through a designated UARTInterfacing ESP32 with Zigbee3.0 Devices (Xiaomi, Philips Hue)Interfacing ESP32 with Zigbee3.0 Devices (Xiaomi, Philips Hue)Unlock seamless smart home integration by following our detailed guide on bridging ESP32 with external Zigbee modules for reliable IoT solutions. interface.

This workflow enables your ESP32 to treat NB‑IoT connectivity similarly to a typical modem interface, making the integration into IoT applicationsConnecting ESP32 to Cloud Services via Wi-FiConnecting ESP32 to Cloud Services via Wi-FiDiscover how to connect your ESP32 to AWS, Azure, and Google Cloud using secure Wi-Fi. This guide covers setup, error handling, and low power strategies. much smoother.

Practical Example: Sensor Data Transmission🔗

Imagine deploying a remote environmental sensor node that periodically sends temperature and humidity data to a cloud platformConnecting ESP32 to Cloud Services via Wi-FiConnecting ESP32 to Cloud Services via Wi-FiDiscover how to connect your ESP32 to AWS, Azure, and Google Cloud using secure Wi-Fi. This guide covers setup, error handling, and low power strategies.:

1. Data Acquisition:

A sensor (e.g., DHT22) is connected to the ESP32Setting Up ESP32 as a Wi-Fi Access PointSetting Up ESP32 as a Wi-Fi Access PointMaster ESP32 AP configuration with our step-by-step guide. Set up a secure, local IoT network using practical code examples and optimization tips., which collects measurements at set intervals.

2. Transmission via NB‑IoTSigfox Message Encoding: Packing Sensor Data into 12-byte PayloadsSigfox Message Encoding: Packing Sensor Data into 12-byte PayloadsLearn efficient data encoding techniques for Sigfox's constrained 12-byte payloads. Discover bitwise operations, structured encoding & CBOR strategies.:

The ESP32 uses the established PPP connection to send the sensor dataSigfox Message Encoding: Packing Sensor Data into 12-byte PayloadsSigfox Message Encoding: Packing Sensor Data into 12-byte PayloadsLearn efficient data encoding techniques for Sigfox's constrained 12-byte payloads. Discover bitwise operations, structured encoding & CBOR strategies. over the NB‑IoT network, often using MQTT or HTTP protocols.

3. Code Sketch for Data Send:

#include <TinyGsmClient.h>
#include <PubSubClient.h>
#define TINY_GSM_MODEM_BG96  // Specify appropriate modem type
HardwareSerial NBSerial(1);
TinyGsm modem(NBSerial);
TinyGsmClient client(modem);
PubSubClient mqttClient(client);
void setup() {
  Serial.begin(115200);
  NBSerial.begin(115200, SERIAL_8N1, 16, 17);
  delay(1000);
  // Initialize modem and check connectivity
  Serial.println("Initializing modem...");
  modem.restart();
  modem.gprsConnect("your_apn_here", "user", "pass");
  // Setup MQTT client and connection
  mqttClient.setServer("mqtt.yourbroker.com", 1883);
  while (!mqttClient.connected()) {
    Serial.println("Connecting to MQTT...");
    if (mqttClient.connect("ESP32_Client")) {
      Serial.println("Connected to MQTT broker!");
    } else {
      delay(2000);
    }
  }
}
void loop() {
  // Simulate sensor data reading
  float temperature = 25.0; // Replace with actual sensor reading code
  float humidity = 50.0;
  // Construct and send payload
  String payload = "{\"temperature\": " + String(temperature) + ", \"humidity\": " + String(humidity) + "}";
  mqttClient.publish("sensors/environment", payload.c_str());
  Serial.println("Data sent: " + payload);
  // Sleep or wait for the next reading
  delay(60000); // 1-minute interval
}

This example shows how you can blend sensor data acquisition with NB‑IoT data transmissionConnecting ESP32 to Cloud Services via Wi-FiConnecting ESP32 to Cloud Services via Wi-FiDiscover how to connect your ESP32 to AWS, Azure, and Google Cloud using secure Wi-Fi. This guide covers setup, error handling, and low power strategies. using the PPP connection and MQTT protocols.

Troubleshooting Common Issues🔗

1. Network RegistrationSIM7000G Module with ESP32: Configuring LTE-M and GNSSSIM7000G Module with ESP32: Configuring LTE-M and GNSSMaster ESP32 integration with SIM7000G for reliable LTE-M connectivity and precise GPS tracking, featuring hardware setup, AT commands, and power tips. Failure:

  • Verify APN settings: AT+CGDCONT=1,"IP","your.apn"
  • Check antenna connection (2 dB gain recommended).

2. AT CommandSIM7000G Module with ESP32: Configuring LTE-M and GNSSSIM7000G Module with ESP32: Configuring LTE-M and GNSSMaster ESP32 integration with SIM7000G for reliable LTE-M connectivity and precise GPS tracking, featuring hardware setup, AT commands, and power tips. Timeouts:

3. High Power ConsumptionQuick Comparison: Range, power consumption, costs, and complexity of each technologyQuick Comparison: Range, power consumption, costs, and complexity of each technologyDiscover the ideal wireless solution for your ESP32 IoT project by analyzing range, power, cost, and complexity. Optimize connectivity now.:

  • Disable unused features: AT+QSCLK=0 (Disable sleep clock).

4. PPP Connection Stability:

Case Study: Smart Water Meter with NB-IoT🔗

Objective: Transmit water usage data every 6 hours from a remote location.

Hardware:

Code Snippet:

void loop() {
  float liters = readFlowSensor();
  String payload = "{\"usage\":" + String(liters) + "}";
  BC66Serial.println("AT+QIACT=1"); // Activate PDP context
  delay(1000);
  sendHTTPData(payload);
  // Enter deep sleep
  esp_sleep_enable_timer_wakeup(6 * 3600 * 1000000);
  esp_deep_sleep_start();
}

Results:

Conclusion and Next Steps🔗

Integrating Quectel BC66/BG96 modules with the ESP32 for NB‑IoT connectivity opens up a realm of possibilities for deploying cost‑effective, energy‑efficient, and wide‑area IoT networks. By mastering both the hardware interfacing and software stack-from detailed AT commandSIM7000G Module with ESP32: Configuring LTE-M and GNSSSIM7000G Module with ESP32: Configuring LTE-M and GNSSMaster ESP32 integration with SIM7000G for reliable LTE-M connectivity and precise GPS tracking, featuring hardware setup, AT commands, and power tips. sequences to robust PPP connection management-you can build scalable applications that operate reliably in the field.

As you advance, consider experimenting with additional features such as firmware over-the-air (OTA) updates or combining NB‑IoT connectivity with other ESP32-native protocols for hybrid network solutions. Happy tinkering and may your IoT projectsConnecting ESP32 to Cloud Services via Wi-FiConnecting ESP32 to Cloud Services via Wi-FiDiscover how to connect your ESP32 to AWS, Azure, and Google Cloud using secure Wi-Fi. This guide covers setup, error handling, and low power strategies. thrive!

Author: Marcelo V. Souza - Engenheiro de Sistemas e Entusiasta em IoT e Desenvolvimento de Software, com foco em inovação tecnológica.

References🔗

Share article

Related Articles