ArduinoOTA: Wireless Update (OTA) from the Arduino IDE of ESP8266 Programs

Table of Contents
drapeau france
level advanced

The ArduinoOTA library is a library that allows to update the Arduino program (and ESP3226, ESP32) wirelessly in Wi-Fi. It is an essential library when developing connected objects. It allows to update the program without having to disassemble the microcontroller (Arduino, ESP8266, ESP32) to connect it to his computer. This library was originally developed to update the Arduino programs, it is perfectly supported by the ESP8266 and ESP32. For this tutorial, we will only address the case of ESP8266.

Install the ArduinoOTA library for ESP8266 on the Arduino IDE

The ArduinoOTA library is integrated into the ESP8266 library. There is nothing more to install. If you’re new to ESP, here’s how to install the ESP library and support. Open the preferences (from the Arduino menu) and add to the list of packages this one

IDE Arduino 1.6.8 esp8266 package

Then go to the board manager and look for esp8266, then click install.

IDE Arduino 1.6.x ajouter carte esp8266

After installation, new examples have been added to the sample menu. Select your ESP8266 board to display the available samples. Open the BasicOTA example in the ArduinoOTA submenu

arduinoota 0 basicota example

This program contains everything you need to manage wireless upgrade in your ESP projects.

#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>

const char* ssid = "..........";
const char* password = "..........";

void setup() {
  WiFi.begin(ssid, password);
  while (WiFi.waitForConnectResult() != WL_CONNECTED) {
    Serial.println("Connection Failed! Rebooting...");

  // Port defaults to 8266
  // ArduinoOTA.setPort(8266);

  // Hostname defaults to esp8266-[ChipID]
  ArduinoOTA.setHostname("Demo OTA ESP8266");

  // No authentication by default
  ArduinoOTA.setPassword((const char *)"123");

  ArduinoOTA.onStart([]() {
  ArduinoOTA.onEnd([]() {
  ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
    Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
  ArduinoOTA.onError([](ota_error_t error) {
    Serial.printf("Error[%u]: ", error);
    if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
    else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
    else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
    else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
    else if (error == OTA_END_ERROR) Serial.println("End Failed");
  Serial.print("IP address: ");

void loop() {

Before reversing the program, change the ssid variables (Wi-Fi network to which to connect) and password (password).

Here, the program uses the ESP8266WiFi library to connect to the network. You can also use the WiFiManager library presented earlier.

Once the connection is established, it is possible to define additional (optional) parameters:

  • SetPort: by default the communication port is 8266. It is not very useful to change it unless it is already in use. For example, for a project integrating UDP communication.
  • SetHostname: This is probably the most important option. It allows you to assign a name to the ESP8266. If you have a lot of objects on your network, it will be much easier to identify it by name than by an identifier built automatically from the serial number.
  • SetPassword: used to request a password from the Arduino IDE before running an update. Practice if you work at several or in a school.

There are four other ways to connect treatments in the following cases:

  • OnStart: code to run when the update is started
  • OnEnd: idem at the end
  • OnProgress: during the progress
  • OnError: and on error

You will not need to add treatments in most cases. In particular, these functions allow us to remain informed of the smooth running of operations.

At the end of the setup, once all functions have been defined, start the wireless update support by calling the begin () method.

Finally, for everything to work, it is necessary to call the ArduinoOTA.handle () method in the loop () loop.

Wireless Update Test

Upload the program and open the Terminal to verify that the ESP8266 is properly connected to the Wi-Fi network.

arduinoota 1 ide arduino ip address

The Arduino IDE automatically detects devices that support remote update. They are added to the list of ports in a new section called Network ports.

arduinoota 2 esp8266 wifi update wireless arduino code


It seems that version 1.8.x includes a bug that prevents the devices from updating. If your ESP does not appear a few seconds after starting the ESP, just restart the Arduino IDE.

To update the program, simply select the ESP as the port instead of the usual serial port. Then upload the program as usual. Here, as a password is required, an input window appears in the IDE. It is requested only once

arduinoota 5 saisie mot de passe type password ide arduino

The remote update (or failure) of the remote update can be tracked directly from the Arduino IDE.

arduinoota 4 ide arduino done uploading

It is not possible to open the serial monitor with wireless setup. A small Web interface is required. Read this tutorial to learn how to add a Web server and HTML interface to an ESP8266 project. To go further, here is a series of articles dealing with the subject

Click to rate this post!
[Total: 0 Average: 0]

Thanks for your reading

Did you like this project ? Don't miss any more projects by subscribing to our weekly newsletter!

Are you having a problem with this topic?

Maybe someone has already found the solution, visit the forum before asking your question
1 Comment
  1. It is known long-lasting bug that Arduino IDE should be restarted to see the network devices which recently came online (it was present in 1.6.x and I guess in earlier versions as well).
    It’s a pity it is still not fixed in 1.8.x 🙁

Leave a Reply

Read more
DIY Projects
DIY Projects
%d bloggers like this: