Ugenz Academy/IoT Tutorial

Ota And Firmware Security

12 min read2,223 words

Reading progress

Keep learning

ESP32 OTA and Firmware Security

Now we'll learn one of the most useful features for a real IoT product:

Updating ESP32 firmware without physically connecting a USB cable.

This is called OTA — Over-The-Air Update.


1. What is OTA?

Normally, when you write a program for ESP32:

Computer │ │ USB Cable ▼ ESP32 │ ▼ New Firmware

Every time you change the code, you connect USB and upload again.

With OTA:

Computer / Server │ │ Wi-Fi ▼ ESP32 │ ▼ New Firmware

No USB cable is required after the device has been prepared for OTA.


2. Why OTA is Important

Imagine you install:

100 ESP32 devices

in different locations.

Without OTA:

Visit device 1 → USB update Visit device 2 → USB update Visit device 3 → USB update ... Visit device 100

Very difficult.

With OTA:

OTA Server │ ├── ESP32 #1 ├── ESP32 #2 ├── ESP32 #3 ├── ... └── ESP32 #100

You can update devices remotely.


3. OTA Architecture

Basic architecture:

Wi-Fi │ ▼ ┌─────────────┐ │ ESP32 │ │ │ │ Old Firmware│ └──────┬──────┘ │ │ OTA ▼ New Firmware

The ESP32 receives the new firmware and writes it to the appropriate flash partition.


4. OTA Does NOT Mean USB Is Never Needed

This is important.

A brand-new ESP32 generally needs an initial firmware upload.

Typical process:

First installation Computer │ USB ▼ ESP32 │ OTA-enabled firmware ▼ After that │ Wi-Fi ▼ OTA updates

So OTA is usually used for subsequent updates.


5. OTA with Arduino IDE

Arduino-ESP32 provides OTA functionality.

A common approach is:

#include <ArduinoOTA.h>

Then configure:

ArduinoOTA.begin();

And continuously process OTA:

void loop() { ArduinoOTA.handle(); }

The exact setup depends on how you configure Wi-Fi and your board.


6. Basic OTA Structure

Conceptually:

#include <WiFi.h> #include <ArduinoOTA.h> void setup() { WiFi.begin("YOUR_WIFI", "YOUR_PASSWORD"); while (WiFi.status() != WL_CONNECTED) { delay(500); } ArduinoOTA.begin(); } void loop() { ArduinoOTA.handle(); // Your normal program }

The important part is:

ArduinoOTA.handle();

Your program needs to process OTA requests regularly.


7. OTA Password

You should not allow every device on the network to upload firmware.

You can configure authentication.

Conceptually:

ArduinoOTA.setPassword("YOUR_PASSWORD");

Then an OTA upload requires the configured password.

However, a password alone is not a complete security architecture.


8. OTA Workflow

Suppose your ESP32 currently has:

Version 1.0

You modify the program:

Version 1.1

Then:

Computer │ │ Wi-Fi ▼ ESP32 │ ├── Receive firmware ├── Verify/write ├── Reboot └── Start Version 1.1

9. Firmware

Firmware is the software running on your microcontroller.

For example:

ESP32 Firmware │ ├── Wi-Fi code ├── Sensor code ├── MQTT code ├── Web server ├── Relay control └── Security

OTA replaces/upgrades this firmware.


10. OTA Partitioning

OTA requires suitable flash partitioning.

Conceptually:

ESP32 Flash ┌──────────────────────┐ │ Bootloader │ ├──────────────────────┤ │ Partition Table │ ├──────────────────────┤ │ OTA App Slot A │ ├──────────────────────┤ │ OTA App Slot B │ ├──────────────────────┤ │ Filesystem / Data │ └──────────────────────┘

Why two application slots?

Because the ESP32 can keep the currently working firmware while writing the new firmware into another application partition.


11. OTA A/B Concept

Imagine:

Slot A Version 1.0 │ │ Running ▼ ESP32

New firmware arrives:

Version 1.1 │ ▼ Slot B

Then the bootloader can select the new application after the update.

Conceptually:

Before: [A: v1.0] ← Running [B: empty] After OTA: [A: v1.0] [B: v1.1] ← New

This architecture can make OTA safer than overwriting the only running application.

Exact partition behavior depends on the ESP32 platform and partition configuration.


12. Web OTA

Another useful method is Web OTA.

You create a web page:

ESP32 │ ▼ http://esp32.local │ ▼ ┌─────────────────────────┐ │ ESP32 UPDATE │ │ │ │ Select Firmware │ │ [ Choose File ] │ │ │ │ [ UPDATE ] │ └─────────────────────────┘

You select the compiled firmware file and upload it.

This is very useful for local networks.


13. Web OTA Architecture

