DIY Projects

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

arduinoota 2 esp8266 wifi update wireless arduino code

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

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

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

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:

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

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.

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.


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

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

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]
Exit mobile version