Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By danbicks
#45183 Hi guys,

Going to ask a silly one here, In the basicOta sketch, why are the callbacks located within the setup subroutine?

Can they be placed outside of setup or is there a specific reason. I can understand that ArduinoOTA.begin(); needs to be there, but don't quite get why a separate callback such as

ArduinoOTA.onProgress( {
Serial.printf("Progress: %u%%\n", (progress / (total / 100)));
});

is located within the setup scope.

Cheers

Dans
User avatar
By martinayotte
#45187 Those callbacks are some kind of "anonymous" functions. The call in setup is only initialize the pointer to those function. The callbacks themselves could be easily placed outside. For example :

Code: Select allvoid myOnProgress() {
  Serial.printf("Progress: %u%%\n", (progress / (total / 100)));
}

void setup() {
  [...code...]
  ArduinoOTA.onProgress(myOnProgress);
  [...code...]
}