Quick Start Guide: Connect Your ESP32 to OtaHub

Quick Start Guide: Connect Your ESP32 to OtaHub

Connect Your ESP32 Device to OtaHub

This guide walks you through connecting an ESP32 device to OtaHub and enabling secure over-the-air firmware updates using the official Arduino library.

The OtaHub Arduino library manages the complete update process:

  • Secure device authentication
  • Device provisioning
  • Firmware version checking
  • OTA firmware downloading
  • Flash partition updates
  • Automatic restart after successful updates

Install the OtaHub Arduino Library

The OtaHub Arduino library is open source and available on GitHub:

https://github.com/c-gayan/OtaHub

You can view the source code, report issues, or contribute to the project.

Method 1 (Recommended)

Install via Arduino Library Manager

The easiest way to install the library is through the Arduino IDE Library Manager.

  1. Open Arduino IDE.
  2. Go to:
Sketch → Include Library → Manage Libraries...
  1. Search for:
OtaHub
  1. Find the official library by c-gayan.
  2. Click Install and select the latest version.

Method 2

Manual ZIP Installation

You can also install the library manually:

  1. Open the OtaHub GitHub repository.
  2. Go to the latest release page.
  3. Download the latest release ZIP file from the Assets section.
  4. Open Arduino IDE.
  5. Go to:
Sketch → Include Library → Add .ZIP Library...
  1. Select the downloaded ZIP file.

Library Usage

Include the OtaHub header:

#include <otahub.h>

Create an OtaHub object:

OtaHub otaHub;

The library handles OTA communication separately and allows your main ESP32 application to continue running without interruption.

API Reference

begin()

void begin(
    String apiKey,
    String currentVersion,
    unsigned int checkIntervalMinutes = 1
)

Initializes the OtaHub client.

When checkIntervalMinutes is greater than 0, the library creates a FreeRTOS background task:

  • Task name: OTA_Task
  • Core: ESP32 Core 0
  • Stack size: 8KB
  • Priority: 0

Your main application continues running normally on Core 1.

To disable automatic background checks, pass 0.

checkForUpdates()

void checkForUpdates()

Manually checks the OtaHub API server for firmware updates.

If a newer firmware version is available in the active deployment stage, the library downloads the firmware, writes it to the flash partition, and automatically restarts the ESP32.

Automatic Updates

The recommended method is using background update checks.

The ESP32 application continues running while OtaHub checks for new firmware periodically.

#include <WiFi.h>
#include <otahub.h>

const char* ssid = "YOUR_WIFI_SSID";
const char* password = "YOUR_WIFI_PASSWORD";

String apiKey = "YOUR_API_KEY";

// IMPORTANT:
// This version must exactly match the version uploaded to OtaHub.
// Example:
// Uploaded firmware version: 1.0.1
// currentVersion must also be: 1.0.1

String currentVersion = "1.0.0";

OtaHub otaHub;

void setup() {
  Serial.begin(115200);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting...");
  }

  // Check for updates every 60 minutes
  otaHub.begin(apiKey, currentVersion, 60);
}

void loop() {

  // Your main application runs normally
  delay(1000);

}

Manual Updates

For applications that require full control, disable the background task and manually call update checks.

#include <WiFi.h>
#include <otahub.h>

const char* ssid = "YOUR_WIFI_SSID";
const char* password = "YOUR_WIFI_PASSWORD";

String apiKey = "YOUR_API_KEY";

String currentVersion = "1.0.0";

OtaHub otaHub;

unsigned long lastCheck = 0;
const unsigned long interval = 3600000; // 60 minutes

void setup() {

  Serial.begin(115200);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting...");
  }

  // Disable background checking
  otaHub.begin(apiKey, currentVersion, 0);

  // Initial update check
  otaHub.checkForUpdates();

}

void loop() {

  if (millis() - lastCheck >= interval) {

    lastCheck = millis();

    if (WiFi.status() == WL_CONNECTED) {
      otaHub.checkForUpdates();
    }

  }

}

Version Management

The firmware version in your ESP32 code must exactly match the firmware version uploaded to OtaHub.

Example:

Uploaded Firmware Version ESP32 currentVersion
1.0.0 1.0.0
1.0.1 1.0.1
2.0.0 2.0.0

Incorrect version matching can cause repeated update attempts.

Next Steps

After connecting your ESP32 device:

  1. Upload your firmware to OtaHub.
  2. Create a firmware release.
  3. Assign the release to a deployment stage.
  4. Connect your device using the OtaHub library.
  5. Monitor and manage updates from the dashboard.

For more information, visit the full documentation.