2

I used to OTA sketches and data files using the ArduinoOTA and ESP32 sketch data Upload tools and the ESP32 devkit, for example when using the Arduino IDE.

Versions:

  • Arduino IDE- 1.8.19
  • ESP32 on Arduino IDE - 1.0.6
  • ArduinoOTA 1.0.9

Moving to PlatformIO-

Started a new project using the ESP32 devkit, ArduinoOTA was added from the registry to the project (also 1.0.9 as on Arduino IDE).

And now - when I tried to copy the BasicOTA example from the Arduino IDE's ArduinoOTA example, the compilation failed.

To make sure I don't have any library/version issues, I checked:

  1. WiFi, ESPmDNS is part of builtin.
  2. WiFiUdp was not found not inbuiltin,installed nor registry - not shown in dependency graph during compilation -- ??
  3. ArduinoOTA used from registry.
#include <WiFi.h>
#include <ESPmDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>

const char* ssid = "dvirz_iot";
const char* password = "GdSd13100301";

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("myesp32");

  // 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);
    })
    .onEnd([]() {
      Serial.println("\nEnd");
    })
    .onProgress([](unsigned int progress, unsigned int total) {
      Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
    })
    .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();
}

and got this compilation error:

 *  Executing task in folder esp32_OTA_from_scratch: platformio run --environment esp32dev 

