Delta Firmware Updates via NB-IoT and ESP32 Dual-Partitions

Firmware updatesAWS IoT Core with ESP32: X.509 Certificates and Shadow UpdatesAWS IoT Core with ESP32: X.509 Certificates and Shadow UpdatesLearn to securely connect ESP32 to AWS IoT Core using X.509 certificates and device shadows, with step-by-step instructions and best practices. are critical for maintaining IoT devices, especially those deployed in remote or hard-to-reach locations. With NB-IoT (Narrow Band IoT), bandwidth and power efficiency are key concerns. This article explores how to implement delta updatesDelta Updates: Reducing OTA Payload Size for Cellular NetworksDelta Updates: Reducing OTA Payload Size for Cellular NetworksLearn how delta updates reduce data usage, improve speed, and cut costs for ESP32 firmware patches over NB-IoT/LTE-M cellular networks.-a method of updating only the changed portions of firmware-using the ESP32’sCombining Wi-Fi with Deep Sleep for Low-Power ApplicationsCombining Wi-Fi with Deep Sleep for Low-Power ApplicationsLearn how to integrate Wi-Fi and deep sleep on ESP32 to maximize battery life in IoT devices. This guide offers practical tips and step-by-step instructions. dual-partition scheme. This approach minimizes data usage and ensures reliable updates over NB-IoT networks.

Table of Contents🔗

1. Introduction to Delta UpdatesDelta Updates: Reducing OTA Payload Size for Cellular NetworksDelta Updates: Reducing OTA Payload Size for Cellular NetworksLearn how delta updates reduce data usage, improve speed, and cut costs for ESP32 firmware patches over NB-IoT/LTE-M cellular networks.

2. Why Delta UpdatesDelta Updates: Reducing OTA Payload Size for Cellular NetworksDelta Updates: Reducing OTA Payload Size for Cellular NetworksLearn how delta updates reduce data usage, improve speed, and cut costs for ESP32 firmware patches over NB-IoT/LTE-M cellular networks. Over NB-IoT?

3. ESP32’sCombining Wi-Fi with Deep Sleep for Low-Power ApplicationsCombining Wi-Fi with Deep Sleep for Low-Power ApplicationsLearn how to integrate Wi-Fi and deep sleep on ESP32 to maximize battery life in IoT devices. This guide offers practical tips and step-by-step instructions. Dual-Partition Scheme

4. Delta UpdateDelta Updates: Reducing OTA Payload Size for Cellular NetworksDelta Updates: Reducing OTA Payload Size for Cellular NetworksLearn how delta updates reduce data usage, improve speed, and cut costs for ESP32 firmware patches over NB-IoT/LTE-M cellular networks. Workflow

5. Implementing Delta UpdatesDelta Updates: Reducing OTA Payload Size for Cellular NetworksDelta Updates: Reducing OTA Payload Size for Cellular NetworksLearn how delta updates reduce data usage, improve speed, and cut costs for ESP32 firmware patches over NB-IoT/LTE-M cellular networks. via NB-IoT

6. Preparing Delta UpdatesDelta Updates: Reducing OTA Payload Size for Cellular NetworksDelta Updates: Reducing OTA Payload Size for Cellular NetworksLearn how delta updates reduce data usage, improve speed, and cut costs for ESP32 firmware patches over NB-IoT/LTE-M cellular networks.

7. Optimizing Delta Payloads for NB-IoTUsing Quectel BC66/BG96 Modules with ESP32 for NB-IoT ConnectivityUsing Quectel BC66/BG96 Modules with ESP32 for NB-IoT ConnectivityExplore our detailed tutorial on integrating Quectel BC66/BG96 with ESP32 for low-power, reliable NB-IoT connectivity. Learn hardware setup and AT commands.

8. Code Example: Delta UpdateDelta Updates: Reducing OTA Payload Size for Cellular NetworksDelta Updates: Reducing OTA Payload Size for Cellular NetworksLearn how delta updates reduce data usage, improve speed, and cut costs for ESP32 firmware patches over NB-IoT/LTE-M cellular networks. Integration

9. Security ConsiderationsZigbee 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.

10. Best PracticesZigbee 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. for Delta Updates

11. Conclusion

Introduction to Delta Updates🔗

Delta updates are a smart way to minimize the size of firmware updatesAWS IoT Core with ESP32: X.509 Certificates and Shadow UpdatesAWS IoT Core with ESP32: X.509 Certificates and Shadow UpdatesLearn to securely connect ESP32 to AWS IoT Core using X.509 certificates and device shadows, with step-by-step instructions and best practices. by transmitting only the differences (delta) between the current and new firmware versions. This is particularly useful for:

