ESP32 Over-The-Air (OTA) Download Solutions Practical Guide

ESP32 Over-The-Air (OTA) Download Solutions Practical Guide

Introduction

OTA (Over-the-Air Technology) refers to the technology that enables remote management of mobile terminal devices and SIM card data through the air interface of mobile communications. OTA upgrades are a crucial part of the Internet of Things (IoT) product design, enabling smart devices to fix system vulnerabilities and upgrade systems, providing better services through firmware and software updates. The OTA firmware upgrade function can not only update the firmware but also reconfigure hardware resources on the chip. Meanwhile, device firmware can obtain updated patches and more security algorithms through the OTA firmware upgrade process to prevent virus attacks.

Using the ESP32 microcontroller from Espressif Systems, which supports Bluetooth and Wi-Fi, along with related modules, kits, and the ESP IoT Development Framework (ESP-IDF), this guide demonstrates how to create an OTA partition and use the otatool.py script to perform firmware updates while the application is still running.

PART01

How to Achieve OTA Updates?

The IoT products need to be deployed, configured, and maintained throughout the lifecycle of the device. An important but often overlooked feature is the bootloader or firmware OTA (FOTA) updates (sometimes simply referred to as OTA). This technology allows companies to avoid sending maintenance personnel on-site or requiring end customers to manually update devices. Instead, all these costs can be eliminated by allowing devices to upgrade firmware in the background or during idle times.

OTA architectures can take many different forms and configurations, ranging from custom solutions to standard implementations provided by cloud providers.

ESP32 Over-The-Air (OTA) Download Solutions Practical Guide

The ESP32 integrates dual-mode 2.4GHz Wi-Fi and Bluetooth, offering ultra-high RF performance, stability, versatility, and reliability, along with ultra-low power consumption to meet various power consumption requirements, making it suitable for a wide range of IoT application scenarios and favored by low-cost systems and manufacturers.

Next, using the ESP32 microcontroller from Espressif Technology, along with related modules, kits, and the ESP IoT Development Framework (ESP-IDF), we will demonstrate how to create an OTA partition and use the otatool.py script to perform firmware updates while the application is still running.

ESP32 Over-The-Air (OTA) Download Solutions Practical Guide

PART02

OTA Upgrade Testing with ESP32 Modules

There are several different ESP32 modules and development boards available for users to purchase. Taking the Adafruit 3405 ESP32 Huzzah Feather board as an example (Figure 2). This is a low-cost development board that includes all the circuitry needed to program the ESP32 and is powered via a USB connector.

ESP32 Over-The-Air (OTA) Download Solutions Practical Guide

Figure 2: The 3405 Huzzah Feather board includes an ESP32 WROOM-32D certified Wi-Fi/Bluetooth module, with 4Mb of flash memory. This board includes all necessary hardware for USB programming and communication with the module.

The core of the 3405 is an ESP32-WROOM-32D module, equipped with 4Mb flash memory, Wi-Fi, Bluetooth, and a complete set of peripherals, suitable for almost any application.

Another board available for use is the ESP32-LYRATD-SYNA audio board from Espressif Systems (Figure 3). This development board includes the ESP32-WROVER-B module.

ESP32 Over-The-Air (OTA) Download Solutions Practical Guide

Figure 3: The ESP32-LYRATD-SYNA board is based on the ESP32 WROVER-B certified Wi-Fi/Bluetooth module, with 4Mb of flash memory. In addition to allowing designers to program via USB and communicate with the module, it also has the circuitry necessary for developing audio applications.

The ESP32-LYRATD-SYNA module also has 4Mb of flash memory, along with all the circuitry needed for audio applications. The board includes an audio codec, an audio amplifier, and headphone and speaker jacks for comprehensive testing of audio applications.

The last board available for OTA testing is the ESP32-S2-SAOLA-1RI development board from Espressif (Figure 4). When it comes to development boards, this one is the least expensive. It includes an ESP32 Wrover module and the circuitry to program the chip. Besides the pins included, which can be easily put on a breadboard for testing, there are no other embellishments.

ESP32 Over-The-Air (OTA) Download Solutions Practical Guide

Figure 4: The ESP32-S2-SAOLA-1RI based on the Wrover module is a bare development board, low-cost but includes sufficient circuitry to program the onboard module.

All three development boards are selectable, as each ESP32 module utilizes the ESP-IDF. This framework is designed to simplify software development for developers by including drivers, middleware, RTOS, and the bootloader and OTA libraries, which are crucial for this article.

The bootloader allows developers to utilize OTA updates and partition memory to update firmware while the main application is still running, helping to minimize downtime.

ESP32 Over-The-Air (OTA) Download Solutions Practical Guide

PART03

ESP32 OTA Development Process

The OTA development workflow for the ESP32 will vary slightly based on business needs and product component selection. For example, a team utilizing AWS may use AWS’s getting started documentation to launch their ESP32 OTA solution. A company customizing its own solution may also utilize the ESP32 documentation. Regardless of which cloud provider or solution is used, the process for setting up OTA updates on the ESP32 generally includes the following steps:

1. Configure the ESP32 partition table

2. Download firmware that supports OTA

3. Develop a tool that acts as a server to push new firmware

4. Download the latest firmware to the ESP32

5. Switch to the new application

