AsyncOTA is a library that allows you to update your ESP32 firmware over-the-air (OTA) using the AsyncTCP / ESPAsyncWebServer library.
- Supports firmware updates over-the-air (OTA)
- Uses AsyncTCP / ESPAsyncWebServer for ESP32
Install frontend dependencies:
yarn && yarn build[env:esp32]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200
lib_deps =
circuitcode/AsyncOTA#include <AsyncOTA.h>AsyncWebServer server(80);void setup() {
AsyncOTA.begin(&server);
server.begin();
}
void loop() {
AsyncOTA.loop();
}Create a custom middleware function to add CORS headers to the response.
AsyncMiddlewareFunction cors([](AsyncWebServerRequest *request, ArMiddlewareNext next) {
next();
String origin = request->header("Origin");
if (origin.length() > 0) {
request->getResponse()->addHeader("Access-Control-Allow-Origin", origin);
} else {
request->getResponse()->addHeader("Access-Control-Allow-Origin", "*");
}
request->getResponse()->addHeader("Access-Control-Allow-Methods", "*");
request->getResponse()->addHeader("Access-Control-Allow-Headers", "*");
request->getResponse()->addHeader("Access-Control-Allow-Credentials", "true");
});
Then add the middleware before starting the server.
server.addMiddleware(&cors);The library will manage automatically the CORS preflight request.
Initialize the library with a username and password.
AsyncOTA.begin(&server, "username", "password");Set a custom hardware ID for the firmware update page.
AsyncOTA.setID("my-device");Navigate to http://<device-ip>/update to access the firmware update page.
This project is licensed under the MIT License - see the LICENSE file for details.