Go Down

Topic: Error: invalid use of 'void' - ArduinoOTA on ESP8266 (Read 189 times) previous topic - next topic

mattlogue

This is odd. This worked before fine, I have ArduinoOTA on a few ESP8266s and it works. Now it says invalid use of 'void' on it's property ".onEnd". This function is from my sketch, however, I went back to the example sketch, it fails too.

Here is faulting function... see carrots for faulting line
Code: [Select]
int OTAInit() {
  ArduinoOTA.setHostname("Thermostat");
  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([]() { <<<<<<<<<<<<<<< ERROR HERE
    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();
}
Just because I live in the states don't mean I care

mattlogue

Just because I live in the states don't mean I care

gfvalvo

Code: [Select]
 .onEnd([]() { <<<<<<<<<<<<<<< ERROR HERE
    Serial.println("\nEnd");
  })


You're trying to invoke an object's method without specifying the object.

Also, your code might be more readable and maintainable without the lambda expressions.
No technical questions via PM. They will be ignored. Post your questions in the forum so that all may learn.

johnwasser

The ".onEnd()" line is the first one where you didn't put "ArduinoOTA" before the '.'.
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

oqibidipo

It works on ESP32, but not on ESP8266.

On ESP32 onXxxx() return a reference to the object which makes chaining the calls possible,
on ESP8266 onXxxx() return void.

ESP32 ArduinoOTA.h
ESP8266 ArduinoOTA.h

gfvalvo

Ahhhh, I missed the attempt at chaining. That's another thing (besides the use of Lambda expressions) that makes this code difficult to read and maintain.

I'd get rid of the chaining and break it out into separate method calls.

Then, get rid of the Lambdas and provide pointers to explicitly defined functions.

I mean, come on, this looks like initialization code. Does it really provide any required optimization in exchange for making it hard to read? Beware of false economies.

No technical questions via PM. They will be ignored. Post your questions in the forum so that all may learn.

mattlogue

When I saw lambdas first I didn't think it was valid code at all. I'm not sure why webserver uses them... I'll replace them with fx pointers but right now it's overflowing stack and that's my main concern... Another thread...
Just because I live in the states don't mean I care

Go Up