Processing esp32dev (platform: espressif32; board: esp32dev; framework: arduino)
-------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32dev.html
PLATFORM: Espressif 32 (6.1.0) > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES: 
 - framework-arduinoespressif32 @ 3.20007.0 (2.0.7) 
 - tool-esptoolpy @ 1.40500.0 (4.5.0) 
 - toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch5
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 34 compatible libraries
Scanning dependencies...
Dependency Graph
|-- ArduinoOTA @ 1.0.9
|-- ESPmDNS @ 2.0.0
|-- WiFi @ 2.0.0
Building in release mode
Compiling .pio/build/esp32dev/src/main.cpp.o
Building .pio/build/esp32dev/bootloader.bin
Generating partitions .pio/build/esp32dev/partitions.bin
esptool.py v4.5
Creating esp32 image...
Merged 1 ELF section
Successfully created esp32 image.
Compiling .pio/build/esp32dev/lib8f4/Update/HttpsOTAUpdate.cpp.o
Compiling .pio/build/esp32dev/lib8f4/Update/Updater.cpp.o
Compiling .pio/build/esp32dev/liba9d/WiFi/WiFi.cpp.o
Compiling .pio/build/esp32dev/liba9d/WiFi/WiFiAP.cpp.o
Compiling .pio/build/esp32dev/liba9d/WiFi/WiFiClient.cpp.o
Compiling .pio/build/esp32dev/liba9d/WiFi/WiFiGeneric.cpp.o
Archiving .pio/build/esp32dev/lib8f4/libUpdate.a
Indexing .pio/build/esp32dev/lib8f4/libUpdate.a
Compiling .pio/build/esp32dev/liba9d/WiFi/WiFiMulti.cpp.o
Compiling .pio/build/esp32dev/liba9d/WiFi/WiFiSTA.cpp.o
Compiling .pio/build/esp32dev/liba9d/WiFi/WiFiScan.cpp.o
Compiling .pio/build/esp32dev/liba9d/WiFi/WiFiServer.cpp.o
Compiling .pio/build/esp32dev/liba9d/WiFi/WiFiUdp.cpp.o
Compiling .pio/build/esp32dev/libc4b/FS/FS.cpp.o
Compiling .pio/build/esp32dev/libc4b/FS/vfs_api.cpp.o
Compiling .pio/build/esp32dev/lib263/SPI/SPI.cpp.o
Archiving .pio/build/esp32dev/liba9d/libWiFi.a
Indexing .pio/build/esp32dev/liba9d/libWiFi.a
Compiling .pio/build/esp32dev/lib494/SD/SD.cpp.o
Archiving .pio/build/esp32dev/lib263/libSPI.a
Indexing .pio/build/esp32dev/lib263/libSPI.a
Compiling .pio/build/esp32dev/lib494/SD/sd_diskio.cpp.o
Compiling .pio/build/esp32dev/lib494/SD/sd_diskio_crc.c.o
Compiling .pio/build/esp32dev/lib624/ArduinoOTA/InternalStorage.cpp.o
Archiving .pio/build/esp32dev/libc4b/libFS.a
Indexing .pio/build/esp32dev/libc4b/libFS.a
Compiling .pio/build/esp32dev/lib624/ArduinoOTA/InternalStorageAVR.cpp.o
Compiling .pio/build/esp32dev/lib624/ArduinoOTA/InternalStorageESP.cpp.o
Compiling .pio/build/esp32dev/lib624/ArduinoOTA/InternalStorageRP2.cpp.o
Archiving .pio/build/esp32dev/lib494/libSD.a
Indexing .pio/build/esp32dev/lib494/libSD.a
Compiling .pio/build/esp32dev/lib624/ArduinoOTA/InternalStorageSTM32.cpp.o
Compiling .pio/build/esp32dev/lib624/ArduinoOTA/OTAStorage.cpp.o
Compiling .pio/build/esp32dev/lib624/ArduinoOTA/WiFiOTA.cpp.o
Compiling .pio/build/esp32dev/lib624/ArduinoOTA/utility/rp2_flash_boot.c.o
Compiling .pio/build/esp32dev/lib624/ArduinoOTA/utility/stm32_flash_boot.c.o
Compiling .pio/build/esp32dev/lib6d4/ESPmDNS/ESPmDNS.cpp.o
Compiling .pio/build/esp32dev/FrameworkArduino/Esp.cpp.o
Archiving .pio/build/esp32dev/lib624/libArduinoOTA.a
Compiling .pio/build/esp32dev/FrameworkArduino/FirmwareMSC.cpp.o
Indexing .pio/build/esp32dev/lib624/libArduinoOTA.a
Compiling .pio/build/esp32dev/FrameworkArduino/FunctionalInterrupt.cpp.o
Compiling .pio/build/esp32dev/FrameworkArduino/HWCDC.cpp.o
Compiling .pio/build/esp32dev/FrameworkArduino/HardwareSerial.cpp.o
Archiving .pio/build/esp32dev/lib6d4/libESPmDNS.a
Indexing .pio/build/esp32dev/lib6d4/libESPmDNS.a
Compiling .pio/build/esp32dev/FrameworkArduino/IPAddress.cpp.o
Compiling .pio/build/esp32dev/FrameworkArduino/IPv6Address.cpp.o
Compiling .pio/build/esp32dev/FrameworkArduino/MD5Builder.cpp.o
Compiling .pio/build/esp32dev/FrameworkArduino/Print.cpp.o
Compiling .pio/build/esp32dev/FrameworkArduino/Stream.cpp.o
Compiling .pio/build/esp32dev/FrameworkArduino/StreamString.cpp.o
Compiling .pio/build/esp32dev/FrameworkArduino/Tone.cpp.o
Compiling .pio/build/esp32dev/FrameworkArduino/USB.cpp.o
Compiling .pio/build/esp32dev/FrameworkArduino/USBCDC.cpp.o
Compiling .pio/build/esp32dev/FrameworkArduino/USBMSC.cpp.o
Compiling .pio/build/esp32dev/FrameworkArduino/WMath.cpp.o
Compiling .pio/build/esp32dev/FrameworkArduino/WString.cpp.o
Compiling .pio/build/esp32dev/FrameworkArduino/base64.cpp.o
Compiling .pio/build/esp32dev/FrameworkArduino/cbuf.cpp.o
Compiling .pio/build/esp32dev/FrameworkArduino/esp32-hal-adc.c.o
Compiling .pio/build/esp32dev/FrameworkArduino/esp32-hal-bt.c.o
Compiling .pio/build/esp32dev/FrameworkArduino/esp32-hal-cpu.c.o
Compiling .pio/build/esp32dev/FrameworkArduino/esp32-hal-dac.c.o
Compiling .pio/build/esp32dev/FrameworkArduino/esp32-hal-gpio.c.o
Compiling .pio/build/esp32dev/FrameworkArduino/esp32-hal-i2c-slave.c.o
Compiling .pio/build/esp32dev/FrameworkArduino/esp32-hal-i2c.c.o
Compiling .pio/build/esp32dev/FrameworkArduino/esp32-hal-ledc.c.o
Compiling .pio/build/esp32dev/FrameworkArduino/esp32-hal-matrix.c.o
Compiling .pio/build/esp32dev/FrameworkArduino/esp32-hal-misc.c.o
Compiling .pio/build/esp32dev/FrameworkArduino/esp32-hal-psram.c.o
Compiling .pio/build/esp32dev/FrameworkArduino/esp32-hal-rgb-led.c.o
Compiling .pio/build/esp32dev/FrameworkArduino/esp32-hal-rmt.c.o
Compiling .pio/build/esp32dev/FrameworkArduino/esp32-hal-sigmadelta.c.o
Compiling .pio/build/esp32dev/FrameworkArduino/esp32-hal-spi.c.o
Compiling .pio/build/esp32dev/FrameworkArduino/esp32-hal-time.c.o
Compiling .pio/build/esp32dev/FrameworkArduino/esp32-hal-timer.c.o
Compiling .pio/build/esp32dev/FrameworkArduino/esp32-hal-tinyusb.c.o
Compiling .pio/build/esp32dev/FrameworkArduino/esp32-hal-touch.c.o
Compiling .pio/build/esp32dev/FrameworkArduino/esp32-hal-uart.c.o
Compiling .pio/build/esp32dev/FrameworkArduino/firmware_msc_fat.c.o
Compiling .pio/build/esp32dev/FrameworkArduino/libb64/cdecode.c.o
Compiling .pio/build/esp32dev/FrameworkArduino/libb64/cencode.c.o
Compiling .pio/build/esp32dev/FrameworkArduino/main.cpp.o
Compiling .pio/build/esp32dev/FrameworkArduino/stdlib_noniso.c.o
Compiling .pio/build/esp32dev/FrameworkArduino/wiring_pulse.c.o
Compiling .pio/build/esp32dev/FrameworkArduino/wiring_shift.c.o
Archiving .pio/build/esp32dev/libFrameworkArduino.a
Indexing .pio/build/esp32dev/libFrameworkArduino.a
Linking .pio/build/esp32dev/firmware.elf
Retrieving maximum program size .pio/build/esp32dev/firmware.elf
Checking size .pio/build/esp32dev/firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]   8.0% (used 26164 bytes from 327680 bytes)
Flash: [==        ]  24.6% (used 322233 bytes from 1310720 bytes)
Building .pio/build/esp32dev/firmware.bin
esptool.py v4.5
Creating esp32 image...
Merged 2 ELF sections
Successfully created esp32 image.
========================================================= [SUCCESS] Took 13.72 seconds =========================================================
 *  Terminal will be reused by tasks, press any key to close it. 

 *  Executing task in folder esp32_OTA_from_scratch: platformio run --environment esp32dev 

