OTA Updates on ESP32: How to Update Firmware Over WiFi
Once your ESP32 device is deployed — in a wall, on a roof, or inside a product enclosure — you do not want to physically connect a USB cable every time you need to update the firmware. OTA (Over-the-Air) updates solve this.
What OTA does
OTA allows you to upload new firmware to your ESP32 over WiFi, without a physical connection. The device downloads the new binary, writes it to a second partition, verifies it, and reboots into the new firmware.
Basic OTA with ArduinoOTA
The simplest approach uses the built-in ArduinoOTA library. Add the following to your setup:
#include <ArduinoOTA.h>
void setup() {
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) delay(500);
ArduinoOTA.setHostname("my-esp32");
ArduinoOTA.setPassword("your-ota-password");
ArduinoOTA.begin();
}
void loop() {
ArduinoOTA.handle(); // Must be called every loop
// ... your code
}HTTP OTA for production
For deployed devices, use HTTP OTA: the device periodically checks a URL for a new firmware version, downloads it, and updates itself. This works without Arduino IDE and is suitable for production deployments.
Important considerations
Always include a rollback mechanism — if the new firmware fails to connect to WiFi, the device should revert to the previous version. Also, never disable OTA in your production firmware, or you will lose remote update capability permanently.
Need ESP32 firmware with OTA support?
I build production-ready firmware with OTA, MQTT, and full documentation. Start a project →