Laptop │ │ Browser ▼ ESP32 Web Server │ │ Firmware Upload ▼ OTA Update │ ▼ ESP32 Restart

You could combine:

HTML CSS JavaScript

with:

ESP32 Web Server + LittleFS + OTA

This creates a professional local configuration/update interface.


14. ESP32 Web Dashboard + OTA

Imagine your smart-home project:

┌─────────────────────────────────┐ │ SMART HOME │ ├─────────────────────────────────┤ │ Temperature: 29.5°C │ │ Humidity: 62% │ │ │ │ Light [ ON ] │ │ Fan [ OFF ] │ │ Door [ LOCKED ] │ │ Security [ ARMED ] │ │ │ │ Firmware: v1.4.2 │ │ │ │ [ UPDATE FIRMWARE ] │ └─────────────────────────────────┘

Now the same interface can control the device and manage firmware.


15. OTA Version Numbers

Always give your firmware a version.

For example:

#define FIRMWARE_VERSION "1.2.0"

You can display:

ESP32 Firmware: v1.2.0

A useful version format is:

MAJOR.MINOR.PATCH

Example:

1.4.2

Meaning:

1 → Major 4 → Minor 2 → Patch

16. Remote OTA

For devices deployed remotely:

Developer │ ▼ Firmware Server │ Internet │ ▼ ESP32

The ESP32 can periodically check whether a new firmware version exists.

Example:

ESP32 v1.2 │ │ Check ▼ Server │ │ v1.3 available ▼ ESP32 │ ▼ Download │ ▼ Verify │ ▼ Install │ ▼ Restart

This is the foundation of large-scale IoT firmware management.


17. OTA Security

OTA creates a major security issue:

What happens if an attacker uploads their own firmware?

If unauthorized firmware can be installed:

Attacker │ ▼ ESP32 │ ▼ Malicious Firmware

They could potentially:

  • Change device behavior
  • Steal credentials
  • Control GPIOs
  • Access sensors
  • Join another network
  • Disable security mechanisms

Therefore OTA must be secured.


18. Authentication

At minimum, OTA should require authentication.

User │ ▼ Login / Password │ ▼ OTA Update

Don't expose an unauthenticated firmware-upload endpoint.


19. Encryption

For remote OTA, communication should be protected with encryption such as TLS.

Without encryption:

ESP32 ←──── Firmware ────→ Server

An attacker may attempt to interfere with communication.

With TLS:

ESP32 ║ ║ Encrypted TLS ║ Server

This protects the communication channel.


20. Firmware Signing

Encryption protects communication, but you also want to know:

"Did this firmware actually come from a trusted developer?"

That's where digital signatures and firmware verification come in.

Conceptually:

Developer │ │ Sign Firmware ▼ Signed Firmware │ ▼ ESP32 │ │ Verify ▼ Install

If verification fails:

❌ Firmware rejected

21. Secure Boot

ESP32 devices can support security mechanisms such as Secure Boot, depending on the ESP32 family and configuration.

Conceptually:

Boot ↓ Verify firmware ↓ Valid? ├── YES → Start └── NO → Reject

This helps prevent unauthorized or modified firmware from being executed.


22. Flash Encryption

Another security mechanism available on supported ESP32 platforms is Flash Encryption.

Conceptually:

Normal Flash: Firmware Passwords Configuration

With flash encryption:

Encrypted Flash

This helps protect sensitive data stored in flash if someone obtains physical access to the device.


23. OTA Security Layers

A strong design can use multiple layers:

OTA Security │ ┌──────────┼──────────┐ ▼ ▼ ▼ Authentication TLS Firmware Verification │ ▼ Secure Boot │ ▼ Flash Encryption

Not every project requires every mechanism, but production IoT devices should use an appropriate security architecture.


24. OTA Failure

What if the firmware update fails?

For example:

Old Firmware ↓ OTA Update ↓ Power Failure ↓ Incomplete Update

A robust OTA architecture should be designed so the device can recover rather than becoming permanently unusable.

This is where rollback becomes important.


25. OTA Rollback

Conceptually:

v1.0 → Working ↓ v1.1 → Update ↓ Crash / Failure ↓ Rollback ↓ v1.0

The exact rollback mechanism depends on the ESP32 framework, bootloader, partition setup, and OTA implementation.


26. Safe OTA Architecture

A production-style design looks like:

Firmware Server │ ▼ HTTPS / TLS │ ▼ ESP32 │ ┌─────┴─────┐ │ │ Download Verify │ │ └─────┬─────┘ ▼ New Image │ ▼ Bootloader │ ┌─────┴─────┐ ▼ ▼ Valid Invalid │ │ ▼ ▼ Start Reject/Rollback

27. OTA + MQTT

You can combine MQTT with OTA.

For example:

