PlatformIO Community

ESP32 OTA using PlatformIO

I have searched in vein for information to get an ESP32 running OTA under PlatformIO.
Is this the correct forum to ask for such help?

What search terms did you enter? It’s right there in the documentation.

Thank you for your email Maximillian.

ESP32 PLATFORMIO OTA.

I did see this in my search and do not comprehend its meaning. I recently learned about the concept of OTA and then looked for a start to finish guide.

As a newbie using PlatformIO, does anyone know of a step by step guide of what I need to do to update my ESP32 so they might accept a code refresh periodically?

Refer to resources like ESP32 OTA, I'm confused.

Really it’s just as easy as

  • adding the ArduinoOTA init code in setup() and the handle code in loop() like in the example
  • checking out what IP address your ESP32 has (e.g. in the router or serial monitor once), or using mDNS names
  • adapting the platformio.ini to use the OTA upload code as shown in the docs above like
upload_protocol = espota
upload_port = IP_ADDRESS_HERE or mDNS_NAME.local
  • using the normal upload button of the IDE.

I suppose one man’s just as easy is another’s man’s frustration

Something imust be wrong with my environment.

My platformio.ini file is as follows:

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed=115200
;upload_port = COM[4]
;upload_port = COM[6]
upload_port = 10.0.4.4

; for "chipMAC": "FC:F5:C4:31:71:04",
;upload_protocol = esp-prog

upload_protocol = espota
upload_flags = --8266
;upload_port = 10.0.4.4

; for "chipMAC": "FC:F5:C4:31:71:04",
;debug_tool = esp-prog
;debug_init_break = tbreak setup
lib_deps =
    ArduinoOTA

When I compile I get a slew of errors emanating from ArdunioOTA class as such:

The terminal process "C:\Users\Tom\.platformio\penv\Scripts\platformio.exe 'run'" terminated with exit code: 1.      
Terminal will be reused by tasks, press any key to close it.