Instead of sending the entire firmware image, delta updatesDelta Updates: Reducing OTA Payload Size for Cellular NetworksDelta Updates: Reducing OTA Payload Size for Cellular NetworksLearn how delta updates reduce data usage, improve speed, and cut costs for ESP32 firmware patches over NB-IoT/LTE-M cellular networks. use algorithms (e.g., bsdiff or xdelta) to compute and apply only the changes. This can reduce the update size by up to 90%, depending on the changes.

Why Delta Updates Over NB-IoT?🔗

NB-IoTUsing Quectel BC66/BG96 Modules with ESP32 for NB-IoT ConnectivityUsing Quectel BC66/BG96 Modules with ESP32 for NB-IoT ConnectivityExplore our detailed tutorial on integrating Quectel BC66/BG96 with ESP32 for low-power, reliable NB-IoT connectivity. Learn hardware setup and AT commands. excels in wide-area coverage and power efficiency but has strict limitations:

A full firmware image (1-2 MB) would take hours/days to transmit and incur high costs. Delta updatesDelta Updates: Reducing OTA Payload Size for Cellular NetworksDelta Updates: Reducing OTA Payload Size for Cellular NetworksLearn how delta updates reduce data usage, improve speed, and cut costs for ESP32 firmware patches over NB-IoT/LTE-M cellular networks. reduce this to 10-100 KB by sending only modified code segments.

Update TypeSize (ESP32 App Partition)NB-IoT Transmit Time
Full1.5 MB~24 hours
Delta15 KB~10 minutes

ESP32’s Dual-Partition Scheme🔗

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. supports a dual-partition scheme, which allows for safe and reliable firmware updatesAWS IoT Core with ESP32: X.509 Certificates and Shadow UpdatesAWS IoT Core with ESP32: X.509 Certificates and Shadow UpdatesLearn to securely connect ESP32 to AWS IoT Core using X.509 certificates and device shadows, with step-by-step instructions and best practices.. The two partitions are:

1. Factory Partition: Contains the original firmware.

2. OTAImplementing Over-the-Air (OTA) Updates via Wi-Fi on ESP32Implementing Over-the-Air (OTA) Updates via Wi-Fi on ESP32Learn how to implement secure and reliable OTA updates on ESP32 for enhanced IoT performance, easy updates, and rollback capability without physical access. Partition: Stores the updated firmware.

During an OTA updateDual-Partition OTA: Safe Rollback and A/B Testing on ESP32Dual-Partition OTA: Safe Rollback and A/B Testing on ESP32Explore the ESP32 dual-partition OTA update process, ensuring safe rollbacks and effective A/B testing for reliable IoT deployments., the new firmware is written to the OTA partition while the device continues running from the factory partition. Once the update is complete and verified, the device reboots into the OTA partition.

This scheme ensures:

// ESP32 partition table example
# Name,   Type, SubType, Offset,  Size
ota_0,    0,    ota_0,   0x10000, 1M
ota_1,    0,    ota_1,   0x110000,1M
factory,  0,    factory, 0x210000,1M

Rollback Mechanism: If the new firmware crashes, the bootloader reverts to the last stable partition.

Delta Update Workflow🔗

Here’s how delta updatesDelta Updates: Reducing OTA Payload Size for Cellular NetworksDelta Updates: Reducing OTA Payload Size for Cellular NetworksLearn how delta updates reduce data usage, improve speed, and cut costs for ESP32 firmware patches over NB-IoT/LTE-M cellular networks. work with the ESP32 and NB-IoT:

1. Generate Delta File: On the server, compute the delta between the current and new firmware using a tool like bsdiff.

2. Transmit Delta File: Send the delta file to the ESP32 over NB-IoTUsing Quectel BC66/BG96 Modules with ESP32 for NB-IoT ConnectivityUsing Quectel BC66/BG96 Modules with ESP32 for NB-IoT ConnectivityExplore our detailed tutorial on integrating Quectel BC66/BG96 with ESP32 for low-power, reliable NB-IoT connectivity. Learn hardware setup and AT commands..

3. Apply Delta: On 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., use the delta file to reconstruct the new firmware and write it to the OTA partition.

4. Verify and Reboot: Validate the new firmware and reboot into the updated partition.

Implementing Delta Updates via NB-IoT🔗

To implement delta updatesDelta Updates: Reducing OTA Payload Size for Cellular NetworksDelta Updates: Reducing OTA Payload Size for Cellular NetworksLearn how delta updates reduce data usage, improve speed, and cut costs for ESP32 firmware patches over NB-IoT/LTE-M cellular networks. with NB-IoT:

1. Choose a Delta Algorithm:

  • bsdiff: Efficient but requires more RAM.
  • xdelta: Lightweight but slightly less efficient.

2. Integrate Delta Library:

3. Optimize for NB-IoTUsing Quectel BC66/BG96 Modules with ESP32 for NB-IoT ConnectivityUsing Quectel BC66/BG96 Modules with ESP32 for NB-IoT ConnectivityExplore our detailed tutorial on integrating Quectel BC66/BG96 with ESP32 for low-power, reliable NB-IoT connectivity. Learn hardware setup and AT commands.:

  • Compress the delta file before transmission.
  • Use chunked transmission to handle limited packet sizes.

4. Handle Power Constraints:

  • Schedule updates during active periods to avoid waking the device unnecessarily.

Preparing Delta Updates🔗

Step 1: Generate Binary Diffs

Use tools like xdelta3 or Espressif’s esp_diff.py to create patches:

esp_diff.py build/firmware_v1.bin build/firmware_v2.bin delta.bin

Step 2: Split Delta into NB-IoT-Friendly Chunks

Divide delta.bin into 1.4 KB blocks for transmission:

CHUNK_SIZE = 1400
with open("delta.bin", "rb") as f:
    chunk = f.read(CHUNK_SIZE)
    while chunk:
        send_over_nbiot(chunk)  // Send via Quectel BC66 module
        chunk = f.read(CHUNK_SIZE)

Optimizing Delta Payloads for NB-IoT🔗

# Compress delta with LZMA
import lzma
with open("delta.bin", "rb") as f_in:
    with lzma.open("delta.xz", "wb") as f_out:
        f_out.write(f_in.read())

Code Example: Delta Update Integration🔗

Below is a simplified example of applying a delta updateDelta Updates: Reducing OTA Payload Size for Cellular NetworksDelta Updates: Reducing OTA Payload Size for Cellular NetworksLearn how delta updates reduce data usage, improve speed, and cut costs for ESP32 firmware patches over NB-IoT/LTE-M cellular networks. on the ESP32:

#include "esp_ota_ops.h"
#include "esp_http_client.h"
#include "esp_log.h"
#include "bsdiff.h"
#define TAG "DELTA_OTA"
void apply_delta_update(const char *delta_url) {
    esp_http_client_config_t config = {
        .url = delta_url,
        .event_handler = _http_event_handler,
    };
    esp_http_client_handle_t client = esp_http_client_init(&config);
    esp_err_t err = esp_http_client_perform(client);
    if (err == ESP_OK) {
        ESP_LOGI(TAG, "Delta file downloaded successfully");
        // Apply delta to reconstruct new firmware
        const esp_partition_t *ota_partition = esp_ota_get_next_update_partition(NULL);
        if (bsdiff_apply(delta_file, ota_partition) == 0) {
            ESP_LOGI(TAG, "Delta applied successfully");
            // Verify and reboot
            esp_ota_set_boot_partition(ota_partition);
            esp_restart();
        } else {
            ESP_LOGE(TAG, "Failed to apply delta");
        }
    } else {
        ESP_LOGE(TAG, "Failed to download delta file");
    }
    esp_http_client_cleanup(client);
}

Security Considerations🔗

1. Signed Updates: Use ECDSA to sign delta patches. Reject unsigned/invalid updates.

2. Secure Boot: Ensure only verified firmware boots.

3. EncryptionConnecting 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.: AESNFC Security: Implementing Encryption and Tamper DetectionNFC Security: Implementing Encryption and Tamper DetectionLearn how to secure your ESP32 NFC projects with AES encryption, HMAC validation, and tamper detection techniques for robust wireless security.-128-CTR encrypt delta payloads.

// Verify ECDSA signature before applying update
if (esp_secure_boot_verify_signature(delta_chunk, sig) != ESP_OK) {
    abort_update();
}

Best Practices for Delta Updates🔗

1. Test Thoroughly:

2. Use CompressionSigfox 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.:

3. Monitor 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.:

  • Schedule updates during active periods to avoid draining the battery.

4. Implement Redundancy:

  • Use checksums and retries to ensure data integrity during transmission.

5. Secure the Process:

  • Sign delta files with cryptographic keys to prevent tampering.

Conclusion🔗

Delta updates over NB-IoT cut costs, reduce energy use, and enable rapid fixes for ESP32 devicesPeer-to-Peer NFC Communication Between ESP32 DevicesPeer-to-Peer NFC Communication Between ESP32 DevicesDiscover how to set up NFC P2P communication on ESP32 devices. Our tutorial covers hardware, software integration, and practical security measures. in hard-to-reach locations. By leveraging the dual-partition scheme and optimizing payloads, developers can maintain robust, secure IoT deployments at scale.

Implement this approach in your projects to optimize firmware update cycles, reduce data costs, and maintain a reliable over-the-air updateDual-Partition OTA: Safe Rollback and A/B Testing on ESP32Dual-Partition OTA: Safe Rollback and A/B Testing on ESP32Explore the ESP32 dual-partition OTA update process, ensuring safe rollbacks and effective A/B testing for reliable IoT deployments. process. Happy coding and happy updating!

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