DIY Projects

ArduinoOTA ESP32: Wi-Fi (OTA) Wireless Update from the Arduino IDE

arduinoota esp32 5 wireless upload update ide arduino
Best deal at: aliexpress.com
CHF 6.50 CHF 6.99

The ArduinoOTA library for wireless updates (OTA) in Wi-Fi is also compatible with ESP32266, the ESP32266’s more powerful successor. It is integrated into the Arduino Core for ESP32 developed by Espressif (GitHub page of the project). It is not yet possible to install the development kit from the board manager. Since the SDK is still in development, the installation process depends on the machine on which the Arduino IDE is installed. It is now possible to use the password hash to further secure the remote update. Another novelty, it is now possible to update in Wi-Fi the SPIFFS memory area.

Install the ArduinoOTA library for ESP32 on the Arduino IDE

Before starting the installation, exit the Arduino IDE. Then, to install the development kit on your MacOS, Windows, Linux or Raspberry Pi, follow this previous tutorial. Once the SDK is installed, you can restart the IDE.

If everything went smoothly, you must have new ESP32 boards

In the current version, the kit supports generic boards (ESP32 Dev Module up to 4MB), and several manufacturers’ boards known as the new Wemos LoLin32 presented recently.

Flash memory USB-Serial
SparkFun ESP32 Thing 4MB
Electronic SweetPeas – ESP320 16MB ?
Nano32 de MakerAsia 4MB
WEMOS LoLin32 4MB
ESPea32 available on Tindie 4MB CP2104
Noduino Quantum 16MB CP2102
Node32s 4MB
Hornbill ESP32 Dev 4MB
Hornbill ESP32 Minima 4MB
FireBeetle-ESP32 4MB
IntoRobot Fig 4MB

To bring up the sample menu, select your ESP32. Generic boards are very well supported by the SDK. From the menu, select the example basicOTA.

The code differs very little from that of the ESP8266 boards.

#include <WiFi.h>
#include <ESPmDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>

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

void setup() {
  Serial.begin(115200);
  Serial.println("Booting");
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  while (WiFi.waitForConnectResult() != WL_CONNECTED) {
    Serial.println("Connection Failed! Rebooting...");
    delay(5000);
    ESP.restart();
  }

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

  // Hostname defaults to esp3232-[MAC]
  ArduinoOTA.setHostname("Demo OTA ESP32");

  // No authentication by default
  // ArduinoOTA.setPassword("admin");

  // Password can be set with it's md5 value as well
  // MD5(admin) = 21232f297a57a5a743894a0e4a801fc3
  ArduinoOTA.setPasswordHash("21232f297a57a5a743894a0e4a801fc3");

  ArduinoOTA.onStart([]() {
    String type;
    if (ArduinoOTA.getCommand() == U_FLASH)
      type = "sketch";
    else // U_SPIFFS
      type = "filesystem";

    // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
    Serial.println("Start updating " + type);
  });
  ArduinoOTA.onEnd([]() {
    Serial.println("\nEnd");
  });
  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");
  });
  ArduinoOTA.begin();
  Serial.println("Ready");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
}

void loop() {
  ArduinoOTA.handle();
}

Several parameters are available:

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

At the end of the setup, the wireless update support is started by calling the begin () method.

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

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

Secure the update with the hash of the password

The ESP32 is much more secure than the ESP8266 (read this article for more information), it is possible to store the hash of the password in place of it. To create your password fingerprint, you can use an online generator such as this one. For example, the hash of the admin password will give the fingerprint 21232f297a57a5a743894a0e4a801fc3.

Please note that some online generators are not recommended … Do not use the admin password!

Then, use the setPasswordhash function instead of setPassword () to specify the authentication password.

ArduinoOTA.setPasswordHash("21232f297a57a5a743894a0e4a801fc3");

Wireless Update Test

Upload the program and open the Terminal to verify that the ESP32 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.

The SDK is still in development. During the tests, I had to enter the password twice before successfully updating.

WEMOS WiFi & Bluetooth Batterie ESP32 développement outil ESP32 batterie esp8266 ESP WROOM 32 ESP32

Price: CHF 6.50
as of 21 October 2021 3 h 03 min
BUY NOW
Aliexpress
Wait For A Price Drop

Price History

Statistics

Current Price CHF 6.50 21 October 2021
Highest Price CHF 6.56 21 September 2021
Lowest Price CHF 5.66 21 December 2020
Since 28 October 2020

Last price changes

CHF 6.50 18 October 2021
CHF 6.53 12 October 2021
CHF 6.54 9 October 2021
CHF 6.55 5 October 2021
CHF 6.56 2 October 2021
Click to rate this post!
[Total: 0 Average: 0]
Exit mobile version