OTA Upload does not work with ESP32

I’m desperately trying to get OTA uploading to work on PlatformIO and my ESP32. Here’s the code I’m currently using:

#include <Arduino.h>
#include <WiFi.h>
#include <esp_wifi.h>
#include <ArduinoOTA.h>

#define WIFI_SSID "..."
#define WIFI_PASS "..."

void setup()
{
  Serial.begin(115200);
  // Connect to Wifi
  Serial.println("Connecting to wifi");
  delay(20);
  WiFi.mode(WIFI_STA);
  WiFi.begin(WIFI_SSID, WIFI_PASS);
  while (WiFi.status() != WL_CONNECTED)
  {
    Serial.println("Wifi onnection Failed!");
    delay(500);
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
  Serial.print("MAC address: ");
  Serial.println(WiFi.macAddress());

  // OTA Configiration and Enable OTA
  Serial.println("Starting OTA server");
  ArduinoOTA.begin(WiFi.localIP(), "Test", "test", InternalStorage);

  // Done
  Serial.println("OTA started successfully");
  Serial.println("Waiting for upload...");
}

void loop()
{
  // OTA Handle
  ArduinoOTA.handle();
}

And this is my platformio.ini:

[env]
platform = espressif32
board = esp32doit-devkit-v1
framework = arduino
monitor_speed = 115200
lib_deps =
  jandrassy/ArduinoOTA @ ^1.1.0

[env:usb]
upload_protocol = esptool
upload_port = /dev/ttyUSB*

[env:ota]
upload_protocol = espota
upload_port = 192.168.178.133
upload_flags =
  --auth=test

After uploading via USB I get the expected output from the serial monitor:

Connecting to wifi
Wifi onnection Failed!
Wifi onnection Failed!
Wifi onnection Failed!
WiFi connected
SSID: …
IP address: 192.168.178.133
MAC address: 84:0D:8E:1C:F3:44
Starting OTA server
OTA started successfully
Waiting for upload…

But now comes the problem: when uploading the code again via OTA, it does not work at all.
Here’s the output:

Configuring upload protocol…
AVAILABLE: cmsis-dap, esp-bridge, esp-prog, espota, esptool, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa
CURRENT: upload_protocol = esptool
Uploading .pio/build/ota/firmware.bin
21:05:23 [DEBUG]: Options: {‘esp_ip’: ‘192.168.178.133’, ‘host_ip’: ‘0.0.0.0’, ‘esp_port’: 3232, ‘host_port’: 41596, ‘auth’: ‘’, ‘image’: ‘.pio/build/ota/firmware.bin’, ‘spiffs’: False, ‘debug’: True, ‘progress’: True, ‘timeout’: 10}
21:05:23 [INFO]: Starting on 0.0.0.0:41596
21:05:23 [INFO]: Upload size: 755472
Sending invitation to 192.168.178.133 …
21:07:03 [ERROR]: No response from the ESP
*** [upload] Error 1
======================

Why isn’t this working? Can anyone spot the mistake?
Thanks :slight_smile:

Why not using the built-in ArduinoOTA library?

This is the library that comes up when searching for “ArduinoOTA” in the PlatformIO library manager.

I thought there was only one ArduinoOTA library? If not, where can I find this built-in library?

It is built-in. Simply `#include <ArduinoOTA.h>

See one of the examples from the link above.
That is the built-in library.

Remove the lib_deps and perform a clean.

1 Like

To say it more clearly: You’re completely mismatching the OTA library code running on the ESP32 and the desktop program trying to upload to it. The espota tool expects the ESP32 to be running the builtin ArduinoOTA library that’s in Arduino-ESP32. Start with the https://github.com/espressif/arduino-esp32/blob/2.0.16/libraries/ArduinoOTA/examples/BasicOTA/BasicOTA.ino example, just adapting your SSID and password, and the IP in the platformio.ini.

The documentation tells you to do the same, linking to BasicOTA.

https://docs.platformio.org/en/latest/platforms/espressif32.html#over-the-air-ota-update