> Executing task: C:\Users\Tom\.platformio\penv\Scripts\platformio.exe run <

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 1.12.4 #72b15f6 > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (esp-prog) External (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.10004.200129 (1.0.4)
 - tool-esptoolpy 1.20600.0 (2.6.0)
 - tool-openocd-esp32 1.1000.20190708 (10.0)
 - toolchain-xtensa32 2.50200.80 (5.2.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 34 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <ArduinoOTA> 1.0.5
|   |-- <Update> 1.0
|   |-- <SD(esp32)> 1.0.5
|   |   |-- <FS> 1.0
|   |   |-- <SPI> 1.0
|   |-- <WiFi> 1.0
|-- <ESPmDNS> 1.0
|   |-- <WiFi> 1.0
|-- <WiFi> 1.0
Building in release mode
Compiling .pio\build\esp32dev\src\main.cpp.o
Generating partitions .pio\build\esp32dev\partitions.bin
Compiling .pio\build\esp32dev\libb98\Update\Updater.cpp.o
Compiling .pio\build\esp32dev\lib6d4\FS\FS.cpp.o
Compiling .pio\build\esp32dev\lib6d4\FS\vfs_api.cpp.o
Compiling .pio\build\esp32dev\lib0cb\SPI\SPI.cpp.o
Compiling .pio\build\esp32dev\lib4d4\SD\SD.cpp.o
Compiling .pio\build\esp32dev\lib4d4\SD\sd_diskio.cpp.o
Compiling .pio\build\esp32dev\lib4d4\SD\sd_diskio_crc.c.o
Compiling .pio\build\esp32dev\lib890\WiFi\ETH.cpp.o
Compiling .pio\build\esp32dev\lib890\WiFi\WiFi.cpp.o
Compiling .pio\build\esp32dev\lib890\WiFi\WiFiAP.cpp.o
Archiving .pio\build\esp32dev\lib0cb\libSPI.a
Compiling .pio\build\esp32dev\lib890\WiFi\WiFiClient.cpp.o
Compiling .pio\build\esp32dev\lib890\WiFi\WiFiGeneric.cpp.o
Compiling .pio\build\esp32dev\lib890\WiFi\WiFiMulti.cpp.o
src\main.cpp: In function 'void setup()':
src\main.cpp:23:14: error: 'class ArduinoOTAMdnsClass<WiFiServer, WiFiClient, WiFiUDP>' has no member named 'onStart'
   ArduinoOTA.onStart([]() {
              ^
src\main.cpp: In lambda function:
src\main.cpp:25:20: error: 'class ArduinoOTAMdnsClass<WiFiServer, WiFiClient, WiFiUDP>' has no member named 'getCommand'
     if (ArduinoOTA.getCommand() == U_FLASH)
                    ^
src\main.cpp:25:36: error: 'U_FLASH' was not declared in this scope
     if (ArduinoOTA.getCommand() == U_FLASH)
                                    ^
src\main.cpp: In function 'void setup()':
src\main.cpp:32:14: error: 'class ArduinoOTAMdnsClass<WiFiServer, WiFiClient, WiFiUDP>' has no member named 'onEnd'
   ArduinoOTA.onEnd([]() { Serial.println("\nEnd"); });
              ^
src\main.cpp:33:14: error: 'class ArduinoOTAMdnsClass<WiFiServer, WiFiClient, WiFiUDP>' has no member named 'onProgress'
   ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
              ^
src\main.cpp:36:25: error: 'ota_error_t' has not been declared
   ArduinoOTA.onError([](ota_error_t error) {
                         ^
src\main.cpp: In lambda function:
src\main.cpp:38:18: error: 'OTA_AUTH_ERROR' was not declared in this scope
     if (error == OTA_AUTH_ERROR)         Serial.println("Auth Failed");
                  ^
src\main.cpp:39:23: error: 'OTA_BEGIN_ERROR' was not declared in this scope
     else if (error == OTA_BEGIN_ERROR)   Serial.println("Begin Failed");
                       ^
src\main.cpp:40:23: error: 'OTA_CONNECT_ERROR' was not declared in this scope
     else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
                       ^
src\main.cpp:41:23: error: 'OTA_RECEIVE_ERROR' was not declared in this scope
     else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
                       ^
src\main.cpp:42:23: error: 'OTA_END_ERROR' was not declared in this scope
     else if (error == OTA_END_ERROR)     Serial.println("End Failed");
                       ^
src\main.cpp: In function 'void setup()':
src\main.cpp:43:4: error: invalid user-defined conversion from 'setup()::<lambda(int)>' to 'void (*)(int, const char*)' [-fpermissive]
   });
    ^
src\main.cpp:36:42: note: candidate is: setup()::<lambda(int)>::operator void (*)(int)() const <near match>
   ArduinoOTA.onError([](ota_error_t error) {
                                          ^
src\main.cpp:36:42: note:   no known conversion from 'void (*)(int)' to 'void (*)(int, const char*)'
In file included from .pio\libdeps\esp32dev\ArduinoOTA\src/ArduinoOTA.h:22:0,
                 from src\main.cpp:4:
.pio\libdeps\esp32dev\ArduinoOTA\src/WiFiOTA.h:49:8: note:   initializing argument 1 of 'void WiFiOTAClass::onError(void (*)(int, const char*))'
   void onError(void (*fn)(int code, const char* msg)) {
        ^
src\main.cpp:44:20: error: no matching function for call to 'ArduinoOTAMdnsClass<WiFiServer, WiFiClient, WiFiUDP>::begin()'
   ArduinoOTA.begin();
                    ^
In file included from src\main.cpp:4:0:
.pio\libdeps\esp32dev\ArduinoOTA\src/ArduinoOTA.h:87: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:87:8: note:   candidate expects 4 arguments, 0 provided
src\main.cpp:49:11: error: 'LED_BUILTIN' was not declared in this scope
   pinMode(LED_BUILTIN, OUTPUT);
           ^
src\main.cpp: In function 'void loop()':
src\main.cpp:56:16: error: 'LED_BUILTIN' was not declared in this scope
   digitalWrite(LED_BUILTIN, HIGH);  // turn the LED on (HIGH is the voltage level)
                ^
*** [.pio\build\esp32dev\src\main.cpp.o] Error 1
========================================================================== [FAILED] Took 8.93 seconds ==========================================================================The terminal process "C:\Users\Tom\.platformio\penv\Scripts\platformio.exe 'run'" terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.

That flag isn’t accepted by the espota program, did you mean --port=8266? This is already default so no need to specify.

No, ArduinoOTA from the library registry is a different library from the ArduinoOTA library which is contained in the Arduino-ESP32 core (https://github.com/espressif/arduino-esp32/tree/master/libraries/ArduinoOTA). For libraries within the core, do not use lib_deps, these are found automatically.

Make sure when you do a “Verbose Build” that you get a library dependency view which only references core internal libraries as in

grafik

Then it will compile.