MQTT Broker │ │ update available ▼ ESP32 │ ▼ Firmware Server │ ▼ Download Firmware

MQTT can act as a notification/control channel, while the actual firmware may be downloaded over HTTPS.


28. OTA + Firebase

You could also use your Firebase-based system.

Next.js Dashboard │ ▼ Firebase │ ▼ Device Management │ ▼ ESP32 │ ▼ OTA Server

Your dashboard could display:

Device: ESP32-001 Version: 1.3.0 Status: Online New Version: 1.4.0 [ UPDATE ]

29. OTA for Your Smart Home

Imagine your project has:

ESP32 Smart Home │ ├── PIR ├── LDR ├── DHT22 ├── Ultrasonic ├── RFID ├── Relay ├── Servo ├── LCD └── Web Dashboard

After installation:

ESP32 installed on wall

Later you discover:

"The door-control logic has a bug."

Without OTA:

Remove ESP32 ↓ Connect USB ↓ Upload ↓ Install again

With OTA:

Laptop ↓ Wi-Fi ESP32 ↓ Firmware v2.0 ↓ Restart

Much easier.


30. OTA + Version Control

Since you use Git/GitHub, your development workflow can be:

Code ↓ Git ↓ Test ↓ Build Firmware ↓ Release v1.2.0 ↓ OTA Server ↓ ESP32

For multiple devices:

Firmware v1.2 │ ┌─────────┼─────────┐ ▼ ▼ ▼ ESP32-1 ESP32-2 ESP32-3

31. OTA and LittleFS

Remember the previous topic?

We learned:

LittleFS ├── index.html ├── style.css └── config.json

Now combine it with OTA:

ESP32 │ ├── Firmware │ └── OTA update │ └── LittleFS ├── HTML ├── CSS ├── JS └── Config

You can update firmware separately from filesystem content, depending on your update architecture and partition setup.


32. OTA vs Web File Update

Don't confuse:

Web file update

index.html style.css script.js

with:

Firmware update

ESP32 program

They are different things.

ESP32 Flash │ ├── Firmware │ └── Filesystem ├── HTML ├── CSS └── JS

33. Common OTA Mistakes

❌ 1. OTA code isn't running continuously

If you forget:

ArduinoOTA.handle();

or the equivalent processing required by your OTA method, updates may not work correctly.


❌ 2. ESP32 isn't connected to Wi-Fi

OTA generally requires network connectivity.


❌ 3. Wrong partition scheme

Insufficient OTA application space can prevent updates.


❌ 4. No authentication

Never create an unrestricted firmware upload endpoint.


❌ 5. No rollback/recovery strategy

A failed update can make remote devices difficult to recover.


❌ 6. Hardcoded secrets

Don't put production credentials into public GitHub repositories.


❌ 7. Unencrypted remote firmware transfer

For Internet-facing deployments, use an appropriately secured transport such as HTTPS/TLS.


34. Development vs Production

Development

You might use:

Arduino IDE ↓ USB ↓ ESP32

then:

Arduino IDE ↓ Wi-Fi OTA ↓ ESP32

Production

A stronger architecture:

Developer ↓ CI/CD ↓ Signed Firmware ↓ Secure Firmware Server ↓ TLS ↓ ESP32 ↓ Verify ↓ Install

35. Professional IoT Update System

For many devices:

Developer │ ▼ GitHub │ ▼ Build System │ ▼ Firmware Release │ ▼ Secure OTA Server │ ┌─────────┼─────────┐ ▼ ▼ ▼ ESP32-1 ESP32-2 ESP32-3

Each device can report:

Device ID Firmware Version IP Wi-Fi status Uptime Battery

This becomes a real device-management system.


🧠 Quick Summary

Remember:

OTA ↓ Over-The-Air firmware update

Normal:

PC ──USB──> ESP32

OTA:

PC/Server ──Wi-Fi/Internet──> ESP32

For production security:

Authentication + TLS + Firmware Verification + Secure Boot + Flash Encryption + Rollback/Recovery

And the professional IoT lifecycle becomes:

Develop ↓ Test ↓ Build ↓ Sign ↓ Release ↓ OTA ↓ Verify ↓ Monitor

🚀 Next Topic

📷 ESP32-CAM and Streaming

Next we'll explore the ESP32-CAM, including:

  • ESP32-CAM board
  • Camera module
  • OV2640
  • Camera pins
  • Capturing images
  • Web camera server
  • Live video streaming
  • Photo capture
  • SD card
  • Web-controlled camera
  • Face detection concepts
  • Smart security camera
  • ESP32-CAM + IoT
  • ESP32-CAM + PIR
  • ESP32-CAM + Firebase/cloud architecture

Keep learning. Keep building. Keep growing.

© 2026 Ugenz Academy