ElegantOTA: firmware updates from a browser page
ElegantOTA, by Ayush Sharma, adds an /update page to a web server already running on an ESP32, ESP8266 or Pico W. Open it in a browser on the same network, pick the compiled .bin file, and the board flashes itself and restarts. Nothing is needed on the computer beyond a browser, which makes it handy for boards mounted where a USB cable cannot reach.
Built in on Mokxi: #include <ElegantOTA.h> and it builds, with nothing to install. Free, and no account needed.
What ElegantOTA does
Version 3 is a single global object. You pass it your server with ElegantOTA.begin(&server), call ElegantOTA.loop() in loop() so it can finish the update and reboot, and optionally attach onStart(), onProgress() and onEnd() to log or show progress. setAuth() puts a user name and password on the page. It works with the core WebServer or with ESPAsyncWebServer, chosen at compile time.
In Mokxi the library compiles and the Demo example runs: the root page answers in the Web panel and /update answers too, but over-the-air updates are not simulated. The page says so, nothing is uploaded or flashed, and the callbacks never run. To try new code, press Run to load a new build.
| Library Manager name | ElegantOTA |
|---|---|
| Author | Ayush Sharma |
| Include | #include <ElegantOTA.h> |
| Boards | ESP32-C3, ESP32-C6, Seeed XIAO ESP32-C3, ESP32-C3 SuperMini, Seeed XIAO ESP32-C6, ESP32 DevKit, ESP32-DevKitC V4, LOLIN32 Lite, Wemos D1 R32, Cheap Yellow Display, TTGO T-Display, ESP32-S3-DevKitC-1, Seeed XIAO ESP32-S3, Arduino Nano ESP32, ESP8266 NodeMCU, Raspberry Pi Pico W |
| In the simulator | Builds and runs, and says plainly that the hardware behind it is not simulated. |
Install it
It builds on ESP32-C3, ESP32-C6, Seeed XIAO ESP32-C3, ESP32-C3 SuperMini, Seeed XIAO ESP32-C6, ESP32 DevKit, ESP32-DevKitC V4, LOLIN32 Lite, Wemos D1 R32, Cheap Yellow Display, TTGO T-Display, ESP32-S3-DevKitC-1, Seeed XIAO ESP32-S3, Arduino Nano ESP32, ESP8266 NodeMCU, Raspberry Pi Pico W.
In Mokxi it is built in: #include <ElegantOTA.h> and the sketch compiles, with no download, no zip and no Library Manager.
On a real board, install "ElegantOTA" by Ayush Sharma from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add ElegantOTA to lib_deps in PlatformIO. Mokxi follows the calls of release 4.0.0, so a sketch written here builds there too.
What to know in the simulator: Over-the-air updates are not simulated: the /update page says so, nothing is uploaded or flashed, and the callbacks never run (press Run to load a new build). 4.0 kept 3.x’s calls; /ota/metadata answers with zero-sized partitions. The AsyncWebServer form needs ESPAsyncWebServer.h first or ELEGANTOTA_USE_ASYNC_WEBSERVER 1.
The calls you will use
In the order a sketch meets them.
ElegantOTA.begin(&server)
Adds the /update page and its upload handler to your WebServer or AsyncWebServer. Call it after your own server.on() routes.
ElegantOTA.loop()
Finishes a pending update and reboots when it is due. Call it on every pass of loop(), after server.handleClient() if you use the core server.
ElegantOTA.onStart(otaStarted)
Registers a function run when an upload begins, a good place to switch off motors or close files.
ElegantOTA.onProgress(otaProgress)
Registers a function given the bytes written so far and the total, for a progress line on Serial.
ElegantOTA.onProgress([](size_t current, size_t final) {
Serial.printf("%u of %u bytes\n", current, final);
});ElegantOTA.onEnd(otaEnded)
Registers a function given true when the update succeeded and false when it failed.
ElegantOTA.setAuth("admin", "secret")
Asks for a user name and password before the update page opens. Without it anyone on the network can flash the board.
ElegantOTA.setAutoReboot(false)
Stops the automatic restart after a successful update, so your own code can decide when to reboot.
Example: A web server with an /update page beside it
On the ESP32-C3-DevKitM-1. It runs in the browser exactly as printed.
// After the library's Demo example.
#if defined(ESP8266)
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
ESP8266WebServer server(80);
#else
#include <WiFi.h>
#include <WebServer.h>
WebServer server(80);
#endif
#include <ElegantOTA.h>
void setup() {
Serial.begin(115200);
WiFi.begin("Mokxi-Lab", "breadboard");
while (WiFi.status() != WL_CONNECTED) delay(250);
server.on("/", []() {
server.send(200, "text/plain", "Hi! This is ElegantOTA Demo.");
});
ElegantOTA.begin(&server);
ElegantOTA.onStart([]() { Serial.println("OTA update started!"); });
ElegantOTA.onProgress([](size_t current, size_t final) {
Serial.printf("OTA progress: %u of %u bytes\n", (unsigned)current, (unsigned)final);
});
ElegantOTA.onEnd([](bool success) { Serial.println(success ? "OTA update finished" : "OTA update failed"); });
server.begin();
Serial.print("HTTP server started: http://");
Serial.print(WiFi.localIP());
Serial.println("/update");
}
void loop() {
server.handleClient();
ElegantOTA.loop();
}Common errors and how to fix them
no matching function for call to 'begin(AsyncWebServer*)'
ElegantOTA 3 builds for the core WebServer unless told otherwise. Include ESPAsyncWebServer.h before ElegantOTA.h, or set ELEGANTOTA_USE_ASYNC_WEBSERVER to 1 in the library’s header or as a build flag, then rebuild.
The upload reaches 100% but the board never restarts
In version 3 the reboot happens inside ElegantOTA.loop(). Add it to loop() and keep loop() free of long delay() calls, or the board waits forever with the new firmware unused.
Upload fails at once with "Not enough space"
The partition scheme has no room for a second copy of the firmware. Choose a scheme with OTA in the board menu, such as the default with two app partitions, and upload once over USB to apply it.
Questions and answers
ElegantOTA or ArduinoOTA?
ArduinoOTA pushes a build from the Arduino IDE or PlatformIO over the network. ElegantOTA lets anyone with a browser upload a .bin file, with no IDE. Many projects use one or the other, and some use both.
Try ElegantOTA without installing anything
Open the example, change the sketch, and keep your version in a free account.