ClavdaClavda

Update ESP32 firmware over the air with PlatformIO

Build a PlatformIO ESP-IDF project, upload its firmware.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

PlatformIO uploads over USB, or over the local network at best. With the ClavdaOTA library in your firmware, the board downloads updates through Clavda instead, so you can update it from anywhere it has Wi-Fi, behind any router.

What you need

  • An ESP32 already connected to Clavda with PlatformIO 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 src/main.c or src/main.cpp 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

Press Build in the PlatformIO toolbar, or run pio run. The file to upload is .pio/build/<env>/firmware.bin, .pio/build/esp32s3/firmware.bin for the [env:esp32s3] of setup: not bootloader.bin or partitions.bin.

Built with the ESP-IDF extension for VS Code or idf.py build instead, the file is build/<project>.bin, named after project() in the root CMakeLists.txt.

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 src/main.c, and register them in app_main(), before clavda_begin():

src/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 of setup. The build prints how much flash the image takes.
  • Turn on app rollback: add CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y to sdkconfig.defaults and delete sdkconfig.<env>, or turn on Enable app rollback support under Bootloader config in pio run -t menuconfig. 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