Processing esp32dev (platform: espressif32; board: esp32dev; framework: arduino)
-------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32dev.html
PLATFORM: Espressif 32 (6.1.0) > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES: 
 - framework-arduinoespressif32 @ 3.20007.0 (2.0.7) 
 - tool-esptoolpy @ 1.40500.0 (4.5.0) 
 - toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch5
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 34 compatible libraries
Scanning dependencies...
Dependency Graph
|-- ArduinoOTA @ 1.0.9
|-- ESPmDNS @ 2.0.0
|-- WiFi @ 2.0.0
Building in release mode
Compiling .pio/build/esp32dev/src/main.cpp.o
src/main.cpp: In lambda function:
src/main.cpp:39:22: error: 'class ArduinoOTAMdnsClass<WiFiServer, WiFiClient, WiFiUDP>' has no member named 'getCommand'
       if (ArduinoOTA.getCommand() == U_FLASH)
                      ^~~~~~~~~~
src/main.cpp:39:38: error: 'U_FLASH' was not declared in this scope
       if (ArduinoOTA.getCommand() == U_FLASH)
                                      ^~~~~~~
src/main.cpp: In function 'void setup()':
src/main.cpp:37:13: error: invalid use of 'void'
   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);
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     })
     ~~       
src/main.cpp:49:6: error: expected primary-expression before ')' token
     })
      ^
