ClavdaClavda

Update ESP32 firmware over the air with ESP-IDF

Build an ESP-IDF project, upload its .bin in Clavda, and the ESP32 installs it from anywhere, without a USB cable, with app rollback if the new build fails. In C or C++.

Updated 2 min read

ESP-IDF's OTA APIs install an image, but something has to fetch it. With the ClavdaOTA component in your firmware, the board downloads updates through Clavda, so you can update it from anywhere it has Wi-Fi, behind any router.

What you need

  • An ESP32 already connected to Clavda with ESP-IDF and showing green under Devices.
  • The partitions.csv from setup, with two app slots, flashed once over USB. Without them there is no room to install an update.

Install an update

Give the build a new version

Change CLAVDA_FIRMWARE_VERSION at the top of your source file for every build you upload, from "1.0.0" to "1.0.1", say. It is the same line in C and C++:

#define CLAVDA_FIRMWARE_VERSION "1.0.1"

Clavda counts an update as done only when the board reconnects reporting the new version, so a build with an unchanged version never shows as installed.

Build the firmware binary

Run idf.py build. The file to upload is build/<project>.bin, named after the project() in the top-level CMakeLists.txt: build/clavda_app.bin for a project made with idf.py create-project clavda_app. Not bootloader.bin or partition-table.bin.

Upload it in Clavda

Open the device's Connect sheet, upload the .bin, and press Update now.

Let the board install it

The board downloads the new firmware, checks it, and restarts into it. Once it reconnects reporting the new version, the update shows as done.

Version strings

Start with a letter or digit and use up to 31 letters, digits, dots, underscores, plus signs or hyphens: 1.0.1, 2026.10.15 and v2-beta all work.

Follow an update from your code

The library can tell your firmware when an update arrives, how far the download is, and how it ended. Return false from the request callback to put an update off, while a motor is running, say: the console then shows the job as deferred rather than failed.

Add the callbacks to your source file, and register them in app_main(), before clavda_begin():

main/main.c
static bool onUpdateRequest(const ClavdaUpdateRequest *request, void *user) {
  printf("Update %s offered, %u bytes\n", request->version, (unsigned)request->size);
  return true;  // false puts it off
}

static void onStart(void *user) {
  printf("Update started\n");
}

static void onProgress(size_t current, size_t total, void *user) {
  printf("%u of %u bytes\n", (unsigned)current, (unsigned)total);
}

static void onEnd(bool success, void *user) {
  printf("%s\n", success ? "Update written, restarting" : "Update failed");
}

// In app_main():
//   clavda_on_update_request(onUpdateRequest, NULL);
//   clavda_on_update_start(onStart, NULL);
//   clavda_on_update_progress(onProgress, NULL);
//   clavda_on_update_end(onEnd, NULL);

Keep updates reliable

  • Call the library's loop on every pass through the app_main() loop, clavda_loop() in C or ClavdaOTA.loop() in C++, with a short vTaskDelay() between passes. Updates install from there.
  • Keep your firmware small enough for one app slot: 1.9 MB with the partitions.csv above. idf.py build prints how much of the slot the image takes.
  • Turn on app rollback: Enable app rollback support (CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE) under Bootloader config in idf.py menuconfig. In a project with no sdkconfig yet, the line CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y in sdkconfig.defaults does the same. A new build then counts as trial firmware: the library confirms it once it reaches Clavda, and if it never gets that far, the board goes back to the previous firmware on its next restart. This only changes the bootloader, so it takes one more flash over USB.

Next steps