The above is a simplified approach; developers should refer back to Figure 1 for the entire firmware update process. This process can be quite complex, so it is recommended to utilize existing ESP32 OTA examples found on GitHub, such as:

1. HTTPS OTA

2. Local OTA

3. Simple OTA

4. OTA Tool (Python script example)

Figure 5 shows the steps of the deployment and update process. Developers need to first execute the red steps to deploy the OTA solution on the ESP32 module, followed by the orange steps to advance the OTA update.

ESP32 Over-The-Air (OTA) Download Solutions Practical Guide

Figure 5: The Espressif Systems OTA update examples located on GitHub provide developers with several simple examples to enable their ESP32 to perform OTA updates.

ESP32 Over-The-Air (OTA) Download Solutions Practical Guide

PART04

Configuring ESP32 Applications for OTA

The ESP32 includes a partition table that describes where data is located on the microcontroller and its position. For example, a standard ESP32 partition table looks like Table 1.

ESP32 Over-The-Air (OTA) Download Solutions Practical Guide

Table 1: The standard ESP32 partition table shows the types of data and their locations on the microcontroller. (Table source: Beningo Embedded)

For example, there is a factory application that includes the NVS library and physical layer (PHY) initialization (init) data section. To utilize the OTA functionality, this table needs to be updated to specify memory locations for OTA firmware updates in addition to the main (factory) application. For OTA, two partitions are typically allocated for updates: one for the firmware being updated and one for the firmware being downloaded. This allows the factory application to remain unchanged. Table 2 shows the updated OTA partition table.

ESP32 Over-The-Air (OTA) Download Solutions Practical Guide

Table 2: A typical ESP32 updated OTA partition table. (Table source: Beningo Embedded)

As shown in the table, there are now ota_0 and ota_1 application sections, each sized at 1Mb, as well as a data section (otadata) allocated for the update process. This table can be modified and updated by developers to fit their applications.

To run the OTA example, there are simple instructions listed in the “How to Use the Examples” section on GitHub. This section describes how to build and program the application.

There is also the otatool, which can be used to update firmware. This script is typically used to read, write, and erase OTA partitions, switch boot partitions, and switch to the factory partition.

The example script can be executed by running the example in the terminal using the command.

./otatool_example.sh

Or using Python.

python otatool_example.py

When it comes to configuring the ESP32 for OTA, ensuring the partition settings are correct is a key step.

ESP32 Over-The-Air (OTA) Download Solutions Practical Guide

PART05

ESP32 OTA Development Tips

PART05

The ESP32 OTA solution can accelerate and simplify developers’ firmware update solutions. To prevent the solution from becoming a development burden, here are several tips and tricks:

1. If possible, leverage existing OTA frameworks provided by the company’s cloud provider. This can greatly simplify development and integration.

2. Use low-cost development boards to test OTA functionality and bootloaders. The ESP32 has several options, which may require some experimentation to determine which is best suited for the application at hand.

3. For custom solutions, utilize the ESP32 OTA examples available on GitHub.

4. For products functioning as Wi-Fi routers or hubs, consider downloading firmware images to external storage and executing updates from high-capacity storage devices.

5. Spend some time reviewing the ESP32 documentation regarding partition tables. This is somewhat different from typical microcontroller implementations.

6. For security reasons, it is best to disable application rollbacks. If an application can roll back to a previous version, potential attackers could push a version with known vulnerabilities, compromising the system.

Developers who follow these “tips and tricks” will find that they can save a lot of time and avoid struggles when trying to leverage the ESP32 or any other OTA solution.

The ESP32 wireless microcontroller has been widely used in various types of devices, as mentioned above, it has a ready-made OTA solution. By leveraging the ESP-IDF and related modules and platforms, developers can significantly reduce design time and complete OTA solutions to run reliably.

ESP32 Over-The-Air (OTA) Download Solutions Practical Guide

Recommendations Based on Domestic Chip Solutions

1. RK3588 High-Performance Visual Processing Mainboard

ESP32 Over-The-Air (OTA) Download Solutions Practical Guide

Application Scenarios: Widely used in VR, industrial control, power, communications, medical, media, security, automotive, finance, consumer electronics, handheld devices, game consoles, display control, teaching instruments, POS machines, game consoles, teaching experimental platforms, multimedia terminals, PDAs, ordering machines, advertising machines, etc.

Price: 1469

View Solution Details>>

2. RK3566 8K HD Display Visual Processing Development Board

ESP32 Over-The-Air (OTA) Download Solutions Practical Guide

Application Scenarios: Widely used in ARM PCs, high-end tablets, edge computing servers, virtual reality, NVR, 8K televisions, etc.

Price: 299

View Solution Details>>

3. RV1126 High-Performance Face Recognition Core Board

ESP32 Over-The-Air (OTA) Download Solutions Practical Guide

Application Scenarios: Widely used in smart locks, smart doorbells, network cameras, dash cams, game interaction, live broadcasting, conference projection, etc.

Price: 340

View Solution Details>>

4. RK3566 Cost-Effective Android Video Mainboard

ESP32 Over-The-Air (OTA) Download Solutions Practical Guide

Application Scenarios: The best choice for cash registers, advertising machines, self-service terminals, and other industries.

Price: 340

View Solution Details>>

ESP32 Over-The-Air (OTA) Download Solutions Practical Guide
ESP32 Over-The-Air (OTA) Download Solutions Practical Guide

Leave a Comment