I cannot get the simple example code for the ESP8266 to compile without error in PI/Atom (ArduinoOTA->BasicOTA). It compiles w/o error with the Arduino IDE. The errors seem to relate to the C++11 Lambda functions:
src/main.cpp: In function 'void setup()':
src/main.cpp:39:14: error: 'class ArduinoOTAMdnsClass<WiFiServer, WiFiClient, WiFiUDP>' has no member named 'onStart'
ArduinoOTA.onStart([]() {
^
src/main.cpp: In lambda function:
src/main.cpp:41:20: error: 'class ArduinoOTAMdnsClass<WiFiServer, WiFiClient, WiFiUDP>' has no member named 'getCommand'
if (ArduinoOTA.getCommand() == U_FLASH) {
^
src/main.cpp: In function 'void setup()':
src/main.cpp:50:14: error: 'class ArduinoOTAMdnsClass<WiFiServer, WiFiClient, WiFiUDP>' has no member named 'onEnd'
ArduinoOTA.onEnd([]() {
^
src/main.cpp:53:14: error: 'class ArduinoOTAMdnsClass<WiFiServer, WiFiClient, WiFiUDP>' has no member named 'onProgress'
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
^
src/main.cpp:56:14: error: 'class ArduinoOTAMdnsClass<WiFiServer, WiFiClient, WiFiUDP>' has no member named 'onError'
ArduinoOTA.onError([](ota_error_t error) {
^
src/main.cpp:56:25: error: 'ota_error_t' has not been declared
ArduinoOTA.onError([](ota_error_t error) {
^
src/main.cpp: In lambda function:
src/main.cpp:58:18: error: 'OTA_AUTH_ERROR' was not declared in this scope
if (error == OTA_AUTH_ERROR) {
^
src/main.cpp:60:25: error: 'OTA_BEGIN_ERROR' was not declared in this scope
} else if (error == OTA_BEGIN_ERROR) {
^
src/main.cpp:62:25: error: 'OTA_CONNECT_ERROR' was not declared in this scope
} else if (error == OTA_CONNECT_ERROR) {
^
src/main.cpp:64:25: error: 'OTA_RECEIVE_ERROR' was not declared in this scope
} else if (error == OTA_RECEIVE_ERROR) {
^
src/main.cpp:66:25: error: 'OTA_END_ERROR' was not declared in this scope
} else if (error == OTA_END_ERROR) {
^
src/main.cpp: In function 'void setup()':
src/main.cpp:70:20: error: no matching function for call to 'ArduinoOTAMdnsClass<WiFiServer, WiFiClient, WiFiUDP>::begin()'
ArduinoOTA.begin();
^
I can find only one post relating to these exact errors and the proposed solution was to add the C++11 build flag, which I did. My PlatformIO.ini looks like this:
Maybe your esp8266 framework hasn’t installed properly? Try uninstalling and re-installing that platform via PIO Home → Platforms?
If you’re referring to this issue … that may be misleading at best, as it’s for the esp32 core, not esp8266…and the author never commented as to if that fixed the problem… although it’s peculiar you’re getting basically the same error.
Thanks for giving it a try, I know it must be possible because lots of people do it and this error is vanishingly rare. However, I’m going to need to dig deeper. I removed the ESP8266 framework and restarted Atom/PlatformIO. I re-installed – it did not go smoothly, I had to abort and restart because it got stuck with the install-spinning-arrow thing for a long time – and got the same result as before, not the result you got. I tried the whole process again, and everything finished without problem. Restarted Atom, re-installed the ESP8266. Same thing.
Added these to the PlatformIO.ini file:
build_flags = -std=c++11
lib_deps = ArduinoOTA
Same error.
Tried the 1.0 version of the ArduinoOTA library (like you have): same error.
And yes, it is very peculiar that I am getting the same error (verbatim).
This is a builtin library and shouldn’t be declared. Does the result stay the same when you remove the hidden .pio folder in project, remove the afforementioned line and recompile?
I removed the lib_deps = ArduinoOTA line as well as the .pio folder and recompile with exactly the same errors.
Is is possible that the difference between a successful dependency graph and mine (unsuccessful) is relevant?
Successful:
No it’s not… In the successful one, the ESP8266 core provided ArduinoOTA library is being used (1.0). In the unsuccessful one, the first party Arduino created ArduinoOTA library is being used (1.0.1). This be because when you added the lib_deps line… you told PlatformIO your project needs a non-core / external library. For order of business is to remove the lib_deps = ArduinoOTA line… as Max pointed out.
Have you tried using the platformio.ini and main.cpp I used as is… just to rule out any copy/paste or unintended edit errors? Make sure you clean the project’s build files first (PlatformIO sidebar icon-> Project Tasks → Clean), or even start a new project.
Yes and no. I did not make clear that I had removed all the extra platformio.ini lines and have been using exactly the one generated by the system when a new project is created (identical to yours). I was still getting the same errors. Also, the difference between <ArduinoOTA> libraries is simply a version difference, Ijust went back, uninstalled 1.0.1, installed 1.0 of <ArduinoOTA> and it made no difference – same errors.
I copied and pasted your code (again, as-is) into a new project. I did not add the #include <Arduino.h> that we are told is necessary (but maybe isn’t, because the presence/absence of that statement makes no difference). Although I cannot rule out c/p issues, the compile errors do not point in that direction (based on my understanding of compile errors). Those errors result from exactly the same code and exactly the same platformio.ini file, after a clean. The difference seems to be either 1) which libraries are getting included; or 2) the order in which the libraries are included. I tend to think it’s the former. To re-ask my question, should everything that gets compiled in this project come from inside the .platformio environment or is it permissible that some of it is being drawn from the (potentially older) Arduino environment libraries?
After all of that, if I UNINSTALL the ArduinoOTA library, compilation succeeds.
I am beginning to see the light.
Although I had long ago removed the lib_deps entry, the failure to compile was due to my having explicitly installed the ArduinoOTA library from Arduino. When I look at that code (thanks for the link), I see all the references to SD card code I was getting in my dependency graph. So the problem was not the lib_deps but rather my failure to realize that there was an OTA library that was built in and explicitly installing the wrong one.
Problem solved. Lesson learned. Thanks.