src/main.cpp:52:6: error: expected primary-expression before ')' token
     })
      ^
src/main.cpp:60:6: error: expected primary-expression before ')' token
     });
      ^
src/main.cpp:62:20: error: no matching function for call to 'ArduinoOTAMdnsClass<WiFiServer, WiFiClient, WiFiUDP>::begin()'
   ArduinoOTA.begin();
                    ^
In file included from src/main.cpp:5:
.pio/libdeps/esp32dev/ArduinoOTA/src/ArduinoOTA.h:91:8: note: candidate: 'void ArduinoOTAMdnsClass<NetServer, NetClient, NetUDP>::begin(IPAddress, const char*, const char*, OTAStorage&) [with NetServer = WiFiServer; NetClient = WiFiClient; NetUDP = WiFiUDP]'
   void begin(IPAddress localIP, const char* name, const char* password, OTAStorage& storage) {
        ^~~~~
.pio/libdeps/esp32dev/ArduinoOTA/src/ArduinoOTA.h:91:8: note:   candidate expects 4 arguments, 0 provided
*** [.pio/build/esp32dev/src/main.cpp.o] Error 1
========================================================== [FAILED] Took 2.69 seconds ==========================================================

 *  The terminal process "platformio 'run', '--environment', 'esp32dev'" terminated with exit code: 1. 
 *  Terminal will be reused by tasks, press any key to close it. 

What could be the problem?

2 Answers 2

1

All I can see are three issues (plus possible some bonus ones)

  1. You can't daisy chain callback setters like that, it returns void and it doesn't make any sense to have void.onProgress... and those callbacks doesn't seems to fit current library, so you should just drop them completely.
  2. There is no begin() without parameters. See examples.
  3. In the library I can see only callback setters: beforeApply, onError and onStart
  4. You might be missing #include <Arduino.h> (it doesn't have any preprocessor like ArduinoIDE that adds this to the first line without you knowing it
  5. You might be missing some defines (you can compare Arduino compile commands and Pio one)

Anyway you should take a look into the examples (at least begin is there). Callbacks looks like they are taken from who knows where (probably different library or so).

But they definitely must be complete like:

ArduinoOTA.onStart([](){ /* started */ });
ArduinoOTA.onBeforeApply([](){ /* before aply */ });

EDIT:

After some searching the ArduinoOTA library is directly in esp32 core (google: "arduinoOTA onProgress esp32"), so you don't have to add any lib_deps for ArduinoOTA. Or more likely you shouldn't add any, and the correct library will be used then. If not, you'll have to copy (or download) correct library into lib/ subdirectory.

2
  • Hi @KIIV - How can you explain the fact that the example is taken from ArduinoOTA library (when using Arduino IDE), compiles and works as it should ??
    – guyd
    Commented Jul 5, 2023 at 3:27
  • 1
    Might be different library (or version). Sometimes the cores has libraries with them. You can always find its location and copy that library to the lib subdirectory in your project (and remove that lib_deps ArduinoOTA reference) to use correct version
    – KIIV
    Commented Jul 5, 2023 at 5:59
0

If you check the ArduinoOTA library in Github it states that this library has not been tested on platformIO Also note that not all functions are the same, parameters are different when you call in ArduinoIDE and on PlatformIO

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.